drop VERSION file, use __version__ directly in mic module
[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 try:
15     import mic
16     version = mic.__version__
17 except (ImportError, AttributeError):
18     version = "dev"
19
20 # --install-layout is recognized after 2.5
21 if sys.version_info[:2] > (2, 5):
22     if len(sys.argv) > 1 and 'install' in sys.argv:
23         try:
24             import platform
25             (dist, ver, id) = platform.linux_distribution()
26
27             # for debian-like distros, mods will be installed to
28             # ${PYTHONLIB}/dist-packages
29             if dist in ('debian', 'Ubuntu'):
30                 sys.argv.append('--install-layout=deb')
31         except:
32             pass
33
34 PACKAGES = [MOD_NAME,
35             MOD_NAME + '/utils',
36             MOD_NAME + '/imager',
37             MOD_NAME + '/kickstart',
38             MOD_NAME + '/kickstart/custom_commands',
39             MOD_NAME + '/3rdparty/pykickstart',
40             MOD_NAME + '/3rdparty/pykickstart/commands',
41             MOD_NAME + '/3rdparty/pykickstart/handlers',
42             MOD_NAME + '/3rdparty/pykickstart/urlgrabber',
43            ]
44
45 IMAGER_PLUGINS = glob.glob(os.path.join("plugins", "imager", "*.py"))
46 BACKEND_PLUGINS = glob.glob(os.path.join("plugins", "backend", "*.py"))
47
48 # the following code to do a simple parse for '--prefix' opts
49 prefix = sys.prefix
50 is_next = False
51 for arg in sys.argv:
52     if is_next:
53         prefix = arg
54         break
55     if '--prefix=' in arg:
56         prefix = arg[9:]
57         break
58     elif '--prefix' == arg:
59         is_next = True
60
61 # get the installation path of mic.conf
62 prefix = os.path.abspath(os.path.expanduser(prefix)).rstrip('/')
63 if prefix.lstrip('/') == 'usr':
64     etc_prefix = '/etc'
65 else:
66     etc_prefix = os.path.join(prefix, 'etc')
67
68 conffile = 'etc/mic.conf'
69 if os.path.isfile('%s/mic/mic.conf' % etc_prefix):
70     conffile += '.new'
71
72 # apply prefix to mic.conf.in to generate actual mic.conf
73 conf_str = file('etc/mic.conf.in').read()
74 conf_str = conf_str.replace('@PREFIX@', prefix)
75 with file(conffile, 'w') as wf:
76     wf.write(conf_str)
77
78 try:
79     os.environ['PREFIX'] = prefix
80     setup(name=MOD_NAME,
81           version = version,
82           description = 'Image Creator for Linux Distributions',
83           author='Jian-feng Ding, Qiang Zhang, Gui Chen',
84           author_email='jian-feng.ding@intel.com, qiang.z.zhang@intel.com, gui.chen@intel.com',
85           url='https://github.com/jfding/mic',
86           scripts=[
87               'tools/mic',
88               ],
89           packages = PACKAGES,
90           data_files = [("%s/lib/mic/plugins/imager" % prefix, IMAGER_PLUGINS),
91                         ("%s/lib/mic/plugins/backend" % prefix, BACKEND_PLUGINS),
92                         ("%s/mic" % etc_prefix, [conffile])]
93     )
94 finally:
95     # remove dynamic file distfiles/mic.conf
96     os.unlink(conffile)
97