1 | """
|
---|
2 | Copyright (C) 2009-2019 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 | The contents of this file may alternatively be used under the terms
|
---|
13 | of the Common Development and Distribution License Version 1.0
|
---|
14 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
15 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
16 | CDDL are applicable instead of those of the GPL.
|
---|
17 |
|
---|
18 | You may elect to license modified versions of this file under the
|
---|
19 | terms and conditions of either the GPL or the CDDL or both.
|
---|
20 | """
|
---|
21 |
|
---|
22 | import os,sys
|
---|
23 | from distutils.core import setup
|
---|
24 |
|
---|
25 | def cleanupComCache():
|
---|
26 | import shutil
|
---|
27 | from distutils.sysconfig import get_python_lib
|
---|
28 | comCache1 = os.path.join(get_python_lib(), 'win32com', 'gen_py')
|
---|
29 | comCache2 = os.path.join(os.environ.get("TEMP", "c:\\tmp"), 'gen_py')
|
---|
30 | print("Cleaning COM cache at",comCache1,"and",comCache2)
|
---|
31 | shutil.rmtree(comCache1, True)
|
---|
32 | shutil.rmtree(comCache2, True)
|
---|
33 |
|
---|
34 | def patchWith(file,install,sdk):
|
---|
35 | newFile=file + ".new"
|
---|
36 | install=install.replace("\\", "\\\\")
|
---|
37 | try:
|
---|
38 | os.remove(newFile)
|
---|
39 | except:
|
---|
40 | pass
|
---|
41 | oldF = open(file, 'r')
|
---|
42 | newF = open(newFile, 'w')
|
---|
43 | for line in oldF:
|
---|
44 | line = line.replace("%VBOX_INSTALL_PATH%", install)
|
---|
45 | line = line.replace("%VBOX_SDK_PATH%", sdk)
|
---|
46 | newF.write(line)
|
---|
47 | newF.close()
|
---|
48 | oldF.close()
|
---|
49 | try:
|
---|
50 | os.remove(file)
|
---|
51 | except:
|
---|
52 | pass
|
---|
53 | os.rename(newFile, file)
|
---|
54 |
|
---|
55 | # See http://docs.python.org/distutils/index.html
|
---|
56 | def main(argv):
|
---|
57 | vboxDest = os.environ.get("VBOX_MSI_INSTALL_PATH", None)
|
---|
58 | if vboxDest is None:
|
---|
59 | vboxDest = os.environ.get('VBOX_INSTALL_PATH', None)
|
---|
60 | if vboxDest is None:
|
---|
61 | raise Exception("No VBOX_INSTALL_PATH defined, exiting")
|
---|
62 |
|
---|
63 | vboxVersion = os.environ.get("VBOX_VERSION", None)
|
---|
64 | if vboxVersion is None:
|
---|
65 | # Should we use VBox version for binding module versioning?
|
---|
66 | vboxVersion = "1.0"
|
---|
67 |
|
---|
68 | import platform
|
---|
69 |
|
---|
70 | if platform.system() == 'Windows':
|
---|
71 | cleanupComCache()
|
---|
72 |
|
---|
73 | # Darwin: Patched before installation. Modifying bundle is not allowed, breaks signing and upsets gatekeeper.
|
---|
74 | if platform.system() != 'Darwin':
|
---|
75 | vboxSdkDest = os.path.join(vboxDest, "sdk")
|
---|
76 | patchWith(os.path.join(os.path.dirname(sys.argv[0]), 'vboxapi', '__init__.py'), vboxDest, vboxSdkDest)
|
---|
77 |
|
---|
78 | setup(name='vboxapi',
|
---|
79 | version=vboxVersion,
|
---|
80 | description='Python interface to VirtualBox',
|
---|
81 | author='Oracle Corp.',
|
---|
82 | author_email='vbox-dev@virtualbox.org',
|
---|
83 | url='http://www.virtualbox.org',
|
---|
84 | packages=['vboxapi']
|
---|
85 | )
|
---|
86 |
|
---|
87 | if __name__ == '__main__':
|
---|
88 | main(sys.argv)
|
---|
89 |
|
---|