remove all hardcoded path in setup.py
[tools/mic.git] / setup.py
1 #!/usr/bin/env python
2
3 import os, sys
4 import glob
5 from distutils.core import setup
6 try:
7     import setuptools
8     # enable "setup.py develop", optional
9 except ImportError:
10     pass
11
12 MOD_NAME = 'mic'
13
14 version_path = 'VERSION'
15 if not os.path.isfile(version_path):
16     print 'No VERSION file in topdir, abort'
17     sys.exit(1)
18
19 try:
20     # first line should be the version number
21     version = open(version_path).readline().strip()
22     if not version:
23         print 'VERSION file is invalid, abort'
24         sys.exit(1)
25
26     ver_file = open('%s/__version__.py' % MOD_NAME, 'w')
27     ver_file.write("VERSION = \"%s\"\n" % version)
28     ver_file.close()
29 except IOError:
30     print 'WARNING: Cannot write version number file'
31
32 # --install-layout is recognized after 2.5
33 if sys.version_info[:2] > (2, 5):
34     if len(sys.argv) > 1 and 'install' in sys.argv:
35         try:
36             import platform
37             (dist, ver, id) = platform.linux_distribution()
38
39             # for debian-like distros, mods will be installed to
40             # ${PYTHONLIB}/dist-packages
41             if dist in ('debian', 'Ubuntu'):
42                 sys.argv.append('--install-layout=deb')
43         except:
44             pass
45
46 PACKAGES = [MOD_NAME,
47             MOD_NAME + '/utils',
48             MOD_NAME + '/imager',
49             MOD_NAME + '/kickstart',
50             MOD_NAME + '/kickstart/custom_commands',
51             MOD_NAME + '/3rdparty/pykickstart',
52             MOD_NAME + '/3rdparty/pykickstart/commands',
53             MOD_NAME + '/3rdparty/pykickstart/handlers',
54             MOD_NAME + '/3rdparty/pykickstart/urlgrabber',
55            ]
56
57 IMAGER_PLUGINS = glob.glob(os.path.join("plugins", "imager", "*.py"))
58 BACKEND_PLUGINS = glob.glob(os.path.join("plugins", "backend", "*.py"))
59
60 # the following code to do a simple parse for '--prefix' opts
61 prefix = '/usr'
62 is_next = False
63 for arg in sys.argv:
64     if is_next:
65         prefix = arg
66         break
67     if '--prefix=' in arg:
68         prefix = arg[9:]
69     elif '--prefix' == arg:
70         is_next = True
71
72 if prefix == '/usr':
73     etc_prefix = '/etc'
74 else:
75     etc_prefix = os.path.join(prefix, 'etc')
76
77 # apply prefix to mic.conf.in to generate actual mic.conf
78 conf_str = file('distfiles/mic.conf.in').read()
79 conf_str = conf_str.replace('@PREFIX@', prefix)
80 with file('distfiles/mic.conf', 'w') as wf:
81     wf.write(conf_str)
82
83 try:
84     setup(name=MOD_NAME,
85           version = version,
86           description = 'Image Creator for Linux Distributions',
87           author='Jian-feng Ding, Qiang Zhang, Gui Chen',
88           author_email='jian-feng.ding@intel.com, qiang.z.zhang@intel.com, gui.chen@intel.com',
89           url='https://github.com/jfding/mic',
90           scripts=[
91               'tools/mic',
92               ],
93           packages = PACKAGES,
94           data_files = [("%s/lib/mic/plugins/imager" % prefix, IMAGER_PLUGINS),
95                         ("%s/lib/mic/plugins/backend" % prefix, BACKEND_PLUGINS),
96                         ("%s/mic" % etc_prefix, ["distfiles/mic.conf"])]
97     )
98 finally:
99     # remove dynamic file distfiles/mic.conf
100     os.unlink('distfiles/mic.conf')
101