Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. ipy.exe ToolsScriptspyc.py /main:test.py /target:exe
  2.  
  3. #!/usr/bin/env python
  4. # CompileToStandalone, a Python to .NET ILR compiler which produces standalone binaries
  5. # (C) 2012 Niall Douglas http://www.nedproductions.biz/
  6. # Created: March 2012
  7.  
  8. import modulefinder, sys, os, subprocess, _winreg
  9.  
  10. if len(sys.argv)<2:
  11. print("Usage: CompileEverythingToILR.py <source py> [-outdir=<dest dir>]")
  12. sys.exit(0)
  13.  
  14. if sys.platform=="cli":
  15. print("ERROR: IronPython's ModuleFinder currently doesn't work, so run me under CPython please")
  16. sys.exit(1)
  17.  
  18. sourcepath=sys.argv[1]
  19. destpath=sys.argv[2][8:] if len(sys.argv)==3 else os.path.dirname(sys.argv[0])
  20. ironpythonpath=None
  21. try:
  22. try:
  23. keyh=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\IronPython\2.7\InstallPath")
  24. ironpythonpath=_winreg.QueryValue(keyh, None)
  25. except Exception as e:
  26. try:
  27. keyh=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\Wow6432Node\IronPython\2.7\InstallPath")
  28. ironpythonpath=_winreg.QueryValue(keyh, "")
  29. except Exception as e:
  30. pass
  31. finally:
  32. if ironpythonpath is not None:
  33. _winreg.CloseKey(keyh)
  34. print("IronPython found at "+ironpythonpath)
  35. else:
  36. raise Exception("Cannot find IronPython in the registry")
  37.  
  38. # What we do now is to load the python source but against the customised IronPython runtime
  39. # library which has been hacked to work with IronPython. This spits out the right set of
  40. # modules mostly, but we include the main python's site-packages in order to resolve any
  41. # third party packages
  42. print("Scanning '"+sourcepath+"' for dependencies and outputting into '"+destpath+"' ...")
  43. searchpaths=[".", ironpythonpath+os.sep+"Lib"]
  44. searchpaths+=[x for x in sys.path if 'site-packages' in x]
  45. finder=modulefinder.ModuleFinder(searchpaths)
  46. finder.run_script(sourcepath)
  47. print(finder.report())
  48. modules=[]
  49. badmodules=finder.badmodules.keys()
  50. for name, mod in finder.modules.iteritems():
  51. path=mod.__file__
  52. # Ignore internal modules
  53. if path is None: continue
  54. # Ignore DLL internal modules
  55. #if '\DLLs\' in path: continue
  56. # Watch out for C modules
  57. if os.path.splitext(path)[1]=='.pyd':
  58. print("WARNING: I don't support handling C modules at '"+path+"'")
  59. badmodules.append(name)
  60. continue
  61. modules.append((name, os.path.abspath(path)))
  62. modules.sort()
  63. print("Modules not imported due to not found, error or being a C module:")
  64. print("n".join(badmodules))
  65. raw_input("nPress Return if you are happy with these missing modules ...")
  66.  
  67. with open(destpath+os.sep+"files.txt", "w") as oh:
  68. oh.writelines([x[1]+'n' for x in modules])
  69. cmd='ipy64 '+destpath+os.sep+'pyc.py /main:"'+os.path.abspath(sourcepath)+'" /out:'+os.path.splitext(os.path.basename(sourcepath))[0]+' /target:exe /standalone /platform:x86 /files:'+destpath+os.sep+'files.txt'
  70. print(cmd)
  71. cwd=os.getcwd()
  72. try:
  73. os.chdir(destpath)
  74. retcode=subprocess.call(cmd, shell=True)
  75. finally:
  76. os.chdir(cwd)
  77. sys.exit(retcode)
  78.  
  79. Traceback (most recent call last):
  80. File "pycpyc.py", line 35, in pycpyc.py
  81. AttributeError: attribute 'CompilerSink' of 'namespace#' object is read-only
  82.  
  83. Traceback (most recent call last):
  84. File "pycpyc.py", line 170, in pycpyc.py
  85. File "pycpyc.py", line 56, in Main
  86. AttributeError: attribute 'ResourceFile' of 'namespace#' object is read-only
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement