-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
112 lines (96 loc) · 3.79 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
# constants declaration
NAME = 'cards-against-humanity'
VERSION = '0.1'
DESCRIPTION = 'Cards Against Humanity Online Game'
from shared.path import getScriptDirectory
import shutil
import sys
import os
import os.path
import platform
from cx_Freeze import setup,Executable
from distutils.sysconfig import get_python_lib
def list_all_files(path):
entrylist = os.listdir(path)
flist = []
for entry in entrylist:
fentry = os.path.join(path, entry)
if os.path.isdir(fentry):
nflist = list_all_files(fentry)
flist = flist + nflist
else:
flist.append(fentry)
return flist
# required to initialize zope packages
# that means that the zope package (if installed)
# needs to contain an __init__.py, which it doesn't from the start
def initialize_zope_package():
lib_dir = get_python_lib()
if not os.path.exists(os.path.join(lib_dir, 'zope')):
print "Zope package not found. This setup file won't work without at least zope.interface installed"
sys.exit()
if not os.path.exists(os.path.join(lib_dir, 'zope', '__init__.py')):
print "No __init__.py file found for zope package, creating it manually"
open(os.path.join(lib_dir, 'zope', '__init__.py'), 'w').write('')
include_files = [(os.path.join(getScriptDirectory(), 'assets', x), os.path.relpath(x, getScriptDirectory())) for x in list_all_files(os.path.join(getScriptDirectory(), 'assets'))]
include_files += [(os.path.join(getScriptDirectory(), "accessible_output", "lib", x), os.path.join("lib", x)) for x in os.listdir(os.path.join(getScriptDirectory(), "accessible_output", "lib"))]
include_files += [(os.path.join(getScriptDirectory(), "languages", x), os.path.join("languages", x)) for x in os.listdir(os.path.join(getScriptDirectory(), "languages"))]
include_files += [(os.path.join(getScriptDirectory(), "sample-databases", x), os.path.join("sample-databases", x)) for x in os.listdir(os.path.join(getScriptDirectory(), "sample-databases"))]
build_exe_options = {
"includes": [
"lxml.etree",
"lxml._elementpath",
"zope.interface"
],
"excludes": [
"bz2",
"email",
"numpy",
"tar",
"Tkinter",
"unittest",
"xml"
],
"include_files": include_files
}
# preparing setup package environment
initialize_zope_package()
setup(
name = NAME,
version = VERSION,
description = DESCRIPTION,
options = {
'build_exe' : build_exe_options
},
executables = [
Executable(
'client.py',
base=(None if platform.system() != 'Windows' else 'Win32GUI')
),
Executable(
'client-accessible.py',
base=(None if platform.system() != 'Windows' else 'Win32GUI')
),
Executable(
'editor.py',
base=(None if platform.system() != 'Windows' else 'Win32GUI')
),
Executable(
'server.py',
base=None
)
]
)
build_dir = os.path.join(getScriptDirectory(), 'build', os.listdir(os.path.join(getScriptDirectory(), 'build'))[0])
if platform.system()=='Windows':
import zipfile
zip=zipfile.ZipFile(os.path.join(getScriptDirectory(), '%s-%s.zip'%(NAME, VERSION)), "w")
for file in list_all_files(build_dir):
zip.write(file,'%s-%s\\%s'%(NAME, VERSION, os.path.relpath(file,build_dir)), zipfile.ZIP_DEFLATED)
zip.close()
else:
import tarfile
tar=tarfile.open('%s-%s.tar.gz'%(NAME, VERSION),'w:gz')
tar.add(build_dir, '%s-%s'%(NAME, VERSION))
tar.close()
shutil.rmtree(os.path.join(getScriptDirectory(), "build"))