diff options
Diffstat (limited to 'scripts/wic')
-rwxr-xr-x | scripts/wic | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/scripts/wic b/scripts/wic index 10a03eeea6..10ce440529 100755 --- a/scripts/wic +++ b/scripts/wic | |||
@@ -58,6 +58,23 @@ from wic.utils.errors import WicError | |||
58 | from wic import engine | 58 | from wic import engine |
59 | from wic import help as hlp | 59 | from wic import help as hlp |
60 | 60 | ||
61 | |||
62 | def wic_logger(): | ||
63 | """Create and convfigure wic logger.""" | ||
64 | logger = logging.getLogger('wic') | ||
65 | logger.setLevel(logging.INFO) | ||
66 | |||
67 | handler = logging.StreamHandler() | ||
68 | |||
69 | formatter = logging.Formatter('%(levelname)s: %(message)s') | ||
70 | handler.setFormatter(formatter) | ||
71 | |||
72 | logger.addHandler(handler) | ||
73 | |||
74 | return logger | ||
75 | |||
76 | logger = wic_logger() | ||
77 | |||
61 | def rootfs_dir_to_args(krootfs_dir): | 78 | def rootfs_dir_to_args(krootfs_dir): |
62 | """ | 79 | """ |
63 | Get a rootfs_dir dict and serialize to string | 80 | Get a rootfs_dir dict and serialize to string |
@@ -125,12 +142,12 @@ def wic_create_subcommand(args, usage_str): | |||
125 | (options, args) = parser.parse_args(args) | 142 | (options, args) = parser.parse_args(args) |
126 | 143 | ||
127 | if len(args) != 1: | 144 | if len(args) != 1: |
128 | logging.error("Wrong number of arguments, exiting\n") | 145 | logger.error("Wrong number of arguments, exiting\n") |
129 | parser.print_help() | 146 | parser.print_help() |
130 | sys.exit(1) | 147 | sys.exit(1) |
131 | 148 | ||
132 | if options.build_rootfs and not bitbake_main: | 149 | if options.build_rootfs and not bitbake_main: |
133 | logging.error("Can't build roofs as bitbake is not in the $PATH") | 150 | logger.error("Can't build roofs as bitbake is not in the $PATH") |
134 | sys.exit(1) | 151 | sys.exit(1) |
135 | 152 | ||
136 | if not options.image_name: | 153 | if not options.image_name: |
@@ -142,8 +159,8 @@ def wic_create_subcommand(args, usage_str): | |||
142 | if not val: | 159 | if not val: |
143 | missed.append(opt) | 160 | missed.append(opt) |
144 | if missed: | 161 | if missed: |
145 | print("The following build artifacts are not specified:") | 162 | logger.error("The following build artifacts are not specified: %s", |
146 | print(" " + ", ".join(missed)) | 163 | ", ".join(missed)) |
147 | sys.exit(1) | 164 | sys.exit(1) |
148 | 165 | ||
149 | if options.image_name: | 166 | if options.image_name: |
@@ -154,23 +171,22 @@ def wic_create_subcommand(args, usage_str): | |||
154 | if options.vars_dir: | 171 | if options.vars_dir: |
155 | BB_VARS.vars_dir = options.vars_dir | 172 | BB_VARS.vars_dir = options.vars_dir |
156 | 173 | ||
157 | if options.build_check: | 174 | if options.build_check and not engine.verify_build_env(): |
158 | print("Checking basic build environment...") | 175 | logger.error("Couldn't verify build environment, exiting\n") |
159 | if not engine.verify_build_env(): | 176 | sys.exit(1) |
160 | print("Couldn't verify build environment, exiting\n") | ||
161 | sys.exit(1) | ||
162 | else: | ||
163 | print("Done.\n") | ||
164 | 177 | ||
165 | bootimg_dir = "" | 178 | bootimg_dir = "" |
166 | 179 | ||
180 | if options.debug: | ||
181 | logger.setLevel(logging.DEBUG) | ||
182 | |||
167 | if options.image_name: | 183 | if options.image_name: |
168 | if options.build_rootfs: | 184 | if options.build_rootfs: |
169 | argv = ["bitbake", options.image_name] | 185 | argv = ["bitbake", options.image_name] |
170 | if options.debug: | 186 | if options.debug: |
171 | argv.append("--debug") | 187 | argv.append("--debug") |
172 | 188 | ||
173 | print("Building rootfs...\n") | 189 | logger.info("Building rootfs...\n") |
174 | if bitbake_main(BitBakeConfigParameters(argv), | 190 | if bitbake_main(BitBakeConfigParameters(argv), |
175 | cookerdata.CookerConfiguration()): | 191 | cookerdata.CookerConfiguration()): |
176 | sys.exit(1) | 192 | sys.exit(1) |
@@ -181,18 +197,18 @@ def wic_create_subcommand(args, usage_str): | |||
181 | "wic-tools", cache=False) | 197 | "wic-tools", cache=False) |
182 | else: | 198 | else: |
183 | if options.build_rootfs: | 199 | if options.build_rootfs: |
184 | print("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n") | 200 | logger.error("Image name is not specified, exiting. (Use -e/--image-name to specify it)\n") |
185 | sys.exit(1) | 201 | sys.exit(1) |
186 | native_sysroot = options.native_sysroot | 202 | native_sysroot = options.native_sysroot |
187 | 203 | ||
188 | if not native_sysroot or not os.path.isdir(native_sysroot): | 204 | if not native_sysroot or not os.path.isdir(native_sysroot): |
189 | print("Building wic-tools...\n") | 205 | logger.info("Building wic-tools...\n") |
190 | if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()), | 206 | if bitbake_main(BitBakeConfigParameters("bitbake wic-tools".split()), |
191 | cookerdata.CookerConfiguration()): | 207 | cookerdata.CookerConfiguration()): |
192 | sys.exit(1) | 208 | sys.exit(1) |
193 | native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 209 | native_sysroot = get_bitbake_var("RECIPE_SYSROOT_NATIVE", "wic-tools") |
194 | if not native_sysroot: | 210 | if not native_sysroot: |
195 | print("Unable to find the location of the native tools sysroot to use\n") | 211 | logger.info("Unable to find the location of the native tools sysroot to use\n") |
196 | sys.exit(1) | 212 | sys.exit(1) |
197 | 213 | ||
198 | wks_file = args[0] | 214 | wks_file = args[0] |
@@ -200,7 +216,7 @@ def wic_create_subcommand(args, usage_str): | |||
200 | if not wks_file.endswith(".wks"): | 216 | if not wks_file.endswith(".wks"): |
201 | wks_file = engine.find_canned_image(scripts_path, wks_file) | 217 | wks_file = engine.find_canned_image(scripts_path, wks_file) |
202 | if not wks_file: | 218 | if not wks_file: |
203 | print("No image named %s found, exiting. (Use 'wic list images' "\ | 219 | logger.error("No image named %s found, exiting. (Use 'wic list images' "\ |
204 | "to list available images, or specify a fully-qualified OE "\ | 220 | "to list available images, or specify a fully-qualified OE "\ |
205 | "kickstart (.wks) filename)\n" % args[0]) | 221 | "kickstart (.wks) filename)\n" % args[0]) |
206 | sys.exit(1) | 222 | sys.exit(1) |
@@ -213,16 +229,16 @@ def wic_create_subcommand(args, usage_str): | |||
213 | kernel_dir = options.kernel_dir | 229 | kernel_dir = options.kernel_dir |
214 | native_sysroot = options.native_sysroot | 230 | native_sysroot = options.native_sysroot |
215 | if rootfs_dir and not os.path.isdir(rootfs_dir): | 231 | if rootfs_dir and not os.path.isdir(rootfs_dir): |
216 | print("--roofs-dir (-r) not found, exiting\n") | 232 | logger.error("--roofs-dir (-r) not found, exiting\n") |
217 | sys.exit(1) | 233 | sys.exit(1) |
218 | if not os.path.isdir(bootimg_dir): | 234 | if not os.path.isdir(bootimg_dir): |
219 | print("--bootimg-dir (-b) not found, exiting\n") | 235 | logger.error("--bootimg-dir (-b) not found, exiting\n") |
220 | sys.exit(1) | 236 | sys.exit(1) |
221 | if not os.path.isdir(kernel_dir): | 237 | if not os.path.isdir(kernel_dir): |
222 | print("--kernel-dir (-k) not found, exiting\n") | 238 | logger.error("--kernel-dir (-k) not found, exiting\n") |
223 | sys.exit(1) | 239 | sys.exit(1) |
224 | if not os.path.isdir(native_sysroot): | 240 | if not os.path.isdir(native_sysroot): |
225 | print("--native-sysroot (-n) not found, exiting\n") | 241 | logger.error("--native-sysroot (-n) not found, exiting\n") |
226 | sys.exit(1) | 242 | sys.exit(1) |
227 | else: | 243 | else: |
228 | not_found = not_found_dir = "" | 244 | not_found = not_found_dir = "" |
@@ -235,12 +251,11 @@ def wic_create_subcommand(args, usage_str): | |||
235 | if not_found: | 251 | if not_found: |
236 | if not not_found_dir: | 252 | if not not_found_dir: |
237 | not_found_dir = "Completely missing artifact - wrong image (.wks) used?" | 253 | not_found_dir = "Completely missing artifact - wrong image (.wks) used?" |
238 | print("Build artifacts not found, exiting.") | 254 | logger.error("Build artifacts not found, exiting.") |
239 | print(" (Please check that the build artifacts for the machine") | 255 | logger.info(" (Please check that the build artifacts for the machine") |
240 | print(" selected in local.conf actually exist and that they") | 256 | logger.info(" selected in local.conf actually exist and that they") |
241 | print(" are the correct artifacts for the image (.wks file)).\n") | 257 | logger.info(" are the correct artifacts for the image (.wks file)).\n") |
242 | print("The artifact that couldn't be found was %s:\n %s" % \ | 258 | logger.info("The artifact that couldn't be found was %s:\n %s", not_found, not_found_dir) |
243 | (not_found, not_found_dir)) | ||
244 | sys.exit(1) | 259 | sys.exit(1) |
245 | 260 | ||
246 | krootfs_dir = options.rootfs_dir | 261 | krootfs_dir = options.rootfs_dir |
@@ -250,7 +265,7 @@ def wic_create_subcommand(args, usage_str): | |||
250 | 265 | ||
251 | rootfs_dir = rootfs_dir_to_args(krootfs_dir) | 266 | rootfs_dir = rootfs_dir_to_args(krootfs_dir) |
252 | 267 | ||
253 | print("Creating image(s)...\n") | 268 | logger.info("Creating image(s)...\n") |
254 | engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, | 269 | engine.wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir, |
255 | native_sysroot, options) | 270 | native_sysroot, options) |
256 | 271 | ||
@@ -264,7 +279,7 @@ def wic_list_subcommand(args, usage_str): | |||
264 | args = parser.parse_args(args)[1] | 279 | args = parser.parse_args(args)[1] |
265 | 280 | ||
266 | if not engine.wic_list(args, scripts_path): | 281 | if not engine.wic_list(args, scripts_path): |
267 | logging.error("Bad list arguments, exiting\n") | 282 | logger.error("Bad list arguments, exiting\n") |
268 | parser.print_help() | 283 | parser.print_help() |
269 | sys.exit(1) | 284 | sys.exit(1) |
270 | 285 | ||
@@ -301,10 +316,6 @@ subcommands = { | |||
301 | } | 316 | } |
302 | 317 | ||
303 | 318 | ||
304 | def start_logging(loglevel): | ||
305 | logging.basicConfig(filename='wic.log', filemode='w', level=loglevel) | ||
306 | |||
307 | |||
308 | def main(argv): | 319 | def main(argv): |
309 | parser = optparse.OptionParser(version="wic version %s" % __version__, | 320 | parser = optparse.OptionParser(version="wic version %s" % __version__, |
310 | usage=hlp.wic_usage) | 321 | usage=hlp.wic_usage) |
@@ -326,6 +337,6 @@ if __name__ == "__main__": | |||
326 | try: | 337 | try: |
327 | sys.exit(main(sys.argv[1:])) | 338 | sys.exit(main(sys.argv[1:])) |
328 | except WicError as err: | 339 | except WicError as err: |
329 | print("ERROR:", err, file=sys.stderr) | 340 | logger.error(err) |
330 | sys.exit(1) | 341 | sys.exit(1) |
331 | 342 | ||