forked from alibaba/AliOS-Things-Linux-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yocto-layer
executable file
·151 lines (120 loc) · 4.86 KB
/
yocto-layer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# Copyright (c) 2012, Intel Corporation.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# DESCRIPTION
# 'yocto-layer' is the Yocto Tool that helps users create a new Yocto
# layer. Invoking it without any arguments will display help screens
# for the 'yocto-layer' command and list the available 'yocto-layer'
# subcommands. Invoking a subcommand without any arguments will
# likewise display help screens for the specified subcommand. Please
# use that interface for detailed help.
#
# AUTHORS
# Tom Zanussi <tom.zanussi (at] intel.com>
#
__version__ = "0.1.0"
import os
import sys
import optparse
import logging
scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
lib_path = scripts_path + '/lib'
sys.path = sys.path + [lib_path]
from bsp.help import *
from bsp.engine import *
def yocto_layer_create_subcommand(args, usage_str):
"""
Command-line handling for layer creation. The real work is done by
bsp.engine.yocto_layer_create()
"""
parser = optparse.OptionParser(usage = usage_str)
parser.add_option("-o", "--outdir", dest = "outdir", action = "store",
help = "name of layer dir to create")
parser.add_option("-i", "--infile", dest = "properties_file", action = "store",
help = "name of file containing the values for layer input properties as a JSON file")
parser.add_option("-c", "--codedump", dest = "codedump", action = "store_true",
default = False, help = "dump the generated code to layergen.out")
(options, args) = parser.parse_args(args)
if len(args) < 1 or len(args) > 2:
logging.error("Wrong number of arguments, exiting\n")
parser.print_help()
sys.exit(1)
layer_name = args[0]
properties = ""
if len(args) == 2:
layer_priority = args[1]
properties = '{"layer_priority":"' + layer_priority + '"}'
if options.outdir:
layer_output_dir = options.outdir
else:
prefix="meta-"
if not layer_name.startswith(prefix):
layer_output_dir="%s%s"%(prefix,layer_name)
else:
layer_output_dir=layer_name
yocto_layer_create(layer_name, scripts_path, layer_output_dir, options.codedump, options.properties_file, properties)
def yocto_layer_list_subcommand(args, usage_str):
"""
Command-line handling for listing available layer properties and
values. The real work is done by bsp.engine.yocto_layer_list()
"""
parser = optparse.OptionParser(usage = usage_str)
parser.add_option("-o", "--outfile", action = "store", dest = "properties_file",
help = "dump the possible values for layer properties to a JSON file")
(options, args) = parser.parse_args(args)
if not yocto_layer_list(args, scripts_path, options.properties_file):
logging.error("Bad list arguments, exiting\n")
parser.print_help()
sys.exit(1)
subcommands = {
"create": [yocto_layer_create_subcommand,
yocto_layer_create_usage,
yocto_layer_create_help],
"list": [yocto_layer_list_subcommand,
yocto_layer_list_usage,
yocto_layer_list_help],
}
def start_logging(loglevel):
logging.basicConfig(filename = 'yocto-layer.log', filemode = 'w', level=loglevel)
def main():
parser = optparse.OptionParser(version = "yocto-layer version %s" % __version__,
usage = yocto_layer_usage)
parser.disable_interspersed_args()
parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
default = False, help = "output debug information")
(options, args) = parser.parse_args()
loglevel = logging.INFO
if options.debug:
loglevel = logging.DEBUG
start_logging(loglevel)
if len(args):
if args[0] == "help":
if len(args) == 1:
parser.print_help()
sys.exit(1)
invoke_subcommand(args, parser, yocto_layer_help_usage, subcommands)
if __name__ == "__main__":
try:
ret = main()
except Exception:
ret = 1
import traceback
traceback.print_exc()
sys.exit(ret)