forked from SeattleTestbed/dist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
executable_setup.py
executable file
·337 lines (266 loc) · 9.98 KB
/
executable_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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
"""
<Author>
<Start Date>
April 05, 2009
<Description>
Distutils script. Distutils is the classic python way to
automate. It supposingly takes care of portability for you.
Also, you can register with Cheese Shop (PyPI) for easy distribution.
Usually, it manages Python modules. We're more into Python
scripts, so we customize it all a bit.
Also, we add some extra handy commands.
References:
http://da44en.wordpress.com/2002/11/22/using-distutils/
http://docs.python.org/distutils/
http://blog.ianbicking.org/pythons-makefile.html
http://wiki.python.org/moin/Distutils/Tutorial
<Usage>
python setup.py ...
Do `python setup.py --help-commands` for available commands.
"""
# standard imports
from distutils.cmd import Command
from distutils.errors import *
from distutils.core import setup
# commands to customize
import distutils.command.build_scripts
import distutils.command.clean
# other python libs
import preparetest
import os
import shutil
import glob
import tempfile
#######################
# New Commands
#######################
class test(Command):
"""
<Purpose>
This command calls a script that erases all the files in a target folder,
then copies the necessary test files to the folder. Afterwards, the .mix files
in the target folder are run through the preprocessor.
If the folder doesn't exist, this command *will* create it for you.
"""
description = "run the seattle preparetest.py script"
user_options = [('include-repy-tests', 't', 'copy in the repy test files')]
boolean_options = ['t']
def initialize_options(self):
"""Setup defaults"""
self.directory = "tests"
self.include_repy_tests = False
def finalize_options(self):
""" What do we have?"""
pass
def run(self):
"""Do a little setup, then pass off to old python script"""
# remove dir if exists and recreate it. other wise create it
refresh_dir(self.directory)
# pass off to preparetest.py
cmd = "python preparetest.py " + str(self.directory)
if self.include_repy_tests:
cmd += " -t"
preparetest.exec_command(cmd)
class demokit(Command):
"""
<Purpose>
This command generates a folder of Repy and some
other files. This generated demokit folder is a distribution of Repy.
Creates a directory called "demokit". If "demokit" exists,
overwrites it.
Uses the build_scripts command to generate Repy and Seash scripts.
"""
description = "build the demokit"
user_options = []
def initialize_options(self):
"""Setup defaults"""
self.directory = "demokit"
def finalize_options(self):
"""See what we have"""
pass
def run(self):
"""Do it"""
#store root directory and get target directory
target_dir = self.directory
# remove dir if exists and recreate it. other wise create it
refresh_dir(target_dir)
# Build Repy
builder =build_scripts(self.distribution)
builder.finalize_options()
builder.run()
# Add the files
preparetest.copy_to_target("build/scripts-2.5/repy.py", target_dir)
preparetest.copy_to_target("build/scripts-2.5/seash.py", target_dir)
preparetest.copy_to_target("seattlelib/repypp.py")
preparetest.copy_to_target("repy/apps/allpairsping/allpairsping.repy", target_dir)
preparetest.copy_to_target("repy/apps/old_demokit/*", target_dir)
preparetest.copy_to_target("LICENSE.TXT", target_dir)
#######################
# Custom Standard Commands
#######################
class clean(distutils.command.clean.clean):
"""
<Purpose>
This command removes the junk of other commands. It also deletes .pyc
files. And does whatever the usual clean would do
"""
description = "clean up temporary files from the 'build', 'test', 'demokit' commands"
def initialize_options(self):
"""Setup"""
# super
distutils.command.clean.clean.initialize_options(self)
# these are the junk dirs from other commands
self._junk = ['demokit', 'tests']
def run(self):
"""Delete it all"""
# super
distutils.command.clean.clean.run(self)
# Remove .pyc files
pycs = [ ]
for dirpath, dirnames, filenames in os.walk('.'):
for fname in filenames:
if fname.endswith('.pyc'):
os.remove(os.path.join(dirpath, fname))
# Remove junk directories
for junker in self._junk:
if (os.path.exists(junker)):
if os.path.isdir(junker):
shutil.rmtree(junker)
else:
os.remove(junker)
class build_scripts(distutils.command.build_scripts.build_scripts):
"""
<Purpose>
This command generates portable versions of our scripts. But first,
we squeeze our scripts into single files.
"""
def initialize_options(self):
"""Setup"""
# super
distutils.command.build_scripts.build_scripts.initialize_options(self)
# these are files needed (included/imported) to build each script
repy_core = ['repy/*.py', 'nodemanager/servicelogger.mix', 'seattlelib/*.r2py', 'nodemanager/persist.py']
nm_core = ['nodemanager/*.mix', 'nodemanager/*.py']
self._dependencies = {
'repy.py': repy_core,
'seash.py': ['seash/seash.mix', 'portability/repyportability.py'] + repy_core + nm_core,
'rhizoma.py': ['seattlelib/rhizoma.mix', 'portability/repyportability.py', 'autograder/nm_remote_api.mix'] + repy_core + nm_core}
def run(self):
"""Process, squeeze, call super, and then clean up"""
# this will dump a processed-squeezed version each script
# into the current directory
for script in self.scripts:
# create a temporary file
tmpdirname = tempfile.mkdtemp()
# copy and process repy in the tmp directory
process_it(script, self._dependencies[script], tmpdirname)
squeeze_it(script, tmpdirname)
# clean up
shutil.rmtree(tmpdirname)
# now do the usual with the newly created scripts
distutils.command.build_scripts.build_scripts.run(self)
# then remove the tmp squeezed ones
for script in self.scripts:
os.remove(script)
######################
# Helpers
####################
def refresh_dir(directory):
"""Creates the directory, or deletes and recreates."""
# remove dir if exists
if (os.path.exists(directory)):
if os.path.isdir(directory):
shutil.rmtree(directory)
else:
os.remove(directory)
# recreate it
os.mkdir(directory)
def squeeze_it(script, tmpdirname):
"""
<Purpose>
Turn a bunch of python files into one compressed file
<Args>
script - the main module to start at
tmpdirname - the directory with all the dependent files
<Pre>
Process all files using process_it() into the tmp dir.
The files in the tmp should be the minimal set of files.
<Side Effect>
Dumps the compressed script into the current directory
"""
fileglob = tmpdirname + "/*.py"
scriptnameonly = os.path.splitext(os.path.basename(script))[0]
cmd = "python squeeze.py -1 -o " + scriptnameonly + " -b " + scriptnameonly + " " + fileglob
preparetest.exec_command(cmd)
def process_it(script, dependencies, tmpdirname):
"""
<Purpose>
Copy into the directory and process all the files needed for the script.
Remove unneeded files after processing.
<Args>
script - the main module to build
dependencies - the files the main script includes or imports
tmpdirname - the temporary directory
<Side Effects>
Leaves the minimal set of files neccessary to run the script in the tmp dir
"""
target_dir = tmpdirname
current_dir = os.getcwd()
# copy them all in
for filepath in dependencies:
preparetest.copy_to_target(filepath, target_dir)
# add some utils
preparetest.copy_to_target("seattlelib/repypp.py", target_dir)
#set working directory to the test folder
os.chdir(target_dir)
#call the process_mix function to process all mix files in the target directory
preparetest.process_mix("repypp.py")
# rm build files
files_to_remove = glob.glob("*.mix") + glob.glob("*.repy") + \
glob.glob("*.r2py")
for fn in files_to_remove:
os.remove(fn)
os.remove("repypp.py") # get rid of the repypp.py file
#go back to root project directory
os.chdir(current_dir)
#################
# Main
#################
"""
<Purpose>
Main interface to Distutils.
<Usage>
cmdclass
Add new commands to the cmdclass dictionary.
scripts
Add other scripts here and modify build_scripts
to correctly build them.
<Else>
All other details are metadata. Distutils uses
then to register your project with Cheese Shop
as well as generate user help messages.
"""
commandClasses = dict(
test = test,
demokit = demokit,
clean = clean,
build_scripts = build_scripts)
setup(name = "Seattle",
version = "0.1e",
author = 'Justin Cappos',
author_email="[email protected]",
maintainer = 'Ivan Beschastnikh',
maintainer_email="[email protected]",
url = "http://seattle.cs.washington.edu",
description = "a platform for networking and distributed systems research",
long_description = """
Seattle is a platform for networking and distributed systems research. It's free, community-driven, and offers a large deployment of computers spread across the world.
Seattle works by operating on resources donated by users and institutions. It's currently targeted for use by educators teaching networking and distributed systems
classes. The global distribution of the Seattle network provides the ability to use it in application contexts that include cloud computing, peer-to-peer networking,
ubiquitous/mobile computing, distributed systems.
""",
keywords = "seattle repy",
license = "GENI Public License",
scripts = ['repy.py', 'seash.py', 'rhizoma.py'],
cmdclass = commandClasses)