-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsetup.py
356 lines (308 loc) · 11.7 KB
/
setup.py
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
import sys, glob, os
import shutil
import libreosteoweb
version = libreosteoweb.__version__
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def remove_useless_files(directory, keepfiles_list, keepdir_list):
keep_path_list = []
for root, directories, files in os.walk(directory):
for d in directories:
if d in keepdir_list or root in keep_path_list:
keep_path_list.append(os.path.join(root, d))
for f in files:
if root not in keep_path_list and f not in keepfiles_list:
os.remove(os.path.join(root, f))
for d in directories:
if os.path.join(root, d) not in keep_path_list:
shutil.rmtree(os.path.join(root, d))
def execute_cmd_context(cmd):
from subprocess import run
run("activate;" + cmd, shell=True, env=os.environ.copy())
def collectstatic():
print("Collect static")
cmd = "python manage.py collectstatic --no-input"
execute_cmd_context(cmd)
def compress():
print("Compress css/js")
cmd = "python manage.py compress --force"
execute_cmd_context(cmd)
def compilejsi18n():
print("Compile JsI18n")
cmd = "python manage.py compilejsi18n"
execute_cmd_context(cmd)
def get_zipcodes():
print("Retrieve ZipCode dataset")
execute_cmd_context("python manage.py import_zipcodes --download-only")
def purge_static():
purge_dir = ['components']
keep_path = ['components/webshim']
to_remove_list = []
# For each dir in purge dir from static :
# delete each files
for root, directories, files in os.walk('static'):
for p in purge_dir:
for d in directories:
if root == os.path.join('static', p):
for a in keep_path:
if d not in os.path.split(a):
shutil.rmtree(os.path.join(root, d))
# Build on Windows.
#
# usage :
# python setup.py build_exe
#
if sys.platform in ['win32']:
# before all of things : collectstatic
collectstatic()
compilejsi18n()
compress()
get_zipcodes()
from cx_Freeze import setup, Executable
import zipfile
# GUI applications require a different base on Windows (the default is for a
# console application).
base = 'Console'
import os.path
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl',
'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
import compressor
def get_djangolocale():
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"Libreosteo.settings.standalone")
import django
directory = os.path.join(django.__path__[0], 'conf', 'locale')
return [(directory, 'django/conf/locale')]
def add_jaraco_files():
import jaraco
directory = os.path.join(jaraco.__path__[0], 'text')
zipf = zipfile.ZipFile(
'build/exe.%s-%s/lib/library.zip' %
(get_platform_identifier(), sys.winver[0:3]), "a")
zipf.write(os.path.join(directory, 'Lorem ipsum.txt'),
os.path.join('jaraco', 'text', 'Lorem ipsum.txt'))
zipf.close()
def get_platform_identifier():
platform_identifier = sys.platform
if os.environ['PROCESSOR_ARCHITECTURE'].lower() == 'amd64':
platform_identifier = 'win-%s' % os.environ[
'PROCESSOR_ARCHITECTURE'].lower()
return platform_identifier
def compressor_path(t):
(c, c1) = t
return (c, c1.replace(compressor.__path__[0] + os.sep, ''))
def get_compressor_templates():
directory = os.path.join(compressor.__path__[0], 'templates')
list_files = get_filepaths(directory)
return list(map(compressor_path, list_files))
def get_filepaths(directory, pyc_only=False):
"""
This function will generate the file names in a directory
tree by walking the tree either top-down or bottom-up. For each
directory in the tree rooted at directory top (including top itself),
it yields a 3-tuple (dirpath, dirnames, filenames).
"""
file_paths = [] # List which will store all of the full filepaths.
# Walk the tree.
for root, directories, files in os.walk(directory):
for filename in files:
if pyc_only and not filename.endswith('.pyc'):
continue
# Join the two strings in order to form the full filepath.
filepath = os.path.join(root, filename)
file_paths.append((filepath, filepath)) # Add it to the list.
for d in directories:
rec_d = os.path.join(root, d)
file_paths + get_filepaths(rec_d)
return file_paths # Self-explanatory.
def include_migration_files(directory):
"""
This function will generate the include from the list of python
migration files in the directory
"""
migration_files = []
for root, directories, files in os.walk(directory):
for filename in files:
if (filename.endswith('.py')
) and not (filename.startswith('__')):
migration_files.append(
directory.replace('/', '.') + '.' +
filename[0:len(filename) - 3])
return migration_files
from cx_Freeze import setup, Executable
copyDependentFiles = True
includes = [
'cherrypy', 'win32serviceutil', 'win32service', 'win32event',
'servicemanager', 'win32timezone', 'django.template.loader_tags',
'django.core.management', 'Libreosteo', 'Libreosteo.urls',
'Libreosteo.settings', 'Libreosteo.wsgi', 'Libreosteo.zip_loader',
'libreosteoweb.admin', 'libreosteoweb.middleware',
'libreosteoweb.management', 'libreosteoweb.models',
'libreosteoweb.search_indexes', 'libreosteoweb.api',
'libreosteoweb.apps', 'libreosteoweb.templatetags.invoice_extras',
'email.mime.image', "rcssmin", "rjsmin", "jaraco.text"
]
migrations = [
'libreosteoweb.migrations', "django.contrib.admin.migrations",
"django.contrib.auth.migrations",
"django.contrib.contenttypes.migrations",
"django.contrib.sessions.migrations"
]
include_files = get_filepaths('media') + get_filepaths('locale') + [
('zipcode_dataset.json', 'zipcode_dataset')
]
extra_includes = get_filepaths(
'templates') + get_compressor_templates() + get_filepaths('static')
packages = [
"os",
"django",
#"htmlentitydefs",
#"HTMLParser",
#"Cookie",
'http',
"gettext",
'html',
"rest_framework",
"haystack",
"sqlite3",
"statici18n",
"email",
"Libreosteo",
"compressor",
"libreosteoweb",
"pkg_resources._vendor",
"django_filters",
"jaraco",
"zipcode_lookup",
"django.core.management.commands",
"zipcode_lookup.management.commands",
"libreosteoweb.management.commands",
"protected_media"
]
in_zip_packages = includes + [
'_markerlib', 'appconf', 'backports', 'cheroot', 'compiler',
'compressor', 'ctypes', 'distutils', 'django_filters', 'email',
'encodings', 'haystack', 'importlib', 'json', 'logging',
'more_itertools', 'multiprocessing', 'pkg_resources', 'pydoc_data',
'rest_framework', 'rest_framework_csv', 'sqlite3', 'sqlparse',
'statici18n', 'tempora', 'test', 'unittest', 'whoosh', 'wsgiref'
'xml'
]
build_exe_options = {
"packages": packages,
"includes": includes + migrations,
"include_files": include_files + extra_includes,
"zip_includes": extra_includes,
"excludes": ['cStringIO', 'tcl', 'Tkinter'],
"no_compress": False,
"optimize": 2,
"zip_include_packages": in_zip_packages,
"zip_exclude_packages": ['libreosteoweb'],
"include_msvcr": True
}
setup(name="LibreOsteo",
version=version,
description="LibreOsteo, suite for osteopaths",
options={"build_exe": build_exe_options},
executables=[
Executable("winserver.py",
base=base,
targetName="LibreOsteo.exe"),
Executable("manage.py", base=base, targetName="manager.exe"),
Executable("application.py",
base=base,
targetName="launcher.exe")
])
# Create a web shorcut link
build_dir = glob.glob('build/exe.%s-%s' %
(get_platform_identifier(), sys.winver[:3]))
for b in build_dir:
shortlink = open(b + "/LibreOsteo.url", "w")
shortlink.write("[InternetShortcut]\n")
shortlink.write("URL=http://localhost:8085/\n")
shortlink.write("\n")
shortlink.write("\n")
##Remove useless locales
remove_useless_files(b + "/django/conf/locale", [], ["fr", "en"])
remove_useless_files(b + "lib/django/conf/locale", [], ['fr', 'en'])
remove_useless_files(b + "/static/components/angular-i18n", [
"angular-locale_en.js", "angular-locale_en-us.js",
"angular-locale_fr.js", "angular-locale_fr-fr.js"
], [])
## Patch django migration loader
from patch import patch_django_loader_pyc
print("Platform identifier : %s" % get_platform_identifier())
patch_django_loader_pyc('build/exe.%s-%s/' %
(get_platform_identifier(), sys.winver[:3]))
# Restore file for jaraco
add_jaraco_files()
#### MACOS X build
#
# Usage:
# python setup.py py2app
if sys.platform in ['darwin']:
from setuptools import setup
# before all of things : collectstatic
collectstatic()
compilejsi18n()
compress()
APP = ['server.py']
DATA_FILES = [
'static',
'locale',
]
OPTIONS = {
'argv_emulation':
True,
'includes': [
# 'HTMLParser',
],
'packages': [
"django",
"Libreosteo",
"libreosteoweb",
"zipcode_lookup",
"rest_framework",
"haystack",
"sqlite3",
"statici18n",
"email",
"compressor",
"django_filters",
"protected_media",
],
'plist': {
'LSBackgroundOnly': True,
'LSUIElement': False,
'CFBundleIdentifier': 'org.libreosteo.macos.libreosteo.service',
'CFBundleGetInfoString': 'LibreOsteoService',
'CFBundleDisplayName': 'LibreOsteoService',
'CFBundleName': 'LibreOsteoService',
'CFBundleShortVersionString': version,
'CFBundleVersion': version,
},
'extra_scripts': ['application.py', 'manage.py'],
'optimize':
True,
'iconfile':
'libreosteoweb/static/images/favicon.icns',
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
remove_useless_files(
"build/exe.win32-2.7/static/bower_components/angular-i18n", [
"angular-locale_en.js", "angular-locale_en-us.js",
"angular-locale_fr.js", "angular-locale_fr-fr.js"
], [])
elif sys.platform not in ['win32']:
print("Nothing to do")