This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository dh-python.

commit 118e26c81f5cf2c05c7c13d99786d070d6ef47bf
Author: Piotr Ożarowski <pi...@debian.org>
Date:   Sat Jun 29 23:00:35 2013 +0200

    move fix_locations to dhpython.fs
---
 dh_python2     | 49 +++-----------------------------
 dh_python3     | 74 +++---------------------------------------------
 dhpython/fs.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 115 deletions(-)

diff --git a/dh_python2 b/dh_python2
index 0b43c80..b45a755 100755
--- a/dh_python2
+++ b/dh_python2
@@ -35,7 +35,8 @@ sys.path.insert(1, '/usr/share/dh-python/')
 from dhpython.debhelper import DebHelper
 from dhpython.depends import Dependencies
 from dhpython.interpreter import Interpreter
-from dhpython.version import supported, default, Version, VersionRange, \
+from dhpython.fs import fix_locations
+from dhpython.version import supported, default, VersionRange, \
     get_requested_versions
 from dhpython.pydist import validate as validate_pydist
 from dhpython.tools import relative_symlink,\
@@ -53,48 +54,6 @@ os.umask(0o22)
 DEFAULT = default('cpython2')
 SUPPORTED = supported('cpython2')
 
-# naming conventions used in the file:
-# * vrange - version range, pair of max and min versions
-# * fn - file name (without path)
-# * fpath - file path
-
-
-### FILES ######################################################
-def fix_locations(package):
-    """Move files to the right location."""
-    dbg_package = package.endswith('-dbg')
-    interpreter = Interpreter('python-dbg' if dbg_package else 'python')
-    found_versions = {}
-    for version in SUPPORTED:
-        interpreter.version = version
-
-        dstdir = interpreter.sitedir(package)
-        for srcdir in interpreter.old_sitedirs(package):
-            if isdir(srcdir):
-                if version in found_versions:
-                    log.error('files for version %s '
-                              'found in two locations:\n %s\n %s',
-                              version, srcdir, found_versions[version])
-                    exit(2)
-                log.info('Python %s should install files in %s. '
-                         'Did you forget "--install-layout=deb"?',
-                         version, interpreter.sitedir())
-                if not isdir(dstdir):
-                    os.makedirs(dstdir)
-                # TODO: what about relative symlinks?
-                log.debug('moving files from %s to %s', srcdir, dstdir)
-                os.renames(srcdir, dstdir)
-                found_versions[version] = srcdir
-
-        # do the same with debug locations
-        dstdir = interpreter.sitedir(package, gdb=True)
-        for srcdir in interpreter.old_sitedirs(package, gdb=True):
-            if isdir(srcdir):
-                if not isdir(dstdir):
-                    os.makedirs(dstdir)
-                log.debug('moving files from %s to %s', srcdir, dstdir)
-                os.renames(srcdir, dstdir)
-
 
 ### SHARING FILES ##############################################
 def share(package, stats, options):
@@ -414,7 +373,7 @@ def scan(package, dname=None, options=None):
                     continue
 
             elif private_dir:
