Skip to content
Snippets Groups Projects
Commit 6d049e4f authored by Piotr Ożarowski's avatar Piotr Ożarowski
Browse files

* dh_python2:

  - generates rtupdate scripts for private directories that compile files
    from given package only, add --compile-all to dh_python2's call if you
    want the old behaviour (i.e. compile also files (plugins?) provided by
    other packages, which do not use a helper/bytecompile them)
* pyclean now accepts --package and private dir argument at the same time
parent da3579a4
No related branches found
No related tags found
No related merge requests found
python-defaults (2.7.2-5) UNRELEASED; urgency=low
[ Piotr Ożarowski ]
* dh_python2:
- generates rtupdate scripts for private directories that compile files
from given package only, add --compile-all to dh_python2's call if you
want the old behaviour (i.e. compile also files (plugins?) provided by
other packages, which do not use a helper/bytecompile them)
* pyclean now accepts --package and private dir argument at the same time
-- Piotr Ożarowski <piotr@debian.org> Thu, 28 Jul 2011 00:23:50 +0200
python-defaults (2.7.2-4) experimental; urgency=low
[ Piotr Ożarowski ]
......
......@@ -29,12 +29,16 @@ log = logging.getLogger(__name__)
class DebHelper(object):
"""Reinvents the wheel / some dh functionality (Perl is ugly ;-P)"""
def __init__(self, packages=None, no_packages=None):
def __init__(self, options):
self.options = options
self.packages = {}
self.python_version = None
source_section = True
binary_package = None
pkgs = options.package
skip_pkgs = options.no_package
try:
fp = open('debian/control', 'r')
except IOError:
......@@ -50,9 +54,9 @@ class DebHelper(object):
if binary_package:
if binary_package.startswith('python3'):
continue
if packages and binary_package not in packages:
if pkgs and binary_package not in pkgs:
continue
if no_packages and binary_package in no_packages:
if skip_pkgs and binary_package in skip_pkgs:
continue
if line.startswith('Architecture:'):
arch = line[13:].strip()
......@@ -65,9 +69,9 @@ class DebHelper(object):
if binary_package.startswith('python3'):
log.debug('skipping Python 3.X package: %s', binary_package)
continue
if packages and binary_package not in packages:
if pkgs and binary_package not in pkgs:
continue
if no_packages and binary_package in no_packages:
if skip_pkgs and binary_package in skip_pkgs:
continue
self.packages[binary_package] = {'substvars': {},
'autoscripts': {},
......@@ -123,7 +127,11 @@ class DebHelper(object):
if not exists(fpath):
fpath = "/usr/share/debhelper/autoscripts/%s" % tpl_name
tpl = open(fpath, 'r').read()
tpl = tpl.replace('#PACKAGE#', package)
if self.options.compile_all and args:
# TODO: should args be checked to contain dir name?
tpl = tpl.replace('#PACKAGE#', '')
else:
tpl = tpl.replace('#PACKAGE#', package)
tpl = tpl.replace('#ARGS#', i)
if tpl not in data and tpl not in new_data:
new_data += "\n%s" % tpl
......@@ -172,6 +180,7 @@ class DebHelper(object):
def save_rtupdate(self):
for package, settings in self.packages.iteritems():
pkg_arg = '' if self.options.compile_all else "-p %s" % package
values = settings.get('rtupdates')
if not values:
continue
......@@ -185,8 +194,8 @@ class DebHelper(object):
data = "#! /bin/sh\nset -e"
for dname, args in values:
cmd = 'if [ "$1" = rtupdate ]; then' +\
"\n\tpyclean %s" % dname +\
"\n\tpycompile %s %s\nfi" % (args, dname)
"\n\tpyclean %s %s" % (pkg_arg, dname) +\
"\n\tpycompile %s %s %s\nfi" % (pkg_arg, args, dname)
if cmd not in data:
data += "\n%s" % cmd
if data:
......
......@@ -489,6 +489,9 @@ def main():
help='act on the package named PACKAGE')
parser.add_option('-N', '--no-package', action='append',
help='do not act on the specified package')
parser.add_option('--compile-all', action='store_true', default=False,
help='compile all files from given private directory in postinst, '
'not just the ones provided by the package')
parser.add_option('-V', type='version_range', dest='vrange',
help='specify list of supported Python versions. ' +\
'See pycompile(1) for examples')
......@@ -559,7 +562,7 @@ def main():
log.debug('options: %s', options)
log.debug('args: %s', args)
dh = DebHelper(options.package, options.no_package)
dh = DebHelper(options)
if not options.vrange and dh.python_version:
options.vrange = parse_pycentral_vrange(dh.python_version)
......
......@@ -130,6 +130,10 @@ OPTIONS
-X REGEXPR, --exclude=REGEXPR exclude items that match given REGEXPR. You may
use this option multiple times to build up a list of things to exclude.
--compile-all compile all files from given private directory in postinst/rtupdate
not just the ones provided by the package (i.e. do not pass the --package
parameter to pycompile/pyclean)
--depends=DEPENDS translate given requirements into Debian dependencies
and add them to ${python:Depends}. Use it for missing items in requires.txt
......
......@@ -69,7 +69,7 @@ def destroyer(): # ;-)
def main():
usage = '%prog [-p PACKAGE | DIR_OR_FILE]'
usage = '%prog [-p PACKAGE] [DIR_OR_FILE]'
parser = optparse.OptionParser(usage, version='%prog 1.0')
parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
help='turn verbose more one')
......@@ -91,27 +91,28 @@ def main():
d = destroyer()
d.next() # initialize coroutine
if options.package and args:
parser.error('only one action is allowed at the same time ('
'cleaning directory or a package)')
if not options.package and not args:
parser.print_usage()
exit(1)
if options.package:
log.info('cleaning package %s', options.package)
files = dpf.from_package(options.package, extensions=('.py', '.so'))
files = add_namespace_files(files, options.package, action=False)
files = dpf.filter_out_ext(files, ('.so',))
for filename in files:
d.send(filename)
elif args:
pfiles = dpf.from_package(options.package, extensions=('.py', '.so'))
pfiles = add_namespace_files(pfiles, options.package, action=False)
pfiles = set(dpf.filter_out_ext(pfiles, ('.so',)))
if args:
log.info('cleaning directories: %s', args)
files = dpf.from_directory(args, extensions=('.py', '.so'))
files = add_namespace_files(files, action=False)
files = dpf.filter_out_ext(files, ('.so',))
for filename in files:
d.send(filename)
files = set(dpf.filter_out_ext(files, ('.so',)))
if options.package:
files = files & pfiles
else:
parser.print_usage()
exit(1)
files = pfiles
for filename in files:
d.send(filename)
if __name__ == '__main__':
main()
......@@ -261,7 +261,7 @@ multiple times to build up a list of things to exclude.')
files = dpf.filter_out_ext(files, ('.so',))
compile(files, versions,
options.force, options.optimize, e_patterns)
elif args: # other directories/files (public ones mostly)
elif args: # other directories/files
versions = debsorted(versions)[:1]
for item in args:
e_patterns = get_exclude_patterns(item, options.regexpr, versions)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment