64 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
| #! /usr/bin/env python
 | |
| 
 | |
| import os
 | |
| import zlib
 | |
| import base64
 | |
| import sys
 | |
| try:
 | |
|     import pickle
 | |
| except Importerror:
 | |
|     import cPickle as pickle
 | |
| 
 | |
| def pytest_addoption(parser):
 | |
|     group = parser.getgroup("general")
 | |
|     group.addoption("--genscript", action="store", default=None, 
 | |
|         dest="genscript", metavar="path", 
 | |
|         help="create standalone py.test script at given target path.")
 | |
| 
 | |
| def pytest_configure(config):
 | |
|     genscript = config.getvalue("genscript")
 | |
|     if genscript:
 | |
|         import py
 | |
|         mydir = py.path.local(__file__).dirpath()
 | |
|         infile = mydir.join("standalonetemplate.py")
 | |
|         pybasedir = py.path.local(py.__file__).dirpath().dirpath()
 | |
|         main(pybasedir, outfile=genscript, infile=infile)
 | |
|         raise SystemExit(0)
 | |
| 
 | |
| def main(pybasedir, outfile, infile):
 | |
|     os.chdir(str(pybasedir))
 | |
|     outfile = str(outfile)
 | |
|     infile = str(infile)
 | |
|     files = []
 | |
|     for dirpath, dirnames, filenames in os.walk("py"):
 | |
|         for f in filenames:
 | |
|             if not f.endswith(".py"):
 | |
|                 continue
 | |
|                 
 | |
|             fn = os.path.join(dirpath, f)
 | |
|             files.append(fn)
 | |
| 
 | |
|     name2src = {}
 | |
|     for f in files:
 | |
|         k = f.replace("/", ".")[:-3]
 | |
|         name2src[k] = open(f, "rb").read()
 | |
| 
 | |
|     data = pickle.dumps(name2src, 2)
 | |
|     data = zlib.compress(data, 9)
 | |
|     data = base64.encodestring(data)
 | |
| 
 | |
|     exe = open(infile, "rb").read()
 | |
|     exe = exe.replace("@SOURCES@", data)
 | |
| 
 | |
|     open(outfile, "wb").write(exe)
 | |
|     os.chmod(outfile, 493)  # 0755
 | |
|     sys.stdout.write("generated standalone py.test at %r, have fun!\n" % outfile)
 | |
| 
 | |
| if __name__=="__main__":
 | |
|     dn = os.path.dirname
 | |
|     here = os.path.abspath(dn(__file__)) # py/plugin/
 | |
|     pybasedir = dn(dn(here))
 | |
|     outfile = os.path.join(os.getcwd(), "py.test-standalone")
 | |
|     infile = os.path.join(here, 'standalonetemplate.py')
 | |
|     main(pybasedir, outfile, infile)
 |