home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Aplikacje_64-bitowe / VirtualBox / VirtualBox-4.1.2-73507-Win.exe / file_vboxapisetup.py < prev    next >
Encoding:
Python Source  |  2011-07-21  |  2.6 KB  |  77 lines

  1. #
  2. # Copyright (C) 2009 Oracle Corporation
  3. #
  4. # This file is part of VirtualBox Open Source Edition (OSE), as
  5. # available from http://www.virtualbox.org. This file is free software;
  6. # you can redistribute it and/or modify it under the terms of the GNU
  7. # General Public License (GPL) as published by the Free Software
  8. # Foundation, in version 2 as it comes in the "COPYING" file of the
  9. # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
  10. # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  11. #
  12.  
  13. import os,sys
  14. from distutils.core import setup
  15.  
  16. def cleanupComCache():
  17.     import shutil
  18.     from distutils.sysconfig import get_python_lib
  19.     comCache1 = os.path.join(get_python_lib(),'win32com', 'gen_py')
  20.     comCache2 = os.path.join(os.environ.get("TEMP", "c:\\tmp"), 'gen_py')
  21.     print "Cleaning COM cache at",comCache1,"and",comCache2
  22.     shutil.rmtree(comCache1, True)
  23.     shutil.rmtree(comCache2, True)
  24.  
  25. def patchWith(file,install,sdk):
  26.     newFile=file+".new"
  27.     install=install.replace("\\", "\\\\")
  28.     try:
  29.         os.remove(newFile)
  30.     except:
  31.         pass
  32.     oldF = open(file, 'r')
  33.     newF = open(newFile, 'w')
  34.     for line in oldF:
  35.         line=line.replace("%VBOX_INSTALL_PATH%",install)
  36.         line=line.replace("%VBOX_SDK_PATH%",sdk)
  37.         newF.write(line)
  38.     newF.close()
  39.     oldF.close()
  40.     try:
  41.         os.remove(file)
  42.     except:
  43.         pass
  44.     os.rename(newFile, file)
  45.  
  46. # See http://docs.python.org/distutils/index.html
  47. def main(argv):
  48.     vboxDest=os.environ.get("VBOX_INSTALL_PATH", None)
  49.     if vboxDest is None:
  50.         raise Exception("No VBOX_INSTALL_PATH defined, exiting")
  51.     vboxVersion=os.environ.get("VBOX_VERSION", None)
  52.     if vboxVersion is None:
  53.         # Should we use VBox version for binding module versioning?
  54.         vboxVersion = "1.0"
  55.     import platform
  56.     if platform.system() == 'Darwin':
  57.         vboxSdkDest = os.path.join(vboxDest, "..", "..", "..", "sdk")
  58.         if not os.path.isdir(vboxSdkDest):
  59.             vboxSdkDest = os.path.join(vboxDest, "sdk")
  60.     else:
  61.         vboxSdkDest = os.path.join(vboxDest, "sdk")
  62.     if platform.system() == 'Windows':
  63.         cleanupComCache()
  64.     patchWith(os.path.join(os.path.dirname(sys.argv[0]), 'vboxapi', '__init__.py'), vboxDest, vboxSdkDest)
  65.     setup(name='vboxapi',
  66.       version=vboxVersion,
  67.       description='Python interface to VirtualBox',
  68.       author='Oracle Corp.',
  69.       author_email='vbox-dev@virtualbox.org',
  70.       url='http://www.virtualbox.org',
  71.       packages=['vboxapi']
  72.       )
  73.  
  74.  
  75. if __name__ == '__main__':
  76.     main(sys.argv)
  77.