-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
318 lines (267 loc) · 11.4 KB
/
setup.py
File metadata and controls
318 lines (267 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env python
#
#This file is part of FredClient.
#
# FredClient is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# FredClient is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FredClient; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import sys, os, shutil
from distutils import log
from freddist.core import setup
from freddist.command.sdist import sdist
from freddist.command.install import install
from freddist.command.install_scripts import install_scripts
from freddist.command.install_lib import install_lib
from freddist.command.install_data import install_data
from freddist import file_util
from freddist.file_util import *
from fred.internal_variables import fred_version, config_name
from fred.session_config import get_etc_config_name
PROJECT_NAME = 'fred-client'
PACKAGE_NAME = 'fred-client'
SCRIPT_FILENAME = "%s.py" % PROJECT_NAME # fred-client.py
QT4SCRIPT_FILENAME = "%s-qt4.pyw" % PROJECT_NAME # fred-client-qt4.pyw
g_directory = ''
# datarootdir/prog_name/ssl => /usr/local/share/fred-client/ssl (default)
DEFAULT_SSL_PATH = 'ssl'
# datarootdir/prog_name/schemas/all.xsd =>
# /usr/local/share/fred-client/schemas/all.xsd
DEFAULT_SCHEMAS_FILEMANE = 'schemas/all.xsd'
# enum/mod-eppd/trunk/schemas/
EPP_SCHEMAS_PATH = os.environ.get('EPP_SCHEMAS_PATH', 'fred/schemas')
APP_SCRIPTS = [PROJECT_NAME, QT4SCRIPT_FILENAME]
#if 'bdist_wininst' in sys.argv and '--install-script=setup_postinstall.py'
#in sys.argv:
if 'bdist_wininst' in sys.argv:
# join postinstall only for WIN distribution
APP_SCRIPTS.append('setup_postinstall.py')
def get_epp_schema_path(directory):
"Return schemas path"
global EPP_SCHEMAS_PATH
if 'EPP_SCHEMAS_PATH' in os.environ:
return os.environ['EPP_SCHEMAS_PATH']
for path in ('fred/schemas', '../../mod-eppd/trunk/schemas/', '../mod-eppd/schemas/'):
fullpath = os.path.normpath(os.path.join(directory, path))
if os.path.exists(fullpath):
EPP_SCHEMAS_PATH = fullpath
return fullpath
raise IOError("Path to schemas missing.")
class EPPClientSDist(sdist):
"sdist check required"
def run(self):
"run main process"
# create temporary symlink
created = False
link_name = os.path.join(self.srcdir, 'fred', 'schemas')
if not os.path.exists(link_name):
os.symlink(EPP_SCHEMAS_PATH, link_name)
created = True
sdist.run(self)
if created:
# remove temporary symlink
os.unlink(link_name)
class EPPClientInstall(install):
user_options = install.user_options
user_options.append(('keeppatt', None,
'not change patterns in config file.'))
user_options.append(('host=', None,
'fred server host [localhost]'))
user_options.append(('port=', None,
'fred server port [700]'))
boolean_options = install.boolean_options
def __init__(self, *attrs):
install.__init__(self, *attrs)
# keep valid paths during package creation
self.is_bdist_mode = None
self.keeppatt = None
# check if object runs in bdist mode
for dist in attrs:
for name in dist.commands:
if name == 'bdist':
# it is bdist mode - we are on creating the package
self.is_bdist_mode = 1
elif name == 'bdist_wininst':
# if we create package for windows, we change patterns
# as late in postinstall process
self.keeppatt = 1
def initialize_options(self):
install.initialize_options(self)
self.host = None
self.port = None
self.include_scripts = True
def finalize_options(self):
install.finalize_options(self)
if not self.host:
self.host = 'localhost'
if not self.port:
self.port = '700'
def update_fred_config(self):
'''Update fred config'''
if not self.keeppatt:
root = self.get_actual_root()
if not os.path.exists('build'):
os.makedirs('build')
values = []
values.append(('FRED_CLIENT_SSL_PATH',
os.path.join(
self.getDir_std('appdir'),
DEFAULT_SSL_PATH))
)
values.append(('FRED_CLIENT_SCHEMAS_FILEMANE',
os.path.join(
self.getDir_std('appdir'),
DEFAULT_SCHEMAS_FILEMANE))
)
values.append(('FRED_CLIENT_HOST', self.host))
values.append(('FRED_CLIENT_PORT', self.port))
self.replace_pattern(
os.path.join(self.srcdir, 'conf', config_name+'.install'),
os.path.join('build', config_name),
values)
else:
shutil.copyfile(
os.path.join(self.srcdir, 'conf', config_name + '.install'),
os.path.join('build', config_name))
print 'File %s was created.' % config_name
def run(self):
self.update_fred_config()
install.run(self)
class EPPClientInstall_scripts(install_scripts):
def update_fred_client(self):
values = [((r"(sys\.path\.insert\(0, )\'[\w/_ \-\.]*\'\)",
r"\1'%s')" % self.getDir_std('purelibdir')))]
self.replace_pattern(os.path.join(self.build_dir, PACKAGE_NAME),
None, values)
if os.environ.has_key('BDIST_SIMPLE'):
self.replace_pattern(os.path.join(self.build_dir, SCRIPT_FILENAME),
None, values)
print "%s file has been updated" % SCRIPT_FILENAME
def update_fred_client_qt4(self):
values = [((r"(sys\.path\.insert\(0, )\'[\w/_ \-\.]*\'\)",
r"\1'%s')" % self.getDir_std('purelibdir')))]
self.replace_pattern(os.path.join(self.build_dir, QT4SCRIPT_FILENAME),
None, values)
print "%s file has been updated" % QT4SCRIPT_FILENAME
def run(self):
self.update_fred_client()
self.update_fred_client_qt4()
install_scripts.run(self)
class Install_lib(install_lib):
def update_session_config(self):
filename = os.path.join(self.build_dir, 'fred', 'session_config.py')
# when simple package creation is in progress this enviroment variable is set to 'True'
if os.environ.has_key('BDIST_SIMPLE'):
# simple package must use as a first configuration file its own
# file from ``data_files'' directory, not file from user home directory
# nor file from /etc or any other directory.
values = [((
r"os\.path\.join\(os\.path.expanduser\(\'\~\'\),config_name\)",
r"'%s'" % os.path.join(
self.getDir_std('sysconfdir'), 'fred', config_name)))]
else:
values = [((
r"(glob_conf = )\'[\w/_ \-\.]*\'",
r"\1'%s'" % os.path.join(
self.getDir_std('sysconfdir'), 'fred', config_name)))]
self.replace_pattern(filename, None, values)
print "session_config.py file has been updated"
def update_version(self):
"Update version number for client"
filename = os.path.join(self.build_dir, 'fred', 'internal_variables.py')
self.replace_pattern(filename, None, ((("PACKAGE_VERSION", self.distribution.metadata.version),)))
def run(self):
self.update_session_config()
self.update_version()
install_lib.run(self)
class Install_data(install_data):
def run(self):
install_data.run(self)
def main(directory):
if os.environ.has_key('BDIST_SIMPLE'):
APP_SCRIPTS.append(SCRIPT_FILENAME)
try:
setup(name = PROJECT_NAME,
description = 'Client FRED (Free Registry for enum and domain)',
author = 'Zdenek Bohm, CZ.NIC',
author_email = 'zdenek.bohm@nic.cz',
url = 'http://www.nic.cz',
license = 'GNU GPL',
packages = ['fred','guiqt4'],
package_data={
'fred': ['INSTALL','LICENSE','CREDITS','*.txt',
'lang/fred_client_cs.po',
'lang/cs/LC_MESSAGES/fred_client.mo'],
'guiqt4': ['*.py','*.png','*.qm'],
},
scripts = APP_SCRIPTS,
data_files=[
('DATAROOTDIR/%s' % PACKAGE_NAME, [
'doc/fred_howto_cs.html',
'doc/niccz_console.ico',
'doc/niccz_gui.ico',
'doc/configure.ico',
'doc/help.ico',
'doc/README_EN.txt',
'doc/README_CS.txt',
'doc/README_CS.html',
'doc/README_QT4_CS.pdf']),
('DATAROOTDIR/%s/ssl' % PACKAGE_NAME, [
'fred/certificates/test-cert.pem',
'fred/certificates/test-key.pem']),
# ('DATADIR/fred-client/schemas', file_util.all_files_in_2('fred/schemas')),
# on posix: '/etc/fred/'
# on windows: ALLUSERSPROFILE = C:\Documents and Settings\All Users
# on windows if ALL... missing: C:\Python25\
#get_etc_config_name()
('SYSCONFDIR/fred', [os.path.join('build', config_name)])
]
+ all_files_in_4(os.path.join('DATADIR', PACKAGE_NAME, 'schemas'),
get_epp_schema_path(directory)),
cmdclass = {
'sdist': EPPClientSDist,
'install': EPPClientInstall,
'install_scripts': EPPClientInstall_scripts,
'install_lib':Install_lib,
'install_data':Install_data,
},
)
return True
except OSError, msg:
message = "%s" % msg
log.error("OSError: %s.", message)
if 'schemas' in message:
log.error("Schemas missing. Use them from the project mod-eppd and "
"copy or make symlink fred/schemas.")
return False
except Exception, msg:
log.error("Error: %s", msg)
return False
if __name__ == '__main__':
g_directory = os.path.dirname(sys.argv[0])
filename = SCRIPT_FILENAME
if 'bdist_simple' in sys.argv:
# when creating bdist_simple package, enviroment variable
# ``BDIST_SIMPLE'' must be set
os.environ['BDIST_SIMPLE'] = 'True'
# copy fred-client to fred-client.py (windows do not recognize file
# without .py extension as a python script)
shutil.copy(os.path.join(g_directory, PACKAGE_NAME),
os.path.join(g_directory, filename))
if main(g_directory):
print "All done!"
if os.environ.has_key('BDIST_SIMPLE'):
# remove now useless fred-client.py file
try:
os.remove(os.path.join(g_directory, filename))
except OSError:
pass