Merge lp://staging/~andrea.corbellini/beeseek/packaging into lp://staging/beeseek/1.0

Proposed by Andrea Corbellini
Status: Merged
Approved by: Andrea Corbellini
Approved revision: 336
Merged at revision: not available
Proposed branch: lp://staging/~andrea.corbellini/beeseek/packaging
Merge into: lp://staging/beeseek/1.0
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~andrea.corbellini/beeseek/packaging
Reviewer Review Type Date Requested Status
Andrea Colangelo Approve
Review via email: mp+10844@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

The new code in this branch helps both users and developers when creating packages. It improves the build process in different ways:

setup.py:
1. Exclude files and directories that are not needed (test files and API documentation).
2. If given, use the --root option instead of --prefix to install data.

Makefile:
1. Avoid the re-build of files already created.

The Makefile also has new commands to create four different types of archives: tar, tar.gz, tar.bz2, zip.

This branch is needed for the creation of distribution packages too.

Revision history for this message
Andrea Colangelo (warp10) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2009-08-09 16:13:30 +0000
3+++ Makefile 2009-08-28 13:32:45 +0000
4@@ -13,20 +13,48 @@
5 # You should have received a copy of the GNU Affero General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-PYTHON=/usr/bin/python
9-
10+NAME := beeseek-peer
11+VERSION := $(shell ./beeseek-peer version --short)
12+FULLNAME := $(NAME)-$(VERSION)
13+PYVERSION := $(shell python -V 2>&1 | egrep -o '([0-9]\.[0-9])')
14+PLATFORM := $(shell uname -s | tr A-Z a-z)-$(shell uname -m)
15+PKGFILES := build/lib.$(PLATFORM)-$(PYVERSION)/beeseek \
16+ build/scripts-$(PYVERSION)/beeseek-peer \
17+ beeseek-peer.init config database templates setup.py
18 pyflakes_ignore := beeseek/tests/unittests/.*\.py.*(undefined name|imported but unused)
19
20 build: version-info
21- $(PYTHON) setup.py build
22+ python setup.py build
23
24 install: build
25- $(PYTHON) setup.py install
26+ python setup.py install
27
28-version-info:
29+version-info: beeseek/_version_info.py
30+beeseek/_version_info.py:
31 bzr version-info --python > beeseek/_version_info.py
32
33
34+dist: build
35+ mkdir -p dist/$(FULLNAME)
36+ cp -R $(PKGFILES) dist/$(FULLNAME)
37+
38+tar: dist/$(FULLNAME).tar
39+dist/$(FULLNAME).tar: dist
40+ tar -cf dist/$(FULLNAME).tar -C dist $(FULLNAME)
41+
42+tar.gz: dist/$(FULLNAME).tar.gz
43+dist/$(FULLNAME).tar.gz: tar
44+ gzip -9 dist/$(FULLNAME).tar
45+
46+tar.bz2: dist/$(FULLNAME).tar.bz2
47+dist/$(FULLNAME).tar.bz2: tar
48+ bzip2 -9 dist/$(FULLNAME).tar
49+
50+zip: dist/$(FULLNAME).zip
51+dist/$(FULLNAME).zip: dist
52+ cd dist; zip -rq $(FULLNAME).zip $(FULLNAME)
53+
54+
55 pychecker:
56 find beeseek -name "*.py" | xargs pychecker --limit=100000
57
58@@ -42,12 +70,13 @@
59 pylint -f parseable -r no --enable-checker miscellaneous beeseek
60
61
62-docs:
63+docs: doc/build
64+doc/build:
65 sphinx-build -b html -d doc/build/doctrees -N -c doc/ beeseek/docs doc/build/html
66 epydoc --html -n"BeeSeek" --no-frames --no-source --simple-term beeseek -o doc/build/html/source
67
68 clean:
69- rm -rf build doc/build dist beeseek/_version_info.py
70+ rm -rf build dist doc/build beeseek/_version_info.py
71 find . -name "*.pyc" -o -name "*.pyo" -o -name "*~" | xargs rm -f
72
73 clean-db:
74
75=== modified file 'beeseek/app/directory.py'
76--- beeseek/app/directory.py 2009-07-09 11:37:49 +0000
77+++ beeseek/app/directory.py 2009-07-14 16:07:24 +0000
78@@ -15,24 +15,37 @@
79
80 import os
81 import stat
82+import sys
83 import tempfile
84
85
86-tempdirs = tempfile._candidate_tempdir_list()
87+lockdirs = tempfile._candidate_tempdir_list()
88+if os.name != 'nt':
89+ lockdirs.insert(0, '/var/lock')
90
91 class Directory(object):
92
93 __slots__ = 'dirlist', '_mode', '_subdirs', '_directory', '_create'
94
95- def __init__(self, dirlist, **kwargs):
96+ def __init__(self, dirlist, mode='rw', subdirs=(), create=False,
97+ adjust=False):
98 if isinstance(dirlist, basestring):
99 dirlist = (dirlist,)
100+ if adjust and os.name == 'nt':
101+ dirlist = self._adjust_for_win(dirlist)
102 self.dirlist = tuple(os.path.normcase(os.path.abspath(
103 os.path.expanduser(directory)))
104 for directory in dirlist)
105- self._mode = kwargs.get('mode', 'rw')
106- self._subdirs = kwargs.get('subdirs', ())
107- self._create = kwargs.get('create', ())
108+ self._mode = mode
109+ self._subdirs = subdirs
110+ self._create = create
111+
112+ def _adjust_for_win(self, dirlist):
113+ basepath = os.path.dirname(sys.executable)
114+ for directory in dirlist:
115+ yield os.path.join(basepath,
116+ 'BeeSeek',
117+ os.path.basename(directory))
118
119 def _check_permissions(self, directory):
120 strmode = self._mode
121@@ -41,7 +54,6 @@
122 stat_result = os.stat(directory)
123 usermode = groupmode = othermode = 0
124
125- # _issuitable() should be called rarely so we can use hasattr() here
126 if not hasattr(os, 'getuid') or stat_result.st_uid == os.getuid():
127 if 'r' in strmode:
128 usermode = stat.S_IXUSR
129
130=== modified file 'beeseek/app/options.py'
131--- beeseek/app/options.py 2009-08-23 19:12:47 +0000
132+++ beeseek/app/options.py 2009-08-24 15:10:30 +0000
133@@ -15,7 +15,7 @@
134
135 import os
136 from beeseek.app import instance
137-from beeseek.app.directory import Directory, tempdirs
138+from beeseek.app.directory import Directory, lockdirs
139 from beeseek.interface import Interface, implements
140
141
142@@ -198,6 +198,14 @@
143 'Enable the testing mode.')
144
145
146+class VersionOptions(BaseOptionList):
147+
148+ implements(IOptionList)
149+
150+ short = Option(bool, None, ('-s', '--short'), None,
151+ 'Show just the version number.')
152+
153+
154 class CommonServiceOptions(CommonOptions):
155
156 """Options to deal with the service."""
157@@ -212,7 +220,7 @@
158 lockdir = Option(Directory, 'LockDirectory',
159 ('-L', '--lock-dir'), None,
160 'The directory for lock files.',
161- default=['/var/lock'] + tempdirs,
162+ default=lockdirs,
163 convert_default=True)
164
165 user = Option(str, 'User',
166@@ -235,7 +243,8 @@
167 convert_kwargs={
168 'subdirs': ('keywords', 'pages', 'configuration',
169 'statistics', 'keys', 'needed-results'),
170- 'create': True})
171+ 'create': True,
172+ 'adjust': True})
173
174 daemon = Option(bool, 'Daemon',
175 ('-b', '--daemon'), ('-f', '--foreground'),
176@@ -254,7 +263,9 @@
177 testing_default='templates',
178 convert_default=True,
179 convert_kwargs={
180- 'mode': 'r', 'subdirs': ('css', 'html', 'images', 'javascript')})
181+ 'mode': 'r',
182+ 'subdirs': ('css', 'html', 'images', 'javascript'),
183+ 'adjust': True})
184
185 server_hostname = Option(str, 'ServerHostname',
186 ('-s', '--server'), None,
187
188=== modified file 'beeseek/app/session.py'
189--- beeseek/app/session.py 2009-08-24 12:38:07 +0000
190+++ beeseek/app/session.py 2009-08-24 15:10:30 +0000
191@@ -29,7 +29,7 @@
192 from beeseek.app.command import CommandObject, command
193 from beeseek.app.baseconfig import ConfigurationParser
194 from beeseek.app.options import (
195- CommonOptions, CommonServiceOptions, StartOptions)
196+ CommonOptions, VersionOptions, CommonServiceOptions, StartOptions)
197 from beeseek.app.directory import Directory
198 from beeseek.app.utils import get_argcount
199
200@@ -210,7 +210,10 @@
201 return getattr(self, '_status', 'unknown')
202
203 # Configuration
204- configdir = Directory(('/etc/beeseek', '~/.beeseek', 'config'), mode='r')
205+ # XXX This should be set elsewhere
206+ configdir = Directory(('/etc/beeseek', 'config'),
207+ mode='r',
208+ adjust=True)
209 logfile = open(os.devnull, 'w')
210 debug = False
211
212@@ -645,12 +648,15 @@
213 parser.populate(command_obj.optionlist)
214 print parser.format_option_help()
215
216- @command(CommonOptions)
217+ @command(VersionOptions)
218 def version(self):
219 """Show version information."""
220- print '%s version %s' % (self.appname, version_info)
221- if version_info.revno:
222- print 'Revision: %s' % version_info.revno
223+ if self.short:
224+ print version_info
225+ else:
226+ print '%s version %s' % (self.appname, version_info)
227+ if version_info.revno:
228+ print 'Revision: %s' % version_info.revno
229
230
231 # Operations queue and threads
232
233=== modified file 'setup.py'
234--- setup.py 2009-08-23 19:12:47 +0000
235+++ setup.py 2009-08-26 13:11:35 +0000
236@@ -23,43 +23,71 @@
237 import os
238 from distutils.core import setup
239 from distutils.command.install_data import install_data
240-import pwd
241+try:
242+ import pwd
243+except ImportError:
244+ pwd = None
245 import beeseek
246
247
248 class configure_and_install_data(install_data):
249
250+ def finalize_options(self):
251+ if self.install_dir is None:
252+ install_cmd = self.distribution.get_command_obj('install')
253+ self.install_dir = install_cmd.root or install_cmd.prefix
254+ dir_specified = self.install_dir
255+ install_data.finalize_options(self)
256+ if not dir_specified and os.name != 'nt':
257+ self.install_dir = os.path.dirname(install_cmd.prefix)
258+
259 def run(self):
260- data_files = self.data_files = []
261- dirs_map = {
262- 'etc/beeseek': 'config',
263- 'var/lib/beeseek/database': 'database',
264- 'usr/share/beeseek/templates': 'templates'
265- }
266+ install_dir = self.install_dir
267+ if os.name == 'nt':
268+ dirs_map = {
269+ 'BeeSeek/config': 'config',
270+ 'BeeSeek/database': 'database',
271+ 'BeeSeek/webdata': 'webdata'
272+ }
273+ else:
274+ dirs_map = {
275+ 'etc/beeseek': 'config',
276+ 'var/lib/beeseek/database': 'database',
277+ 'usr/share/beeseek/templates': 'templates'
278+ }
279
280 for destination, source in dirs_map.iteritems():
281- sourcelen = len(source) + 1
282+ destination = os.path.join(install_dir, destination)
283+ self.mkpath(destination)
284 for directory, subdirs, subfiles in os.walk(source):
285- path = os.path.join(destination, directory[sourcelen:])
286- subfiles = [os.path.join(directory, filename)
287- for filename in subfiles]
288- data_files.append((path, subfiles))
289-
290- install_data.run(self)
291- self.mkpath(os.path.join(self.install_dir, 'etc/init.d'))
292- self.copy_file('beeseek-peer.init',
293- os.path.join(self.install_dir,
294- 'etc/init.d/beeseek-peer'))
295- self.mkpath(os.path.join(self.install_dir, 'var/log/beeseek'))
296-
297- items = pwd.getpwnam('www-data')
298- uid, gid = items[2], items[3]
299- for path in ('var/log/beeseek', 'var/lib/beeseek'):
300- path = os.path.join(self.install_dir, path)
301- for directory, subdirs, subfiles in os.walk(path):
302- os.chown(directory, uid, gid)
303- for filename in subfiles:
304- os.chown(os.path.join(directory, filename), uid, gid)
305+ subdirectory = directory[len(source)+1:]
306+ for subdir in subdirs:
307+ self.mkpath(
308+ os.path.join(destination, subdirectory, subdir))
309+ for file_name in subfiles:
310+ self.copy_file(
311+ os.path.join(directory, file_name),
312+ os.path.join(destination, subdirectory, file_name))
313+
314+ if os.name != 'nt':
315+ self.mkpath(os.path.join(install_dir, 'etc/init.d'))
316+ self.copy_file('beeseek-peer.init',
317+ os.path.join(install_dir, 'etc/init.d/beeseek-peer'))
318+ self.mkpath(os.path.join(install_dir, 'var/log/beeseek'))
319+
320+ if not self.dry_run and pwd:
321+ items = pwd.getpwnam('www-data')
322+ uid, gid = items[2], items[3]
323+ for path in ('var/log/beeseek', 'var/lib/beeseek'):
324+ path = os.path.join(install_dir, path)
325+ for directory, subdirs, subfiles in os.walk(path):
326+ try:
327+ os.chown(directory, uid, gid)
328+ for filename in subfiles:
329+ os.chown(
330+ os.path.join(directory, filename), uid, gid)
331+ except OSError:
332+ pass
333
334
335 def add_packages(metadata):
336@@ -68,10 +96,13 @@
337 packages = metadata['packages'] = []
338 for directory, subdirs, subfiles in os.walk(path):
339 name = directory[unneeded:].replace(os.path.sep, '.')
340- if (name.startswith('beeseek.tests')
341- or name.startswith('beeseek.app.server')):
342- continue
343- packages.append(name)
344+ skip = False
345+ for package in exclude_packages:
346+ if name.startswith(package):
347+ skip = True
348+ break
349+ if not skip:
350+ packages.append(name)
351
352 def add_description(metadata):
353 from beeseek.app import peer
354@@ -83,6 +114,13 @@
355 metadata['description'] = summary.rstrip('.')
356 metadata['long_description'] = description.strip()
357
358+exclude_packages = [
359+ 'beeseek.app.server',
360+ 'beeseek.docs',
361+ 'beeseek.testing',
362+ 'beeseek.tests',
363+ ]
364+
365 metadata = {
366 'name': 'beeseek-peer',
367 'version': beeseek.__version__,
368
369=== modified file 'testsuite.py'
370--- testsuite.py 2009-08-05 16:40:13 +0000
371+++ testsuite.py 2009-08-24 14:52:46 +0000
372@@ -130,6 +130,9 @@
373 for test_case in testlist:
374 test_case.run(run_dependencies)
375 testing.Logger.finish()
376+ if testing.Logger.failures or testing.Logger.errors:
377+ sys.exit(1)
378+ sys.exit(0)
379
380
381 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches