bump up to release 2.0.1
[tools/mic.git] / setup.py
1
2 # Copyright (c) 2014 Intel, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the Free
6 # Software Foundation; version 2 of the License
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc., 59
15 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 """
18     Main for installing mic
19 """
20
21
22 import os, sys
23 import glob
24 from distutils.core import setup
25
26
27 MOD_NAME = 'mic'
28
29
30 def check_debian():
31     """--install-layout is recognized after 2.5"""
32     if sys.version_info[:2] > (2, 5):
33         if len(sys.argv) > 1 and 'install' in sys.argv:
34             try:
35                 import platform
36                 (dist, _, _) = platform.linux_distribution()
37                 # for debian-like distros, mods will be installed to
38                 # ${PYTHONLIB}/dist-packages
39                 if dist in ('debian', 'Ubuntu'):
40                     sys.argv.append('--install-layout=deb')
41             except AttributeError:
42                 pass
43
44
45 def create_conf_file():
46     """Apply prefix to mic.conf.in to generate actual mic.conf"""
47     with open('etc/mic.conf.in') as source_file:
48         conf_str = source_file.read()
49         conf_str = conf_str.replace('@PREFIX@', PREFIX)
50         with open(CONF_FILE, 'w') as conf_file:
51             conf_file.write(conf_str)
52
53
54 try:
55     import mic
56     VERSION = mic.__version__
57 except (ImportError, AttributeError):
58     VERSION = "dev"
59
60 check_debian()
61
62 PACKAGES = [MOD_NAME,
63             MOD_NAME + '/utils',
64             MOD_NAME + '/imager',
65             MOD_NAME + '/kickstart',
66             MOD_NAME + '/kickstart/custom_commands',
67             MOD_NAME + '/3rdparty/pykickstart',
68             MOD_NAME + '/3rdparty/pykickstart/commands',
69             MOD_NAME + '/3rdparty/pykickstart/handlers',
70             MOD_NAME + '/3rdparty/urlgrabber',
71             MOD_NAME + '/3rdparty/requests',
72             MOD_NAME + '/3rdparty/requests/packages',
73             MOD_NAME + '/3rdparty/requests/packages/urllib3',
74             MOD_NAME + '/3rdparty/requests/packages/chardet',
75             MOD_NAME + '/3rdparty/requests/packages/urllib3/packages',
76             MOD_NAME + '/3rdparty/requests/packages/urllib3/contrib',
77             MOD_NAME + '/3rdparty/requests/packages/urllib3/util',
78             MOD_NAME + '/3rdparty/requests/packages/urllib3/packages/ssl_match_hostname',
79            ]
80
81 IMAGER_PLUGINS = glob.glob(os.path.join("plugins", "imager", "*.py"))
82 BACKEND_PLUGINS = glob.glob(os.path.join("plugins", "backend", "*.py"))
83
84 PREFIX = sys.prefix
85 # if real_prefix, it must be in virtualenv, use prefix as root
86 ROOT = sys.prefix if hasattr(sys, 'real_prefix') else ''
87
88 CONF_FILE = 'etc/mic.conf'
89 create_conf_file()
90
91 setup(name=MOD_NAME,
92   version = VERSION,
93   description = 'Image Creator for Linux Distributions',
94   author='Jian-feng Ding, Qiang Zhang, Gui Chen',
95   author_email='jian-feng.ding@intel.com, qiang.z.zhang@intel.com,\
96                 gui.chen@intel.com',
97   url='https://github.com/01org/mic',
98   scripts=[
99       'tools/mic',
100       ],
101   packages = PACKAGES,
102   data_files = [("%s/lib/mic/plugins/imager" % PREFIX, IMAGER_PLUGINS),
103                 ("%s/lib/mic/plugins/backend" % PREFIX, BACKEND_PLUGINS),
104                 ("%s/etc/mic" % ROOT, [CONF_FILE])]
105 )