-                if exists(fpath):
+                if exists(fpath) and fext != 'so':
                     mode = os.stat(fpath)[ST_MODE]
                     if mode & S_IXUSR or mode & S_IXGRP or mode & S_IXOTH:
                         if (options.no_shebang_rewrite or
@@ -639,7 +598,7 @@ def main():
             except Exception as err:
                 log.error("%s.pyremove: %s", package, err)
                 exit(5)
-            fix_locations(package)
+            fix_locations(package, interpreter, SUPPORTED)
         stats = scan(package, private_dir, options)
         if not private_dir:
             share(package, stats, options)
diff --git a/dh_python3 b/dh_python3
index 2572ad3..9bea7de 100755
--- a/dh_python3
+++ b/dh_python3
@@ -25,9 +25,8 @@ import logging
 import os
 import re
 import sys
-from filecmp import cmp as cmpfile
 from optparse import OptionParser, SUPPRESS_HELP
-from os.path import isdir, islink, exists, join, split
+from os.path import islink, exists, join, split
 from shutil import rmtree, copy as fcopy
 from stat import ST_MODE, S_IXUSR, S_IXGRP, S_IXOTH
 sys.path.insert(1, '/usr/share/dh-python/')
@@ -36,6 +35,7 @@ from dhpython.depends import Dependencies
 from dhpython.interpreter import Interpreter, EXTFILE_RE
 from dhpython.version import supported, default, Version, VersionRange
 from dhpython.pydist import validate as validate_pydist
+from dhpython.fs import fix_locations
 from dhpython.tools import fix_shebang, clean_egg_name
 from dhpython.option import Option
 
@@ -48,72 +48,6 @@ DEFAULT = default('cpython3')
 SUPPORTED = supported('cpython3')
 
 
-### FILES ######################################################
-def fix_locations(package):
-    """Move files to the right location."""
-    dbg_package = package.endswith('-dbg')
-    interpreter = Interpreter('python-dbg' if dbg_package else 'python')
-    for version in SUPPORTED:
-        interpreter.version = version
-
-        dstdir = interpreter.sitedir(package)
-        for srcdir in interpreter.old_sitedirs(package):
-            if isdir(srcdir):
-                # TODO: what about relative symlinks?
-                log.debug('moving files from %s to %s', srcdir, dstdir)
-                share_files(srcdir, dstdir, package.endswith('-dbg'))
-                parent_dir = '/'.join(srcdir.split('/')[:-1])
-                if exists(parent_dir) and not os.listdir(parent_dir):
-                    os.rmdir(parent_dir)
-
-        # do the same with debug locations
-        dstdir = interpreter.sitedir(package, gdb=True)
-        for srcdir in interpreter.old_sitedirs(package, gdb=True):
-            if isdir(srcdir):
-                log.debug('moving files from %s to %s', srcdir, dstdir)
-                share_files(srcdir, dstdir, package.endswith('-dbg'))
-                parent_dir = '/'.join(srcdir.split('/')[:-1])
-                if exists(parent_dir) and not os.listdir(parent_dir):
-                    os.rmdir(parent_dir)
-
-
-def share_files(srcdir, dstdir, dbg_package=False):
-    """Try to move as many files from srcdir to dstdir as possible."""
-    for i in os.listdir(srcdir):
-        fpath1 = join(srcdir, i)
-        if i.rsplit('.', 1)[-1] == 'so':
-            # try to rename extension here as well (in :meth:`scan` info about
-            # Python version is gone)
-            public_dir = PUBLIC_DIR_RE.match(srcdir)
-            if public_dir:
-                ver = public_dir.groups()[0]
-                # note that if ver is empty, default Python version will be 
used
-                tmp = "python%s-dbg" if dbg_package else "python%s"
-                interpreter = Interpreter(tmp % ver)
-                fpath1_orig = fpath1
-                new_name = interpreter.check_extname(i)
-                if new_name:
-                    fpath1 = join(srcdir, new_name)
-                if exists(fpath1):
-                    log.warn('destination file exist, '
-                             'cannot rename %s to %s', fpath1_orig, fpath1)
-                else:
-                    log.warn('renaming %s to %s', fpath1_orig, fpath1)
-                    os.rename(fpath1_orig, fpath1)
-        fpath2 = join(dstdir, i)
-        if not exists(fpath2):
-            os.renames(fpath1, fpath2)
-            continue
-        if isdir(fpath1):
-            share_files(fpath1, fpath2, dbg_package)
-        elif cmpfile(fpath1, fpath2, shallow=False):
-            os.remove(fpath1)
-        # XXX: check symlinks
-
-    if exists(srcdir) and not os.listdir(srcdir):
-        os.rmdir(srcdir)
-
-
 ### PACKAGE DETAILS ############################################
 def scan(package, dname=None, options=None):
     """Gather statistics about Python files in given package."""
@@ -243,7 +177,7 @@ def scan(package, dname=None, options=None):
                             os.rename(fpath, new_fpath)
 
             elif private_dir:
-                if exists(fpath):
+                if exists(fpath) and fext != 'so':
                     mode = os.stat(fpath)[ST_MODE]
                     if mode & S_IXUSR or mode & S_IXGRP or mode & S_IXOTH:
                         if (options.no_shebang_rewrite or
@@ -422,7 +356,7 @@ def main():
             interpreter.debug = True
 
         if not private_dir:
-            fix_locations(package)
+            fix_locations(package, interpreter, SUPPORTED)
         stats = scan(package, private_dir, options)
 
         dependencies = Dependencies(package, 'cpython3')
diff --git a/dhpython/fs.py b/dhpython/fs.py
new file mode 100644
index 0000000..42e72c5
--- /dev/null
+++ b/dhpython/fs.py
@@ -0,0 +1,88 @@
+# Copyright © 2013 Piotr Ożarowski <pi...@debian.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# 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 logging
+from filecmp import cmp as cmpfile
+from os import listdir, remove, renames, rmdir
+from os.path import exists, isdir, join
+
+log = logging.getLogger(__name__)
+
+
+def fix_locations(package, interpreter, versions):
+    """Move files to the right location."""
+    for version in versions:
+        interpreter.version = version
+
+        dstdir = interpreter.sitedir(package)
+        for srcdir in interpreter.old_sitedirs(package):
+            if isdir(srcdir):
+                # TODO: what about relative symlinks?
+                log.debug('moving files from %s to %s', srcdir, dstdir)
+                share_files(srcdir, dstdir, interpreter)
+                parent_dir = '/'.join(srcdir.split('/')[:-1])
+                if exists(parent_dir) and not listdir(parent_dir):
+                    rmdir(parent_dir)
+
+        # do the same with debug locations
+        dstdir = interpreter.sitedir(package, gdb=True)
+        for srcdir in interpreter.old_sitedirs(package, gdb=True):
+            if isdir(srcdir):
+                log.debug('moving files from %s to %s', srcdir, dstdir)
+                share_files(srcdir, dstdir, interpreter)
+                parent_dir = '/'.join(srcdir.split('/')[:-1])
+                if exists(parent_dir) and not listdir(parent_dir):
+                    rmdir(parent_dir)
+
+
+def share_files(srcdir, dstdir, interpreter):
+    """Try to move as many files from srcdir to dstdir as possible."""
+    for i in listdir(srcdir):
+        fpath1 = join(srcdir, i)
+        if i.rsplit('.', 1)[-1] == 'so':
+            # try to rename extension here as well (in :meth:`scan` info about
+            # Python version is gone)
+            version = interpreter.parse_public_version(srcdir)
+            if version:
+                # note that if ver is empty, default Python version will be 
used
+                fpath1_orig = fpath1
+                new_name = interpreter.check_extname(i, version)
+                if new_name:
+                    fpath1 = join(srcdir, new_name)
+                if exists(fpath1):
+                    log.warn('destination file exist, '
+                             'cannot rename %s to %s', fpath1_orig, fpath1)
+                else:
+                    log.warn('renaming %s to %s', fpath1_orig, fpath1)
+                    renames(fpath1_orig, fpath1)
+        fpath2 = join(dstdir, i)
+        if not exists(fpath2):
+            renames(fpath1, fpath2)
+            continue
+        if isdir(fpath1):
+            share_files(fpath1, fpath2, interpreter)
+        elif cmpfile(fpath1, fpath2, shallow=False):
+            remove(fpath1)
+        # XXX: check symlinks
+
+    if exists(srcdir) and not listdir(srcdir):
+        rmdir(srcdir)
+
+

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/reproducible/dh-python.git

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to