viewgit/index.php:465 Only variables should be passed by reference [2048]
viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]
#!/usr/bin/python # # import tarfile import tempfile import json import os import sys import base64 import shutil import subprocess class Bundle(): """This class represent a bundle of an application that can be easily moved around.""" def __init__(self, appname = None): """ :param appname The name of the application whose this bundle refers to """ self._appname = appname self._bundle = None self._appcmd = None def bundle_app (self, appdir, appcmd): """Bundle an application and prepare it for distribution.""" if self._bundle is not None: raise RuntimeError ("Only a single application can be bundled") self._appcmd = appcmd self._appdir = appdir if (self._appdir.endswith ("/")): self._appdir = appdir[:-1] # Create the tar archive to be packed tmp_f = tempfile.NamedTemporaryFile (delete = False) tar = tarfile.TarFile (fileobj = tmp_f, mode = 'w') # Create packing information package_info = { 'name': self._appname, 'appcmd': self._appcmd, 'appdir': os.path.basename (self._appdir), } # Add the directory that needs to be packed together # with the info on how to run the package. We need to # chdir to the right place to have directory structure # packed right old_dir = os.getcwd () os.chdir (os.path.dirname (self._appdir)) tar.add (os.path.basename (self._appdir)) # Create the info file with open ("info.bundle", "w") as handle: handle.write (json.dumps (package_info)) tar.add ("info.bundle") # Close the tar file and copy the tar in my home tar.close () tmp_f.close () # Read the file with open (tmp_f.name, "rb") as handle: self._bundle = handle.read () # Remove the file since we don't need it anymore os.remove (tmp_f.name) # Pack the application with this python code to make # it unbundlable. os.chdir (old_dir) with open(__file__, "rb") as handle: file_content = handle.read () file_content += b"\n\n\n" + 15 * b"#" + base64.b64encode (self._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 with open(self._bundle_path, "w") as handle: handle.write (file_content.decode ("utf-8")) return self._bundle_path def unbundle_app (self): """Unbundle app assuming that it is contained in this file""" with open(__file__, "rb") as handle: self._bundle = handle.read () # Decode the content of the file start = self._bundle.index(15 * "#") self._bundle = base64.b64decode (self._bundle[start + 14:]) tmp_d = tempfile.mkdtemp () os.chdir (tmp_d) with open (os.path.join (tmp_d, "bundle.tar"), "wb") as handle: handle.write (self._bundle) tar = tarfile.open (os.path.join (tmp_d, "bundle.tar")) tar.extractall () tar.close () package_info = json.load (open ("info.bundle", "r")) os.chdir (package_info["appdir"]) p = subprocess.Popen (package_info["appcmd"], shell = True) 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_msg ("Starting bundle framework") if len (sys.argv) <= 1: print_msg ("Entering unbundle mode") bundle = Bundle () 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) if b_path is not None: print_msg ("Bundle created correctly as %s" % b_path) else: print_msg ("Bundle creation canceled")