Skip to content
Newer
Older
100644 196 lines (161 sloc) 6.28 KB
d446c20 @trey0 initial commit
trey0 authored
1 # __BEGIN_LICENSE__
2 # Copyright (C) 2008-2010 United States Government as represented by
3 # the Administrator of the National Aeronautics and Space Administration.
4 # All Rights Reserved.
5 # __END_LICENSE__
6
7 import os
8 from setuptools import setup, find_packages, Command
9
10 import os.path as op
11 import subprocess
12
13
14 def read_file(filename):
15 """Read a file into a string"""
16 path = os.path.abspath(os.path.dirname(__file__))
17 filepath = os.path.join(path, filename)
18 try:
19 return open(filepath).read()
20 except IOError:
21 return ''
22
23 # Use the docstring of the __init__ file to be the description
24 #DESC = " ".join(__import__('geocamMapFasten').__doc__.splitlines()).strip()
25 DESC = ""
26
27 PROJ_ROOT = op.abspath(op.dirname(__file__))
28
29
30 def find_sub_apps(directory=PROJ_ROOT):
31 """We define a sub-application to be any top-level subdirectory that
32 contains a urls.py and a models.py. Note that we do not look solely
33 for submodule based apps, since there could be an odd app or two that
34 aren't based on a git submodule, or it could be the main 'glue'
35 application."""
36 requiredFiles = ['models.py', 'urls.py']
37 subApps = []
38 for entry in os.listdir(directory):
39 fullEntry = op.join(directory, entry)
40 if not op.isdir(fullEntry):
41 continue
42 if all([op.exists(op.join(fullEntry, f)) for f in requiredFiles]):
43 subApps.append((entry, fullEntry))
44 return subApps
45
46
47 def find_submodules(directory=op.join(PROJ_ROOT, 'apps')):
48 """We define a submodule as a subdirectory in submodules which contains a
49 subdirectory under that of the same name. We do not do git magic as there
50 could be times where it is a sub-app that isn't a git subrepo."""
51 subModules = []
52 for entry in os.listdir(directory):
53 fullEntry = op.join(directory, entry)
54 if not op.isdir(fullEntry):
55 continue
56 fullSubDir = op.join(fullEntry, entry)
57 if op.exists(fullSubDir) and op.isdir(fullSubDir):
58 subModules.append((entry, fullSubDir))
59 return subModules
60
61
62 class RunSubCommand(Command):
63 """Run a sub-command on the sub-apps. This class is meant to be subclassed.
64 Override 'self.subcommand' in initialize_options to specify what command
65 to run. If you override run, be sure to call this class' run to
66 run the subcommand."""
67 user_options = []
68
69 # Option defaults
70 def initialize_options(self):
71 self.subcommand = None # pylint: disable=W0201
72
73 # Validate options
74 def finalize_options(self):
75 pass
76
77 # Where the action happens
78 def run(self):
79 if getattr(self, 'subcommand', None) is None:
80 raise Exception("must override self.subcommand")
81 projDir = op.abspath(op.dirname(__file__))
82 subApps = find_sub_apps(projDir)
83 for app, _directory in subApps:
84 appDir = op.join(projDir, 'submodules', app)
85 if not op.exists(appDir):
86 self.announce("skipping %s" % app)
87 continue
88
89 setupPath = op.join(appDir, 'setup.py')
90 if not op.exists(setupPath):
91 self.announce("skipping %s" % app)
92 continue
93
94 subprocess.call(["python", setupPath, self.subcommand])
95
96
97 class TestCommand(RunSubCommand):
98 description = 'test geocam command'
99 user_options = []
100
101 # Option defaults
102 def initialize_options(self):
103 self.subcommand = 'geocam'
104
105 # Validate options
106 def finalize_options(self):
107 pass
108
109
110 class SymlinkCommand(Command):
111 """This command makes the submodule app directories symlinked to the
112 site-level. Will not work on windows."""
113 description = 'symlink submodules to the main site level'
114 user_options = [('force', 'f', 'overwrite existing symlinks')]
115 boolean_options = ['force']
116
117 # Option defaults
118 def initialize_options(self):
119 self.force = False
120
121 # Validate options
122 def finalize_options(self):
123 pass
124
125 def run(self):
126 subModules = find_submodules()
127 for name, directory in subModules:
128 destination = op.join(PROJ_ROOT, name)
129 if op.exists(destination):
130 if not op.islink(destination):
131 self.announce("skipping " + name + ": not a symlink")
132 continue
133 if not self.force:
134 self.announce("skipping " + name + ": file exists (use -f to override)")
135 continue
136 os.remove(destination)
137 os.symlink(directory, destination)
138
139
140 class MediaCommand(Command):
141 description = 'collect together the site-level static media'
142 user_options = [('force', 'f', 'overwrite existing symlinks')]
143 boolean_options = ['force']
144
145 # Option defaults
146 def initialize_options(self):
147 self.force = False
148
149 # Validate options
150 def finalize_options(self):
151 pass
152
153 def run(self):
154 siteMediaDir = op.join(PROJ_ROOT, 'media')
155 if not op.exists(siteMediaDir):
156 os.mkdir(siteMediaDir)
157 subApps = find_sub_apps()
158 for name, directory in subApps:
159 mediaDirectory = op.join(directory, 'media', name)
160 if not op.exists(mediaDirectory):
161 self.announce("skipping " + name + ": media directory does not exist")
162 continue
163 destination = op.join(siteMediaDir, name)
164 if op.exists(destination):
165 if not op.islink(destination):
166 self.announce("skipping " + name + ": not a symlink")
167 continue
168 if not self.force:
169 self.announce("skipping " + name + ": file exists (use -f to override)")
170 continue
171 os.remove(destination)
172 os.symlink(directory, destination)
173
174
175 setup(
176 name="geocamMapFasten",
177 version='1.0', # __import__('geocamMapFasten').get_version().replace(' ', '-'),
178 url='',
179 author='mfsmith3',
180 author_email='',
181 description=DESC,
182 long_description=read_file('README'),
183 packages=find_packages(),
184 include_package_data=True,
185 install_requires=read_file('requirements.txt'),
186 classifiers=[
187 'License :: OSI Approved :: NASA Open Source Agreement',
188 'Framework :: Django',
189 ],
190
191 cmdclass={
192 'link_submodules': SymlinkCommand,
193 'link_media': MediaCommand
194 },
195 )
Something went wrong with that request. Please try again.