forked from roam-qgis/Roam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
180 lines (145 loc) · 6.32 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
from setuptools import find_packages
from distutils.core import setup
from distutils.command.build import build
from fabricate import run
try:
import py2exe
except ImportError:
print "Can't import py2exe. Do you have it installed."
import glob
import os
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\*')
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')
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):
"""
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
newpath = r'{}\{}'.format(outpath, os.path.basename(path))
newpath, collection = filecollection(files)
yield newpath, collection
for dir in dirs:
for path, collection in getfiles(os.path.join(path, dir), newpath):
yield (path, collection)
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']),
(r'libs\roam\templates', [r'src\roam\templates\info.html',
r'src\roam\templates\error.html']),
(r'libs\roam\templates\bootstrap', glob.glob(r'src\roam\templates\bootstrap\*')),
(r'projects', [r'src\projects\__init__.py']),
# 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\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 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 path, collection in getfiles(gdalsharepath, r'libs'):
datafiles.append((path, collection))
return datafiles
icon = r'src\roam\resources\branding\icon.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, icon)])
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'
run('lrelease', filepath, '-qm', newfile)
class qtbuild(build):
def run(self):
buildqtfiles()
build.run(self)
setup(
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='',
windows=[roam_target, projectupdater_target, configmanager_target],
data_files=get_data_files(),
zipfile='libs\\',
cmdclass= {'build': qtbuild},
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'],
'skip_archive': True,
}},
)