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, 'cmd': self._appcmd, 'dir': 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): 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 def tar_filter (self, tarinfo): """Check if a file has to be packed or not, and skips files such as version control logs and source files""" pass 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 ("utf-8") # Decode the content of the file start = self._bundle.index(15 * "#") self._bundle = base64.b64decode (self._bundle[start + 14:].encode ("utf-8")) tmp_d = tempfile.mkdtemp () os.chdir (tmp_d) with open ("bundle.tar", "wb") as handle: handle.write (self._bundle) tar = tarfile.open ("bundle.tar") tar.extractall () tar.close () package_info = json.load (open ("info.bundle", "r")) print_msg ("Launching %s" % package_info["name"]) os.chdir (package_info["dir"]) # Executing the program p = subprocess.Popen (package_info["cmd"], shell = True) p.wait () # Remove extracted files shutil.rmtree (tmp_d) def print_msg (msg): print ("\033[31;1m> \033[0m%s" % msg) def print_help (): help_text = """ Bundle.py v0.1 --- A simple framework to pack applications bundle.py is a simple python script that packs compiled application in a single autoextracting python file that can be executed and runs the application. To pack your application, simply create an application.info file similar to this (JSON coded dictionary) { "name": "My beatiful application", "path": "/home/me/dev/my_app", "cmd": "./src/my_app" } and then run ./bundle.py application.info """ print (help_text) sys.exit (0) if __name__ == "__main__": # Check if this is the bundle.py source file # and if it does not contain a bundle with open (__file__, "r") as handle: if len(sys.argv) <= 1 and not (15 * "#") in handle.read (): print_help () 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") package_info = json.load (open (sys.argv[1], "r")) bundle = Bundle (package_info["name"]) b_path = bundle.bundle_app (package_info["path"], package_info["cmd"]) if b_path is not None: print_msg ("Bundle created correctly as %s" % b_path) else: print_msg ("Bundle creation canceled")