bundle.py works with python3 and python2, except for python3.2 where tarfile
Leonardo Robol [2011-10-02 13:36]
bundle.py works with python3 and python2, except for python3.2 where tarfile
is broken (hopefully the bug is being solved).
diff --git a/bundle.py b/bundle.py
index ebaccb8..8a6bd46 100755
--- a/bundle.py
+++ b/bundle.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python3
+#!/usr/bin/python
#
#
@@ -81,9 +81,8 @@ class Bundle():
# Dump file_content
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
+ print_msg ("Not overwriting %s, please remove it manually" % self._bundle_path)
+ return None
with open(self._bundle_path, "w") as handle:
handle.write (file_content.decode ("utf-8"))
return self._bundle_path
@@ -101,25 +100,22 @@ class Bundle():
tmp_d = tempfile.mkdtemp ()
os.chdir (tmp_d)
- with open (os.path.join (tmp_d, "bundle.tar"), "wb") as handle:
+ with open ("bundle.tar", "wb") as handle:
handle.write (self._bundle)
- tar = tarfile.open (os.path.join (tmp_d, "bundle.tar"))
+ tar = tarfile.open ("bundle.tar")
+
tar.extractall ()
tar.close ()
package_info = json.load (open ("info.bundle", "r"))
os.chdir (package_info["appdir"])
+
+ # Executing the program
p = subprocess.Popen (package_info["appcmd"], shell = True)
p.wait ()
- shutil.rmtree (tmp_d)
-def ask (question):
- if sys.version_info > (3,0):
- print ("\033[32;1m>\033[0m", str(question), ":", end=" ")
- sys.stdout.flush ()
- return sys.stdin.readline ().strip ("\n")
- else:
- return raw_input ("\033[32;1m> \033[0m" + str(question) +": ")
+ # Remove extracted files
+ shutil.rmtree (tmp_d)
def print_msg (msg):
print ("\033[31;1m> \033[0m%s" % msg)
@@ -134,11 +130,10 @@ if __name__ == "__main__":
bundle.unbundle_app ()
else:
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)
+ package_info = json.load (open (sys.argv[1], "r"))
+ bundle = Bundle (package_info["appname"])
+ b_path = bundle.bundle_app (package_info["appdir"],
+ package_info["appcmd"])
if b_path is not None:
print_msg ("Bundle created correctly as %s" % b_path)