Some fixes in the bundle, such as pretty print

Leonardo Robol [2011-10-02 10:19]
Some fixes in the bundle, such as pretty print
Filename
bundle.py
diff --git a/bundle.py b/bundle.py
index b183af2..c245238 100644
--- a/bundle.py
+++ b/bundle.py
@@ -79,8 +79,14 @@ class Bundle():
         file_content += b"\n\n\n" + 15 * b"#" + base64.b64encode (self._bundle)

         # Dump file_content
-        with open(self._appname + ".bundle", "w") as handle:
+        self._bundle_path = self._appname + ".bundle"
+        if os.path.exists (self._bundle_path):
+            r = ask ("%s already exists, overwrite it? [y/n]" % self._bundle_path)
+            if (r != "y"):
+                return None
+        with open(self._bundle_path, "w") as handle:
             handle.write (file_content.decode ("utf-8"))
+        return self._bundle_path


     def unbundle_app (self):
@@ -107,17 +113,29 @@ class Bundle():
         p.wait ()
         shutil.rmtree (tmp_d)

-
+def ask (question):
+    return raw_input ("\033[32;1m> \033[0m" + question + ": ")
+
+def print_msg (msg):
+    print ("\033[31;1m> \033[0m%s" % msg)

 if __name__ == "__main__":

-    print ("Starting bundle framework")
+    print_msg ("Starting bundle framework")

     if len (sys.argv) <= 1:
-        print ("Entering unbundle mode")
+        print_msg ("Entering unbundle mode")
         bundle = Bundle ()
         bundle.unbundle_app ()
     else:
-        if sys.argv[1] == "bundle":
-            bundle = Bundle (sys.argv[2])
-            bundle.bundle_app (sys.argv[3], sys.argv[4])
+        print_msg ("Entering bundle mode")
+        appdir = sys.argv[1]
+        appname = ask ("Enter bundle name")
+        appcmd =  ask ("Enter the command to run the application")
+        bundle = Bundle (appname)
+        b_path = bundle.bundle_app (appdir, appcmd)
+
+        if b_path is not None:
+            print_msg ("Bundle created correctly as %s" % b_path)
+        else:
+            print_msg ("Bundle creation canceled")
ViewGit