forked from pyroscope/pyrocore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
352 lines (294 loc) · 10.7 KB
/
pavement.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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# -*- coding: utf-8 -*-
""" PyroCore - Python Torrent Tools Core Package.
PyroScope is a collection of tools for the BitTorrent protocol and especially the rTorrent client.
This is the core package and basic command line tools subproject.
Copyright (c) 2010, 2011 The PyroScope Project <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
from __future__ import with_statement
import os
import re
import sys
import glob
import time
import webbrowser
from paver.easy import *
from paver.setuputils import setup
try:
from pyrobase.paver.easy import *
except ImportError:
pass # dependencies not yet installed
from setuptools import find_packages
SPHINX_AUTOBUILD_PORT = 8340
#
# Project Metadata
#
changelog = path("debian/changelog")
if not changelog.exists():
changelog = path("../debian/changelog")
name, version = open(changelog).readline().split(" (", 1)
version, _ = version.split(")", 1)
project = Bunch(
# egg
name = "pyrocore",
version = version,
package_dir = {"": "src"},
packages = find_packages("src", exclude = ["tests"]),
entry_points = {
"console_scripts": [
"chtor = pyrocore.scripts.chtor:run",
"hashcheck = pyrocore.scripts.hashcheck:run",
"lstor = pyrocore.scripts.lstor:run",
"mktor = pyrocore.scripts.mktor:run",
"pyroadmin = pyrocore.scripts.pyroadmin:run",
"rtcontrol = pyrocore.scripts.rtcontrol:run",
"rtevent = pyrocore.scripts.rtevent:run",
"rtmv = pyrocore.scripts.rtmv:run",
"rtxmlrpc = pyrocore.scripts.rtxmlrpc:run",
"pyrotorque = pyrocore.scripts.pyrotorque:run",
# "rtorrd = pyrocore.scripts.rtorrd:run",
],
},
include_package_data = True,
zip_safe = False,
data_files = [
("EGG-INFO", [
"README.md", "LICENSE", "debian/changelog",
]),
],
# dependencies
setup_requires = [
],
install_requires = [
"pyrobase>=0.2",
"ProxyTypes>=0.9",
],
extras_require = {
"templating": ["Tempita>=0.5.1"],
"pyrotorque": ["APScheduler>=2.0.2,<3"],
"pyrotorque.httpd": ["waitress>=0.8.2", "WebOb>=1.2.3", "psutil>=0.6.1"],
"FlexGet": ["flexget>=1.0"],
},
# tests
test_suite = "nose.collector",
# cheeseshop
author = "The PyroScope Project",
author_email = "[email protected]",
description = __doc__.split('.', 1)[0].strip(),
long_description = __doc__.split('.', 1)[1].strip(),
license = [line.strip() for line in __doc__.splitlines()
if line.strip().startswith("Copyright")][0],
url = "http://code.google.com/p/pyroscope/",
keywords = "bittorrent rtorrent cli python",
classifiers = [
# see http://pypi.python.org/pypi?:action=list_classifiers
#"Development Status :: 3 - Alpha",
#"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Natural Language :: English",
"Operating System :: POSIX",
"Programming Language :: Python :: 2.5",
"Topic :: Communications :: File Sharing",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
],
)
options(
setup=project,
docs=Bunch(docs_dir="docs/apidocs", includes="pyrobase"),
)
setup(**project)
#
# Build
#
@task
@needs(["setuptools.command.egg_info"])
def bootstrap():
"initialize project"
# Link files shared by subprojects
debian = path("debian")
debian.exists() or debian.makedirs()
for shared in ("debian/changelog", "LICENSE"):
path(shared).exists() or (path("..") / shared).link(shared)
build()
@task
def build():
"build the software"
rtrc_086 = path("src/pyrocore/data/config/rtorrent-0.8.6.rc")
rtrc_089 = path(str(rtrc_086).replace("0.8.6", "0.8.9"))
if not rtrc_089.exists() or rtrc_086.mtime > rtrc_089.mtime:
rtrc_089.write_bytes(rtrc_086.text().replace("#087#", ""))
sh("./src/scripts/migrate_rtorrent_rc.sh %s >/dev/null" % rtrc_089)
sh("bash -c 'rm %s{?0.8.6,-????-??-??-??-??-??}'" % rtrc_089)
call_task("setuptools.command.build")
@task
def gendocs():
"create some doc pages automatically"
helppage = path("docs/references-cli-usage.rst")
content = [
".. automatically generated using 'paver gendocs'.",
"",
".. contents::",
" :local:",
"",
".. note::",
"",
" The help output presented here applies to version ``%s`` of the tools."
% sh("pyroadmin --version", capture=True).split()[1],
"",
]
for tool in sorted(project.entry_points["console_scripts"]):
tool, _ = tool.split(None, 1)
content.extend([
".. _cli-usage-%s:" % tool,
"",
tool,
'^' * len(tool),
"",
"::",
"",
])
help_opt = "--help-fields --config-dir /tmp" if tool == "rtcontrol" else "--help"
help_txt = sh("%s -q %s" % (tool, help_opt), capture=True, ignore_error=True).splitlines()
content.extend(' ' + i for i in help_txt)
content.extend([
"",
])
content = [line.rstrip() for line in content if all(
i not in line for i in (", Copyright (c) ", "Total time: ", "Configuration file '/tmp/")
)]
content = [line for line, succ in zip(content, content[1:] + ['']) if line or succ] # filter twin empty lines
helppage.write_lines(content)
@task
@needs("docs")
def dist_docs():
"create a documentation bundle"
dist_dir = path("dist")
docs_package = path("%s/%s-%s-docs.zip" % (dist_dir.abspath(), options.setup.name, options.setup.version))
dist_dir.exists() or dist_dir.makedirs()
docs_package.exists() and docs_package.remove()
sh(r'cd docs && find . -type f \! \( -path "*/.svn*" -o -name "*~" \) | sort'
' | zip -qr -@ %s' % (docs_package,))
print
print "Upload @ http://pypi.python.org/pypi?:action=pkg_edit&name=%s" % ( options.setup.name,)
print docs_package
@task
@needs("stopdocs")
def autodocs():
"create Sphinx docs locally, and start a watchdog"
build_dir = path('docs/_build')
index_html = build_dir / 'html/index.html'
if build_dir.exists():
build_dir.rmtree()
with pushd("docs"):
print "\n*** Generating API doc ***\n"
sh("sphinx-apidoc -o apidoc -f -T -M ../src/pyrocore")
print "\n*** Generating HTML doc ***\n"
sh('nohup %s/Makefile SPHINXBUILD="sphinx-autobuild -p %d'
' -i \'.*\' -i \'*.log\' -i \'*.png\' -i \'*.txt\'" html >autobuild.log 2>&1 &'
% (os.getcwd(), SPHINX_AUTOBUILD_PORT))
for i in range(10):
time.sleep(.5)
pid = sh('netstat -tulpn 2>/dev/null | grep 127.0.0.1:%d' % (SPHINX_AUTOBUILD_PORT,),
capture=True, ignore_error=True)
if pid:
sh("touch docs/index.rst")
pid, _ = pid.split()[-1].split('/', 1)
sh('ps %s' % pid)
url = 'http://localhost:%d/' % SPHINX_AUTOBUILD_PORT
print "\n*** Open '%s' in your browser..." % url
break
@task
def stopdocs():
"stop Sphinx watchdog"
for i in range(4):
pid = sh('netstat -tulpn 2>/dev/null | grep 127.0.0.1:%d' % (SPHINX_AUTOBUILD_PORT,),
capture=True, ignore_error=True).strip()
if pid:
pid, _ = pid.split()[-1].split('/', 1)
if not i:
sh('ps %s' % pid)
sh('kill %s' % pid)
time.sleep(.5)
else:
break
#
# Testing
#
@task
@needs("nosetests")
def test():
"run unit tests"
@task
def coverage():
"generate coverage report and show in browser"
coverage_index = path("build/coverage/index.html")
coverage_index.remove()
sh("paver test")
coverage_index.exists() and webbrowser.open(coverage_index)
@task
@needs("build")
def functest():
"functional test of the command line tools"
bindir = os.path.dirname(sys.executable)
sh(bindir + "/mktor -o build/pavement.torrent pavement.py http://example.com/")
sh(bindir + "/mktor -o build/tests.torrent -x '*.pyc' -r 'pyroscope tests' --private src/tests/ http://example.com/")
sh(bindir + "/lstor build/*.torrent")
@task
def installtest():
"test of fresh installation"
testdir = path("build/install-test")
if testdir.exists():
testdir.rmtree()
if os.environ.get('TRAVIS', '').lower() == 'true':
sh("git clone https://github.com/pyroscope/pyrocore.git " + testdir)
else:
sh("git clone . " + testdir)
testbin = testdir / "test-bin"
testbin.makedirs()
os.environ["BIN_DIR"] = testbin.abspath()
os.environ["PROJECT_ROOT"] = ''
with pushd(testdir):
sh("./update-to-head.sh")
sh("./test-bin/pyroadmin --version")
#
# Release Management
#
@task
@needs(["dist_clean", "build", "minilib", "generate_setup", "sdist"])
def release():
"check release before upload to PyPI"
sh("paver bdist_egg")
# Check that source distribution can be built and is complete
print
print "~" * 78
print "TESTING SOURCE BUILD"
sh(
"{ cd dist/ && unzip -q %s-%s.zip && cd %s-%s/"
" && /usr/bin/python setup.py sdist >/dev/null"
" && if { unzip -ql ../%s-%s.zip; unzip -ql dist/%s-%s.zip; }"
" | cut -b26- | sort | uniq -c| egrep -v '^ +2 +' ; then"
" echo '^^^ Difference in file lists! ^^^'; false;"
" else true; fi; } 2>&1"
% tuple([project["name"], version] * 4)
)
path("dist/%s-%s" % (project["name"], version)).rmtree()
print "~" * 78
print
print "Created", " ".join([str(i) for i in path("dist").listdir()])
print "Use 'paver sdist bdist_egg upload' to upload to PyPI"
print "Use 'paver dist_docs' to prepare an API documentation upload"