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

remove public modules listed in debian/pkg.pyremove

parent a69f2a20
No related branches found
No related tags found
No related merge requests found
...@@ -2,9 +2,11 @@ python-defaults (2.6.6-6) UNRELEASED; urgency=low ...@@ -2,9 +2,11 @@ python-defaults (2.6.6-6) UNRELEASED; urgency=low
* Make the error message about missing extension more clear * Make the error message about missing extension more clear
(and more verbose in --verbose mode) (and more verbose in --verbose mode)
* dh_python2: install files listed in debian/package.pyinstall file * dh_python2: install files listed in debian/pkg.pyinstall file
as public modules for all requested Python versions (use dh_install's as public modules for all requested Python versions (use dh_install's
package.install files for private modules) package.install files for private modules); remove public modules listed
in debian/pkg.pyremove (glob.glob pattern and version range can be used in
both files)
* pycompile: `pycompile $DESTDIR/usr/lib/python*` will recognize public * pycompile: `pycompile $DESTDIR/usr/lib/python*` will recognize public
site-packages directories and use the right interpreter instead of raising site-packages directories and use the right interpreter instead of raising
KeyError KeyError
......
...@@ -22,11 +22,12 @@ ...@@ -22,11 +22,12 @@
from __future__ import with_statement from __future__ import with_statement
import codecs import codecs
import logging import logging
import os
import re import re
from cPickle import dumps from cPickle import dumps
from glob import glob from glob import glob
from os import link, makedirs, symlink from os.path import exists, isdir, join, split
from os.path import exists, join, split from shutil import rmtree
from debpython.version import RANGE_PATTERN, getver, get_requested_versions from debpython.version import RANGE_PATTERN, getver, get_requested_versions
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -39,6 +40,11 @@ INSTALL_RE = re.compile(r""" ...@@ -39,6 +40,11 @@ INSTALL_RE = re.compile(r"""
\s* # optional version range: \s* # optional version range:
(?P<vrange>%s)?$ (?P<vrange>%s)?$
""" % RANGE_PATTERN, re.VERBOSE) """ % RANGE_PATTERN, re.VERBOSE)
REMOVE_RE = re.compile(r"""
(?P<pattern>.+?) # file pattern
\s* # optional version range:
(?P<vrange>%s)?$
""" % RANGE_PATTERN, re.VERBOSE)
def sitedir(version, package=None, gdb=False): def sitedir(version, package=None, gdb=False):
...@@ -80,7 +86,7 @@ def relpath(target, link): ...@@ -80,7 +86,7 @@ def relpath(target, link):
def relative_symlink(target, link): def relative_symlink(target, link):
"""Create relative symlink.""" """Create relative symlink."""
return symlink(relpath(target, link), link) return os.symlink(relpath(target, link), link)
def shebang2pyver(fname): def shebang2pyver(fname):
...@@ -131,7 +137,7 @@ class memoize(object): ...@@ -131,7 +137,7 @@ class memoize(object):
def pyinstall(package, vrange): def pyinstall(package, vrange):
"""Install local files listed in .pyinstall files as public modules.""" """Install local files listed in pkg.pyinstall files as public modules."""
status = True status = True
srcfpath = "./debian/%s.pyinstall" % package srcfpath = "./debian/%s.pyinstall" % package
if not exists(srcfpath): if not exists(srcfpath):
...@@ -151,6 +157,10 @@ def pyinstall(package, vrange): ...@@ -151,6 +157,10 @@ def pyinstall(package, vrange):
if details['module']: if details['module']:
details['module'] = details['module'].replace('.', '/') details['module'] = details['module'].replace('.', '/')
myvers = versions & get_requested_versions(details['vrange']) myvers = versions & get_requested_versions(details['vrange'])
if not myvers:
log.debug('%s.pyinstall: no matching versions for line %s',
package, line)
continue
files = glob(details['pattern']) files = glob(details['pattern'])
if not files: if not files:
status = False status = False
...@@ -170,13 +180,65 @@ def pyinstall(package, vrange): ...@@ -170,13 +180,65 @@ def pyinstall(package, vrange):
dstdir = split(dstfpath)[0] dstdir = split(dstfpath)[0]
if not exists(dstdir): if not exists(dstdir):
try: try:
makedirs(dstdir) os.makedirs(dstdir)
except: except:
log.error('cannot create %s directory', dstdir) log.error('cannot create %s directory', dstdir)
return False return False
if exists(dstfpath):
try:
os.remove(dstfpath)
except:
status = False
log.error('cannot replace %s file', dstfpath)
continue
try: try:
link(fpath, dstfpath) os.link(fpath, dstfpath)
except: except:
status = False status = False
log.error('cannot copy %s file to %s', fpath, dstdir) log.error('cannot copy %s file to %s', fpath, dstdir)
return status return status
def pyremove(package, vrange):
"""Remove public modules listed in pkg.pyremove file."""
status = True
srcfpath = "./debian/%s.pyremove" % package
if not exists(srcfpath):
return status
versions = get_requested_versions(vrange)
for line in codecs.open(srcfpath, encoding='utf-8'):
if not line or line.startswith('#'):
continue
details = REMOVE_RE.match(line)
if not details:
status = False
log.warn('%s.pyremove: unrecognized line: %s',
package, line)
continue
details = details.groupdict()
myvers = versions & get_requested_versions(details['vrange'])
if not myvers:
log.debug('%s.pyremove: no matching versions for line %s',
package, line)
continue
for version in myvers:
files = glob(sitedir(version, package) + details['pattern'])
if not files:
log.debug('%s.pyremove: nothing to remove: python%d.%d, %s',
package, version, details['pattern'])
continue
for fpath in files:
if isdir(fpath):
try:
rmtree(fpath)
except Exception, e:
status = False
log.error(e)
else:
try:
os.remove(fpath)
except (IOError, OSError), e:
status = False
log.error(e)
return status
...@@ -41,7 +41,7 @@ from debpython.pydist import validate as validate_pydist, \ ...@@ -41,7 +41,7 @@ from debpython.pydist import validate as validate_pydist, \
PUBLIC_DIR_RE PUBLIC_DIR_RE
from debpython.tools import sitedir, relative_symlink, \ from debpython.tools import sitedir, relative_symlink, \
shebang2pyver, clean_egg_name,\ shebang2pyver, clean_egg_name,\
pyinstall pyinstall, pyremove
from debpython.option import Option from debpython.option import Option
# initialize script # initialize script
...@@ -486,6 +486,8 @@ def main(): ...@@ -486,6 +486,8 @@ def main():
log.debug('processing package %s...', package) log.debug('processing package %s...', package)
if not pyinstall(package, options.vrange): if not pyinstall(package, options.vrange):
exit(4) exit(4)
if not pyremove(package, options.vrange):
exit(5)
fix_locations(package) fix_locations(package)
stats = scan(package, private_dir) stats = scan(package, private_dir)
share(package, stats, options) share(package, stats, options)
......
debian/spam.py foo 2.5-
foo/spam.py 2.6
foo/bar 2.7-
print 'SPAM'
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