author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 28 Apr 2010 10:06:01 +0200 | |
branch | stable |
changeset 5421 | 8167de96c523 |
parent 4721 | 8f63691ccb7f |
child 5423 | e15abfdcce38 |
child 5424 | 8ecbcbff9777 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# pylint: disable-msg=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611 |
|
3 |
# |
|
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
4 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
5 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
7 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
8 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
9 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
10 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
11 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
12 |
# any later version. |
0 | 13 |
# |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
14 |
# logilab-common is distributed in the hope that it will be useful, but WITHOUT |
0 | 15 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
16 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
17 |
# details. |
0 | 18 |
# |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
19 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
20 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
21 |
"""Generic Setup script, takes package info from __pkginfo__.py file |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
22 |
""" |
0 | 23 |
|
24 |
import os |
|
25 |
import sys |
|
26 |
import shutil |
|
27 |
from distutils.core import setup |
|
28 |
from distutils.command import install_lib |
|
29 |
from os.path import isdir, exists, join, walk |
|
30 |
||
31 |
# import required features |
|
32 |
from __pkginfo__ import modname, version, license, short_desc, long_desc, \ |
|
33 |
web, author, author_email |
|
34 |
# import optional features |
|
35 |
try: |
|
36 |
from __pkginfo__ import distname |
|
37 |
except ImportError: |
|
38 |
distname = modname |
|
39 |
try: |
|
40 |
from __pkginfo__ import scripts |
|
41 |
except ImportError: |
|
42 |
scripts = [] |
|
43 |
try: |
|
44 |
from __pkginfo__ import data_files |
|
45 |
except ImportError: |
|
46 |
data_files = None |
|
47 |
try: |
|
48 |
from __pkginfo__ import subpackage_of |
|
49 |
except ImportError: |
|
50 |
subpackage_of = None |
|
51 |
try: |
|
52 |
from __pkginfo__ import include_dirs |
|
53 |
except ImportError: |
|
54 |
include_dirs = [] |
|
55 |
try: |
|
56 |
from __pkginfo__ import ext_modules |
|
57 |
except ImportError: |
|
58 |
ext_modules = None |
|
59 |
||
60 |
BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog') |
|
61 |
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
62 |
|
0 | 63 |
|
64 |
def ensure_scripts(linux_scripts): |
|
65 |
""" |
|
66 |
Creates the proper script names required for each platform |
|
67 |
(taken from 4Suite) |
|
68 |
""" |
|
69 |
from distutils import util |
|
70 |
if util.get_platform()[:3] == 'win': |
|
71 |
scripts_ = [script + '.bat' for script in linux_scripts] |
|
72 |
else: |
|
73 |
scripts_ = linux_scripts |
|
74 |
return scripts_ |
|
75 |
||
76 |
||
77 |
def get_packages(directory, prefix): |
|
78 |
"""return a list of subpackages for the given directory |
|
79 |
""" |
|
80 |
result = [] |
|
81 |
for package in os.listdir(directory): |
|
82 |
absfile = join(directory, package) |
|
83 |
if isdir(absfile): |
|
84 |
if exists(join(absfile, '__init__.py')) or \ |
|
85 |
package in ('test', 'tests'): |
|
86 |
if prefix: |
|
87 |
result.append('%s.%s' % (prefix, package)) |
|
88 |
else: |
|
89 |
result.append(package) |
|
90 |
result += get_packages(absfile, result[-1]) |
|
91 |
return result |
|
92 |
||
93 |
def export(from_dir, to_dir, |
|
94 |
blacklist=BASE_BLACKLIST, |
|
95 |
ignore_ext=IGNORED_EXTENSIONS): |
|
96 |
"""make a mirror of from_dir in to_dir, omitting directories and files |
|
97 |
listed in the black list |
|
98 |
""" |
|
99 |
def make_mirror(arg, directory, fnames): |
|
100 |
"""walk handler""" |
|
101 |
for norecurs in blacklist: |
|
102 |
try: |
|
103 |
fnames.remove(norecurs) |
|
104 |
except ValueError: |
|
105 |
pass |
|
106 |
for filename in fnames: |
|
107 |
# don't include binary files |
|
108 |
if filename[-4:] in ignore_ext: |
|
109 |
continue |
|
110 |
if filename[-1] == '~': |
|
111 |
continue |
|
112 |
src = '%s/%s' % (directory, filename) |
|
113 |
dest = to_dir + src[len(from_dir):] |
|
114 |
print >> sys.stderr, src, '->', dest |
|
115 |
if os.path.isdir(src): |
|
116 |
if not exists(dest): |
|
117 |
os.mkdir(dest) |
|
118 |
else: |
|
119 |
if exists(dest): |
|
120 |
os.remove(dest) |
|
121 |
shutil.copy2(src, dest) |
|
122 |
try: |
|
123 |
os.mkdir(to_dir) |
|
124 |
except OSError, ex: |
|
125 |
# file exists ? |
|
126 |
import errno |
|
127 |
if ex.errno != errno.EEXIST: |
|
128 |
raise |
|
129 |
walk(from_dir, make_mirror, None) |
|
130 |
||
131 |
||
132 |
EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n' |
|
133 |
||
134 |
class MyInstallLib(install_lib.install_lib): |
|
135 |
"""extend install_lib command to handle package __init__.py and |
|
136 |
include_dirs variable if necessary |
|
137 |
""" |
|
138 |
def run(self): |
|
139 |
"""overridden from install_lib class""" |
|
140 |
install_lib.install_lib.run(self) |
|
141 |
# create Products.__init__.py if needed |
|
142 |
if subpackage_of: |
|
143 |
product_init = join(self.install_dir, subpackage_of, '__init__.py') |
|
144 |
if not exists(product_init): |
|
145 |
self.announce('creating %s' % product_init) |
|
146 |
stream = open(product_init, 'w') |
|
147 |
stream.write(EMPTY_FILE) |
|
148 |
stream.close() |
|
149 |
# manually install included directories if any |
|
150 |
if include_dirs: |
|
151 |
if subpackage_of: |
|
152 |
base = join(subpackage_of, modname) |
|
153 |
else: |
|
154 |
base = modname |
|
155 |
for directory in include_dirs: |
|
156 |
dest = join(self.install_dir, base, directory) |
|
157 |
export(directory, dest) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
158 |
|
0 | 159 |
def install(**kwargs): |
160 |
"""setup entry point""" |
|
161 |
if subpackage_of: |
|
162 |
package = subpackage_of + '.' + modname |
|
163 |
kwargs['package_dir'] = {package : '.'} |
|
164 |
packages = [package] + get_packages(os.getcwd(), package) |
|
165 |
else: |
|
166 |
kwargs['package_dir'] = {modname : '.'} |
|
167 |
packages = [modname] + get_packages(os.getcwd(), modname) |
|
168 |
kwargs['packages'] = packages |
|
169 |
return setup(name = distname, |
|
170 |
version = version, |
|
171 |
license =license, |
|
172 |
description = short_desc, |
|
173 |
long_description = long_desc, |
|
174 |
author = author, |
|
175 |
author_email = author_email, |
|
176 |
url = web, |
|
177 |
scripts = ensure_scripts(scripts), |
|
178 |
data_files=data_files, |
|
179 |
ext_modules=ext_modules, |
|
180 |
cmdclass={'install_lib': MyInstallLib}, |
|
181 |
**kwargs |
|
182 |
) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
183 |
|
0 | 184 |
if __name__ == '__main__' : |
185 |
install() |