diff --git a/debpython/option.py b/debpython/option.py index 014c452219154ac850137c08b92cb2c00d567533..116f807c4775611e5fbed887ca959bcd590044b7 100644 --- a/debpython/option.py +++ b/debpython/option.py @@ -18,6 +18,7 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. + import re import optparse from copy import copy diff --git a/debpython/tools.py b/debpython/tools.py index 538c5def8d017bf6e759866513ff9560fa2983aa..3ae7180c4c4348284144e69bd1b9e2d191285868 100644 --- a/debpython/tools.py +++ b/debpython/tools.py @@ -118,13 +118,16 @@ def shebang2pyver(fname): :rtype: tuple :returns: pair of Python interpreter string and Python version """ - with open(fname) as fp: - data = fp.read(32) - match = SHEBANG_RE.match(data) - if not match: - return None - res = match.groups() - if res != (None, None): - if res[1]: - res = res[0], getver(res[1]) - return res + try: + with open(fname) as fp: + data = fp.read(32) + match = SHEBANG_RE.match(data) + if not match: + return None + res = match.groups() + if res != (None, None): + if res[1]: + res = res[0], getver(res[1]) + return res + except IOError: + log.error('cannot open %s', fname) diff --git a/debpython/version.py b/debpython/version.py index 2f3ab9c24fb5244d7b2772455ab32860e12ddd56..5d2423bac0e6cd422edaff5904aeb92c0aaa48b8 100644 --- a/debpython/version.py +++ b/debpython/version.py @@ -18,6 +18,7 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. + import re from os.path import exists from types import GeneratorType @@ -229,7 +230,7 @@ def getver(value): """ if not value: return '' - return tuple(int(i) for i in value.split('.'))[:2] + return tuple(int(i) for i in value.split('.', 2))[:2] def debsorted(versions, return_str=None): diff --git a/dh_python b/dh_python index 944d602058bdd3a764e0517c4018c7313ed2dede..473a10612eae38ec3a7074e99c0c30093346ec13 100755 --- a/dh_python +++ b/dh_python @@ -41,7 +41,7 @@ from debpython.tools import sitedir, relative_symlink, guess_dependency, \ from debpython.option import Option # initialize script -logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' +\ +logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' '%(message)s') log = logging.getLogger('dh_python') os.umask(022) @@ -382,19 +382,21 @@ def dependencies(package, stats, options): depends.append(interpreter) # TODO: if versions[0] not in requested_versions: FTBFS else: # no hardcoded versions - dep = '' + dep = args = '' vr = options.vrange if vr: - args = "-V %s" % vrange_str(vr) - for pattern in options.regexpr or []: - args += " -X '%s'" % pattern.replace("'", r"\'") - rtscripts.append((private_dir, args)) - + args += "-V %s" % vrange_str(vr) if vr[0]: # minumum version specified dep = "python (>= %s)" % vrepr(vr[0]) if vr[1]: # maximum version specified dep += ", python (<< %s)" % vrepr(vr[1]) dep = dep.lstrip(', ') + + if details.get('compile', False): + for pattern in options.regexpr or []: + args += " -X '%s'" % pattern.replace("'", r"\'") + rtscripts.append((private_dir, args)) + dep = dep or 'python' if dep not in depends: depends.append(dep) @@ -432,6 +434,8 @@ def parse_pydep(fname): ################################################################ def main(): + if exists('debian/pycompat'): + sys.exist(0) # be compatible with old dh_python usage = '%prog -p PACKAGE [-V [X.Y][-][A.B]] DIR_OR_FILE [-X REGEXPR]\n' parser = OptionParser(usage, version='%prog 2.0~alpha1', option_class=Option) diff --git a/pyclean b/pyclean index 9763652702ef9f8b29a7410a707c4978b2397677..d3db3005298b6e7f1a2d5df11de2687eb041dd9e 100755 --- a/pyclean +++ b/pyclean @@ -34,7 +34,8 @@ from debpython.version import SUPPORTED # initialize script -logging.basicConfig() +logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' + '%(message)s') log = logging.getLogger('pyclean') """TODO: move it to manpage diff --git a/pycompile b/pycompile index fa0d041b712298cf0a733856594ae0a56533c5e6..d405e98b75df428ed785d0b26525d80a0c8affd6 100755 --- a/pycompile +++ b/pycompile @@ -35,9 +35,10 @@ from debpython.version import SUPPORTED, DEFAULT, debsorted, vrepr, \ from debpython.option import Option, compile_regexpr # initialize script -logging.basicConfig() +logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' + '%(message)s') log = logging.getLogger('pycompile') -# TODO: /usr/share/python2/foo/2.5-/bar/-2.7/baz.py +# TODO: /usr/share/python3/foo/3.1-/bar/-3.5/baz.py STDINS = {} """TODO: move it to manpage