binman: Use underscore in test filenames
[oweals/u-boot.git] / tools / binman / control.py
index 9e7587864ce0d1a8b30f3a50adeac0232fc3cfc6..8268eda37eae5c2f50997287dca26e8bb6ba7be8 100644 (file)
@@ -15,8 +15,6 @@ import tools
 import cbfs_util
 import command
 import elf
-from image import Image
-import state
 import tout
 
 # List of images we plan to create
@@ -113,6 +111,9 @@ def ReadEntry(image_fname, entry_path, decomp=True):
     Returns:
         data extracted from the entry
     """
+    global Image
+    from image import Image
+
     image = Image.FromFile(image_fname)
     entry = image.FindEntryPath(entry_path)
     return entry.ReadData(decomp)
@@ -459,6 +460,9 @@ def Binman(args):
     Args:
         args: Command line arguments Namespace object
     """
+    global Image
+    global state
+
     if args.full_help:
         pager = os.getenv('PAGER')
         if not pager:
@@ -468,29 +472,27 @@ def Binman(args):
         command.Run(pager, fname)
         return 0
 
-    if args.cmd == 'ls':
-        try:
-            tools.PrepareOutputDir(None)
-            ListEntries(args.image, args.paths)
-        finally:
-            tools.FinaliseOutputDir()
-        return 0
-
-    if args.cmd == 'extract':
-        try:
-            tools.PrepareOutputDir(None)
-            ExtractEntries(args.image, args.filename, args.outdir, args.paths,
-                           not args.uncompressed)
-        finally:
-            tools.FinaliseOutputDir()
-        return 0
+    # Put these here so that we can import this module without libfdt
+    from image import Image
+    import state
 
-    if args.cmd == 'replace':
+    if args.cmd in ['ls', 'extract', 'replace']:
         try:
+            tout.Init(args.verbosity)
             tools.PrepareOutputDir(None)
-            ReplaceEntries(args.image, args.filename, args.indir, args.paths,
-                           do_compress=not args.compressed,
-                           allow_resize=not args.fix_size, write_map=args.map)
+            if args.cmd == 'ls':
+                ListEntries(args.image, args.paths)
+
+            if args.cmd == 'extract':
+                ExtractEntries(args.image, args.filename, args.outdir, args.paths,
+                               not args.uncompressed)
+
+            if args.cmd == 'replace':
+                ReplaceEntries(args.image, args.filename, args.indir, args.paths,
+                               do_compress=not args.compressed,
+                               allow_resize=not args.fix_size, write_map=args.map)
+        except:
+            raise
         finally:
             tools.FinaliseOutputDir()
         return 0