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]

  1. #!/usr/bin/python
  2. #
  3. #
  4.  
  5. import tarfile
  6. import tempfile
  7. import json
  8. import os
  9. import sys
  10. import base64
  11. import shutil
  12. import subprocess
  13.  
  14. class Bundle():
  15. """This class represent a bundle of an application
  16. that can be easily moved around."""
  17.  
  18. def __init__(self, appname = None):
  19. """
  20. :param appname The name of the application
  21. whose this bundle refers to
  22. """
  23. self._appname = appname
  24. self._bundle = None
  25. self._appcmd = None
  26.  
  27.  
  28. def bundle_app (self, appdir, appcmd):
  29. """Bundle an application and prepare it for
  30. distribution."""
  31. if self._bundle is not None:
  32. raise RuntimeError ("Only a single application can be bundled")
  33. self._appcmd = appcmd
  34. self._appdir = appdir
  35. if (self._appdir.endswith ("/")):
  36. self._appdir = appdir[:-1]
  37.  
  38. # Create the tar archive to be packed
  39. tmp_f = tempfile.NamedTemporaryFile (delete = False)
  40. tar = tarfile.TarFile (fileobj = tmp_f, mode = 'w')
  41.  
  42. # Create packing information
  43. package_info = {
  44. 'name': self._appname,
  45. 'appcmd': self._appcmd,
  46. 'appdir': os.path.basename (self._appdir),
  47. }
  48.  
  49. # Add the directory that needs to be packed together
  50. # with the info on how to run the package. We need to
  51. # chdir to the right place to have directory structure
  52. # packed right
  53. old_dir = os.getcwd ()
  54. os.chdir (os.path.dirname (self._appdir))
  55. tar.add (os.path.basename (self._appdir))
  56.  
  57. # Create the info file
  58. with open ("info.bundle", "w") as handle:
  59. handle.write (json.dumps (package_info))
  60. tar.add ("info.bundle")
  61.  
  62. # Close the tar file and copy the tar in my home
  63. tar.close ()
  64. tmp_f.close ()
  65.  
  66. # Read the file
  67. with open (tmp_f.name, "rb") as handle:
  68. self._bundle = handle.read ()
  69.  
  70. # Remove the file since we don't need it anymore
  71. os.remove (tmp_f.name)
  72.  
  73. # Pack the application with this python code to make
  74. # it unbundlable.
  75. os.chdir (old_dir)
  76. with open(__file__, "rb") as handle:
  77. file_content = handle.read ()
  78.  
  79. file_content += b"\n\n\n" + 15 * b"#" + base64.b64encode (self._bundle)
  80.  
  81. # Dump file_content
  82. with open(self._appname + ".bundle", "w") as handle:
  83. handle.write (file_content.decode ("utf-8"))
  84.  
  85.  
  86. def unbundle_app (self):
  87. """Unbundle app assuming that it is contained in this file"""
  88. with open(__file__, "rb") as handle:
  89. self._bundle = handle.read ()
  90.  
  91. # Decode the content of the file
  92. start = self._bundle.index(15 * "#")
  93. self._bundle = base64.b64decode (self._bundle[start + 14:])
  94.  
  95. tmp_d = tempfile.mkdtemp ()
  96. os.chdir (tmp_d)
  97.  
  98. with open (os.path.join (tmp_d, "bundle.tar"), "wb") as handle:
  99. handle.write (self._bundle)
  100. tar = tarfile.open (os.path.join (tmp_d, "bundle.tar"))
  101. tar.extractall ()
  102. tar.close ()
  103.  
  104. package_info = json.load (open ("info.bundle", "r"))
  105. os.chdir (package_info["appdir"])
  106. p = subprocess.Popen (package_info["appcmd"], shell = True)
  107. p.wait ()
  108. shutil.rmtree (tmp_d)
  109.  
  110.  
  111.  
  112. if __name__ == "__main__":
  113.  
  114. print ("Starting bundle framework")
  115.  
  116. if len (sys.argv) <= 1:
  117. print ("Entering unbundle mode")
  118. bundle = Bundle ()
  119. bundle.unbundle_app ()
  120. else:
  121. if sys.argv[1] == "bundle":
  122. bundle = Bundle (sys.argv[2])
  123. bundle.bundle_app (sys.argv[3], sys.argv[4])