/
setup.py
231 lines (180 loc) · 7.5 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
from setuptools import find_packages
from distutils.core import setup
from distutils.command.build import build
from fabricate import run
import os
if os.name is 'nt':
try:
import py2exe
except ImportError:
print "Can't import py2exe. Do you have it installed."
import glob
import sys
import shutil
import sys
from sys import platform
curpath = os.path.dirname(os.path.realpath(__file__))
# You are not meant to do this but we don't install using
# setup.py so no big deal.
sys.path.append(os.path.join(curpath, 'src'))
import roam
try:
osgeopath = os.environ['OSGEO4W_ROOT']
except KeyError:
osgeopath = r'C:\OSGeo4W'
try:
qgisname = os.environ['QGISNAME']
except KeyError:
qgisname = 'qgis'
osgeobin = os.path.join(osgeopath, 'bin')
qtimageforms = os.path.join(osgeopath, r'apps\qt4\plugins\imageformats\*')
qtsqldrivers = os.path.join(osgeopath, r'apps\qt4\plugins\sqldrivers\*')
qgisresources = os.path.join(osgeopath, "apps", qgisname, "resources")
svgs = os.path.join(osgeopath, "apps", qgisname, "svg")
qgispluginpath = os.path.join(osgeopath, "apps", qgisname, "plugins", "*provider.dll")
gdalsharepath = os.path.join(osgeopath, 'share', 'gdal')
sdkpath = os.path.join(curpath, "sdk")
appsrcopyFilesath = os.path.join(curpath, "src", 'roam')
srceditorwidgets = os.path.join(curpath, "src", 'roam', 'editorwidgets')
projectinstallerpath = os.path.join(curpath, "src", 'project_installer')
configmangerpath = os.path.join(curpath, "src", 'configmanager')
def getfiles(folder, outpath, includebase=True):
"""
Walks a given folder and converts all paths to outpath root.
"""
def filecollection(files):
collection = []
for f in files:
filename = os.path.join(path, f)
collection.append(filename)
return newpath, collection
for path, dirs, files in os.walk(folder):
if not files: continue
if includebase:
newpath = r'{}\{}'.format(outpath, os.path.basename(path))
else:
newpath = r'{}'.format(outpath)
newpath, collection = filecollection(files)
yield newpath, collection
for dir in dirs:
for path1, collection1 in getfiles(os.path.join(path, dir), newpath):
yield (path1, collection1)
def get_data_files():
utils = ['ogr2ogr.exe', 'ogrinfo.exe', 'gdalinfo.exe', 'NCSEcw.dll',
os.path.join('gdalplugins', 'gdal_ECW_JP2ECW.dll')]
extrafiles = [os.path.join(osgeobin, path) for path in utils]
i18nfiles = os.path.join(appsrcopyFilesath, 'i18n\*.qm')
datafiles = [(".", [r'src\roam.config']),
# We have to copy the imageformat drivers to the root folder.
(r'imageformats', glob.glob(qtimageforms)),
(r'libs\qgis\plugins', glob.glob(qgispluginpath)),
(r'libs\qgis\resources', [os.path.join(qgisresources, 'qgis.db'),
os.path.join(qgisresources, 'srs.db')]),
(r'libs', extrafiles),
(r'libs', glob.glob(qtsqldrivers)),
(r'libs\roam\i18n', glob.glob(i18nfiles)),
(r'libs\roam\editorwidgets', glob.glob(os.path.join(srceditorwidgets, "*.pil"))),
(r'libs\roam\editorwidgets', glob.glob(os.path.join(srceditorwidgets, "*.pyd"))),
(r'libs\roam\editorwidgets', glob.glob(os.path.join(srceditorwidgets, "*.png")))]
for files in getfiles(r"src\roam\templates", r"libs\roam"):
datafiles.append(files)
for path, collection in getfiles(svgs, r'libs\qgis\svg'):
datafiles.append((path, collection))
for path, collection in getfiles(r'src\configmanager\templates', r'libs\configmanager\templates'):
datafiles.append((path, collection))
for files in getfiles(r'src\help', r'.'):
datafiles.append((files))
for path, collection in getfiles(r'src\plugins', r'plugins'):
print path, collection
datafiles.append((path, collection))
for path, collection in getfiles(gdalsharepath, r'libs'):
datafiles.append((path, collection))
# We copy the ogr2ogr10 and ogrinfo10 from the sdk folder because
# MS SQL support in GDAL 1.11 is busted. Do this until OSGeo4W gets a new
# GDAL build.
# GDAL ticket http://trac.osgeo.org/gdal/ticket/5474
# Fixed in 1.11.1
for path, collection in getfiles(sdkpath, r'libs', includebase=False):
datafiles.append((path, collection))
versiontext = os.path.join(appsrcopyFilesath, "version.txt")
with open(versiontext, 'w') as f:
f.write(roam.__version__)
datafiles.append((r'libs\roam', [versiontext]))
return datafiles
icon = r'src\roam\resources\branding\icon.ico'
configicon = r'src\roam\resources\branding\config.ico'
roam_target = dict(
script=r'src\roam\__main__.py',
dest_base='Roam',
icon_resources=[(1, icon)])
tests_target = dict(
script=r'tests\__main__.py',
dest_base='Roam_tests',
icon_resources=[(1, icon)])
projectupdater_target = dict(
script=r'src\project_installer\__main__.py',
dest_base='Roam Project Updater',
icon_resources=[(1, icon)])
configmanager_target = dict(
script=r'src\configmanager\__main__.py',
dest_base='Roam Config Manager',
icon_resources=[(1, configicon)])
def buildqtfiles():
pyuic4 = 'pyuic4'
if platform == 'win32':
pyuic4 += '.bat'
for folder in [appsrcopyFilesath, projectinstallerpath, configmangerpath]:
for root, dirs, files in os.walk(folder):
for file in files:
filepath = os.path.join(root, file)
file, ext = os.path.splitext(filepath)
if ext == '.ui':
newfile = file + ".py"
run(pyuic4, '-o', newfile, filepath, shell=True)
elif ext == '.qrc':
newfile = file + "_rc.py"
run('pyrcc4', '-o', newfile, filepath)
elif ext == '.ts':
newfile = file + '.qm'
if os.name is 'nt':
run('lrelease', filepath, '-qm', newfile)
else:
run('lrelease-qt4', filepath, '-qm', newfile)
class qtbuild(build):
def run(self):
buildqtfiles()
build.run(self)
package_details = dict(
name='roam',
version=roam.__version__,
packages=find_packages('./src'),
package_dir={'': 'src', 'tests': 'tests'},
url='',
license='GPL',
author='Digital Mapping Solutions',
author_email='nathan.woodrow@mapsolutions.com.au',
description='',
data_files=get_data_files(),
cmdclass={'build': qtbuild},
)
if os.name is 'nt':
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if os.path.basename(pathname).lower() in ("msvcp100.dll", "msvcr100.dll"):
return 0
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
package_details.update(
options={'py2exe': {
'dll_excludes': ['msvcr80.dll', 'msvcp80.dll',
'msvcr80d.dll', 'msvcp80d.dll',
'powrprof.dll', 'mswsock.dll',
'w9xpopen.exe', 'MSVCP90.dll'],
'excludes': ['PyQt4.uic.port_v3'],
'includes': ['PyQt4.QtNetwork', 'sip', 'PyQt4.QtSql', 'sqlite3', "Queue", 'PyQt4.Qsci'],
'skip_archive': True,
}},
windows=[roam_target, configmanager_target],
zipfile="libs\\"
)
setup(**package_details)