1 #!/usr/bin/env python |
1 #!/usr/bin/env python |
|
2 # pylint: disable-msg=W0404,W0622,W0704,W0613,W0152 |
2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
3 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
4 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
4 # |
|
5 # This file is part of CubicWeb. |
|
6 # |
|
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
8 # terms of the GNU Lesser General Public License as published by the Free |
|
9 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
10 # any later version. |
|
11 # |
|
12 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
14 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
15 # details. |
|
16 # |
|
17 # You should have received a copy of the GNU Lesser General Public License along |
|
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
19 """ |
|
20 |
5 |
21 """ |
6 __docformat__ = "restructuredtext en" |
22 # pylint: disable-msg=W0404,W0622,W0704,W0613,W0152 |
|
23 # Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE). |
|
24 # http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
25 # |
|
26 # This program is free software; you can redistribute it and/or modify it under |
|
27 # the terms of the GNU General Public License as published by the Free Software |
|
28 # Foundation; either version 2 of the License, or (at your option) any later |
|
29 # version. |
|
30 # |
|
31 # This program is distributed in the hope that it will be useful, but WITHOUT |
|
32 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
33 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|
34 # |
|
35 # You should have received a copy of the GNU General Public License along with |
|
36 # this program; if not, write to the Free Software Foundation, Inc., |
|
37 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
38 """ Generic Setup script, takes package info from __pkginfo__.py file """ |
|
39 |
7 |
40 from distutils.core import setup |
8 import os |
|
9 import sys |
|
10 import shutil |
|
11 from os.path import isdir, exists, join, walk |
41 |
12 |
|
13 try: |
|
14 if os.environ.get('NO_SETUPTOOLS'): |
|
15 raise ImportError() |
|
16 from setuptools import setup |
|
17 from setuptools.command import install_lib |
|
18 USE_SETUPTOOLS = 1 |
|
19 except ImportError: |
|
20 from distutils.core import setup |
|
21 from distutils.command import install_lib |
|
22 USE_SETUPTOOLS = 0 |
|
23 |
|
24 |
|
25 sys.modules.pop('__pkginfo__', None) |
42 # import required features |
26 # import required features |
43 from __pkginfo__ import distname, version, license, short_desc, long_desc, \ |
27 from __pkginfo__ import modname, version, license, description, \ |
44 web, author, author_email |
28 web, author, author_email |
45 # import optional features |
29 # import optional features |
46 try: |
30 import __pkginfo__ |
47 from __pkginfo__ import data_files |
31 distname = getattr(__pkginfo__, 'distname', modname) |
48 except ImportError: |
32 scripts = getattr(__pkginfo__, 'scripts', []) |
49 data_files = None |
33 data_files = getattr(__pkginfo__, 'data_files', None) |
50 try: |
34 include_dirs = getattr(__pkginfo__, 'include_dirs', []) |
51 from __pkginfo__ import include_dirs |
35 ext_modules = getattr(__pkginfo__, 'ext_modules', None) |
52 except ImportError: |
36 dependency_links = getattr(__pkginfo__, 'dependency_links', []) |
53 include_dirs = [] |
37 |
|
38 STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') |
|
39 |
|
40 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') |
|
41 |
|
42 if exists('README'): |
|
43 long_description = file('README').read() |
|
44 else: |
|
45 long_description = '' |
|
46 if USE_SETUPTOOLS: |
|
47 requires = {} |
|
48 for entry in ("__depends__", "__recommends__"): |
|
49 requires.update(getattr(__pkginfo__, entry, {})) |
|
50 install_requires = [("%s %s" % (d, v and v or "")).strip() |
|
51 for d, v in requires.iteritems()] |
|
52 else: |
|
53 install_requires = [] |
|
54 |
|
55 |
|
56 def ensure_scripts(linux_scripts): |
|
57 """Creates the proper script names required for each platform |
|
58 (taken from 4Suite) |
|
59 """ |
|
60 from distutils import util |
|
61 if util.get_platform()[:3] == 'win': |
|
62 scripts_ = [script + '.bat' for script in linux_scripts] |
|
63 else: |
|
64 scripts_ = linux_scripts |
|
65 return scripts_ |
|
66 |
|
67 def get_packages(directory, prefix): |
|
68 """return a list of subpackages for the given directory""" |
|
69 result = [] |
|
70 for package in os.listdir(directory): |
|
71 absfile = join(directory, package) |
|
72 if isdir(absfile): |
|
73 if exists(join(absfile, '__init__.py')) or \ |
|
74 package in ('test', 'tests'): |
|
75 if prefix: |
|
76 result.append('%s.%s' % (prefix, package)) |
|
77 else: |
|
78 result.append(package) |
|
79 result += get_packages(absfile, result[-1]) |
|
80 return result |
|
81 |
|
82 def export(from_dir, to_dir, |
|
83 blacklist=STD_BLACKLIST, |
|
84 ignore_ext=IGNORED_EXTENSIONS, |
|
85 verbose=True): |
|
86 """make a mirror of from_dir in to_dir, omitting directories and files |
|
87 listed in the black list |
|
88 """ |
|
89 def make_mirror(arg, directory, fnames): |
|
90 """walk handler""" |
|
91 for norecurs in blacklist: |
|
92 try: |
|
93 fnames.remove(norecurs) |
|
94 except ValueError: |
|
95 pass |
|
96 for filename in fnames: |
|
97 # don't include binary files |
|
98 if filename[-4:] in ignore_ext: |
|
99 continue |
|
100 if filename[-1] == '~': |
|
101 continue |
|
102 src = join(directory, filename) |
|
103 dest = to_dir + src[len(from_dir):] |
|
104 if verbose: |
|
105 print >> sys.stderr, src, '->', dest |
|
106 if os.path.isdir(src): |
|
107 if not exists(dest): |
|
108 os.mkdir(dest) |
|
109 else: |
|
110 if exists(dest): |
|
111 os.remove(dest) |
|
112 shutil.copy2(src, dest) |
|
113 try: |
|
114 os.mkdir(to_dir) |
|
115 except OSError, ex: |
|
116 # file exists ? |
|
117 import errno |
|
118 if ex.errno != errno.EEXIST: |
|
119 raise |
|
120 walk(from_dir, make_mirror, None) |
|
121 |
|
122 |
|
123 class MyInstallLib(install_lib.install_lib): |
|
124 """extend install_lib command to handle package __init__.py and |
|
125 include_dirs variable if necessary |
|
126 """ |
|
127 def run(self): |
|
128 """overridden from install_lib class""" |
|
129 install_lib.install_lib.run(self) |
|
130 # manually install included directories if any |
|
131 if include_dirs: |
|
132 base = modname |
|
133 for directory in include_dirs: |
|
134 dest = join(self.install_dir, base, directory) |
|
135 export(directory, dest, verbose=False) |
54 |
136 |
55 def install(**kwargs): |
137 def install(**kwargs): |
56 """setup entry point""" |
138 """setup entry point""" |
57 #kwargs['distname'] = modname |
139 if USE_SETUPTOOLS: |
58 return setup(name=distname, |
140 if '--force-manifest' in sys.argv: |
59 version=version, |
141 sys.argv.remove('--force-manifest') |
60 license=license, |
142 # install-layout option was introduced in 2.5.3-1~exp1 |
61 description=short_desc, |
143 elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: |
62 long_description=long_desc, |
144 sys.argv.remove('--install-layout=deb') |
63 author=author, |
145 if USE_SETUPTOOLS and install_requires: |
64 author_email=author_email, |
146 kwargs['install_requires'] = install_requires |
65 url=web, |
147 kwargs['dependency_links'] = dependency_links |
66 data_files=data_files, |
148 return setup(name = distname, |
67 **kwargs) |
149 version = version, |
|
150 license = license, |
|
151 description = description, |
|
152 long_description = long_description, |
|
153 author = author, |
|
154 author_email = author_email, |
|
155 url = web, |
|
156 scripts = ensure_scripts(scripts), |
|
157 data_files = data_files, |
|
158 ext_modules = ext_modules, |
|
159 cmdclass = {'install_lib': MyInstallLib}, |
|
160 **kwargs |
|
161 ) |
68 |
162 |
69 if __name__ == '__main__' : |
163 if __name__ == '__main__' : |
70 install() |
164 install() |