WIP Confirm formatting and writing images
authorŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 3 Oct 2023 18:41:24 +0000 (20:41 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Tue, 3 Oct 2023 18:41:24 +0000 (20:41 +0200)
Change-Id: I228acfa32416df6a8d48e12a9f6473d4deb763b1
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
scripts/tizen/sd_fusing.py

index f14bd40..281a090 100755 (executable)
@@ -20,6 +20,7 @@ __version__ = "1.0.0"
 Format = False
 Device = ""
 File = ""
+Yes = False
 
 class DebugFormatter(logging.Formatter):
     def format(self, record):
@@ -455,6 +456,7 @@ def mkpart(args, target):
 
 def check_args(args):
     global Format
+    global Yes
 
     logging.info(f"Device: {args.device}")
 
@@ -462,13 +464,22 @@ def check_args(args):
         logging.info("Fusing binar{}: {}".format("y" if len(args.binaries) == 1 else "ies",
                      ", ".join(args.binaries)))
 
+    if args.YES:
+        Yes = True
+
     if args.create:
         Format = True
+        Yes = True
 
-    if args.format or Format:
-        response = input(f"{args.device} will be formatted. Is it OK? [y/N] ")
-        if response.lower() in ('y', 'yes'):
+    if args.format:
+        if Yes:
             Format = True
+        else:
+            response = input(f"{args.device} will be formatted. Continue? [y/N] ")
+            if response.lower() in ('y', 'yes'):
+                Format = True
+            else:
+                Format = False
 
 def check_device(args):
     global Format
@@ -656,8 +667,20 @@ def do_fuse_image(img, target):
         do_fuse_file(f, os.path.basename(img), target)
 
 def fuse_image(args, target):
+    global Yes
+
     if args.binaries is None or len(args.binaries) == 0:
         return
+
+    if not Yes and not Format:
+        print(f"The following images will be written to {args.device} and the "
+              "existing data will be lost.\n")
+        for b in args.binaries:
+            print("  " + b)
+        response = input("\nContinue? [y/N] ")
+        if not response.lower() in ('y', 'yes'):
+            return
+
     with tempfile.TemporaryDirectory() as tmpd:
         for b in args.binaries:
             if re.search('\.(tar|tar\.gz|tgz)$', b):
@@ -701,6 +724,8 @@ if __name__ == '__main__':
                         help="Choose partition set to update: a or b.")
     parser.add_argument("--version", action="version",
                         version=f"%(prog)s {__version__}")
+    parser.add_argument("--YES", action="store_true",
+                        help="agree to to destroy data on ")
     args = parser.parse_args()
 
     if args.target == 'list':