-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
195 lines (161 loc) · 6.28 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
# __BEGIN_LICENSE__
# Copyright (C) 2008-2010 United States Government as represented by
# the Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
# __END_LICENSE__
import os
from setuptools import setup, find_packages, Command
import os.path as op
import subprocess
def read_file(filename):
"""Read a file into a string"""
path = os.path.abspath(os.path.dirname(__file__))
filepath = os.path.join(path, filename)
try:
return open(filepath).read()
except IOError:
return ''
# Use the docstring of the __init__ file to be the description
#DESC = " ".join(__import__('geocamMapMixer').__doc__.splitlines()).strip()
DESC = ""
PROJ_ROOT = op.abspath(op.dirname(__file__))
def find_sub_apps(directory=PROJ_ROOT):
"""We define a sub-application to be any top-level subdirectory that
contains a urls.py and a models.py. Note that we do not look solely
for submodule based apps, since there could be an odd app or two that
aren't based on a git submodule, or it could be the main 'glue'
application."""
requiredFiles = ['models.py', 'urls.py']
subApps = []
for entry in os.listdir(directory):
fullEntry = op.join(directory, entry)
if not op.isdir(fullEntry):
continue
if all([op.exists(op.join(fullEntry, f)) for f in requiredFiles]):
subApps.append((entry, fullEntry))
return subApps
def find_submodules(directory=op.join(PROJ_ROOT, 'apps')):
"""We define a submodule as a subdirectory in submodules which contains a
subdirectory under that of the same name. We do not do git magic as there
could be times where it is a sub-app that isn't a git subrepo."""
subModules = []
for entry in os.listdir(directory):
fullEntry = op.join(directory, entry)
if not op.isdir(fullEntry):
continue
fullSubDir = op.join(fullEntry, entry)
if op.exists(fullSubDir) and op.isdir(fullSubDir):
subModules.append((entry, fullSubDir))
return subModules
class RunSubCommand(Command):
"""Run a sub-command on the sub-apps. This class is meant to be subclassed.
Override 'self.subcommand' in initialize_options to specify what command
to run. If you override run, be sure to call this class' run to
run the subcommand."""
user_options = []
# Option defaults
def initialize_options(self):
self.subcommand = None # pylint: disable=W0201
# Validate options
def finalize_options(self):
pass
# Where the action happens
def run(self):
if getattr(self, 'subcommand', None) is None:
raise Exception("must override self.subcommand")
projDir = op.abspath(op.dirname(__file__))
subApps = find_sub_apps(projDir)
for app, _directory in subApps:
appDir = op.join(projDir, 'submodules', app)
if not op.exists(appDir):
self.announce("skipping %s" % app)
continue
setupPath = op.join(appDir, 'setup.py')
if not op.exists(setupPath):
self.announce("skipping %s" % app)
continue
subprocess.call(["python", setupPath, self.subcommand])
class TestCommand(RunSubCommand):
description = 'test geocam command'
user_options = []
# Option defaults
def initialize_options(self):
self.subcommand = 'geocam'
# Validate options
def finalize_options(self):
pass
class SymlinkCommand(Command):
"""This command makes the submodule app directories symlinked to the
site-level. Will not work on windows."""
description = 'symlink submodules to the main site level'
user_options = [('force', 'f', 'overwrite existing symlinks')]
boolean_options = ['force']
# Option defaults
def initialize_options(self):
self.force = False
# Validate options
def finalize_options(self):
pass
def run(self):
subModules = find_submodules()
for name, directory in subModules:
destination = op.join(PROJ_ROOT, name)
if op.exists(destination):
if not op.islink(destination):
self.announce("skipping " + name + ": not a symlink")
continue
if not self.force:
self.announce("skipping " + name + ": file exists (use -f to override)")
continue
os.remove(destination)
os.symlink(directory, destination)
class MediaCommand(Command):
description = 'collect together the site-level static media'
user_options = [('force', 'f', 'overwrite existing symlinks')]
boolean_options = ['force']
# Option defaults
def initialize_options(self):
self.force = False
# Validate options
def finalize_options(self):
pass
def run(self):
siteMediaDir = op.join(PROJ_ROOT, 'media')
if not op.exists(siteMediaDir):
os.mkdir(siteMediaDir)
subApps = find_sub_apps()
for name, directory in subApps:
mediaDirectory = op.join(directory, 'media', name)
if not op.exists(mediaDirectory):
self.announce("skipping " + name + ": media directory does not exist")
continue
destination = op.join(siteMediaDir, name)
if op.exists(destination):
if not op.islink(destination):
self.announce("skipping " + name + ": not a symlink")
continue
if not self.force:
self.announce("skipping " + name + ": file exists (use -f to override)")
continue
os.remove(destination)
os.symlink(directory, destination)
setup(
name="geocamMapMixer",
version='1.0', # __import__('geocamMapMixer').get_version().replace(' ', '-'),
url='',
author='Trey Smith',
author_email='',
description=DESC,
long_description=read_file('README'),
packages=find_packages(),
include_package_data=True,
install_requires=read_file('requirements.txt'),
classifiers=[
'License :: OSI Approved :: NASA Open Source Agreement',
'Framework :: Django',
],
cmdclass={
'link_submodules': SymlinkCommand,
'link_media': MediaCommand
},
)