one more step
authorTomasz Buchert <tomasz@debian.org>
Sat, 29 Aug 2015 21:05:16 +0000 (23:05 +0200)
committerTomasz Buchert <tomasz@debian.org>
Sat, 29 Aug 2015 21:05:16 +0000 (23:05 +0200)
debocker
src/debocker/debian.py [new file with mode: 0644]

index 8544960..dc601c8 100755 (executable)
--- a/debocker
+++ b/debocker
@@ -6,8 +6,7 @@ import re
 import os
 from os.path import isdir, join, isfile, abspath, dirname, \
     realpath, splitext, relpath
-from subprocess import check_call, check_output, CalledProcessError, DEVNULL
-from shutil import which, copytree, copyfile
+from shutil import which
 from shlex import quote as shell_quote
 from collections import OrderedDict
 from string import Template
@@ -20,6 +19,7 @@ sys.path.append(join(HERE, 'src'))
 from debocker.utils import cached_constant, cached_property, tmppath, \
     calculate_md5_and_size, log_check_call, log_check_output
 from debocker.log import log, LOW, fail
+from debocker.debian import extract_pristine_tar
 
 __version__ = "0.2"
 
@@ -44,36 +44,6 @@ def assert_docker():
     if which('docker') is None:
         fail('docker is not available')
 
-def extract_pristine_tar(path, candidates):
-    if which('pristine-tar') is None:
-        log('No pristine-tar available.', LOW)
-        return None
-    try:
-        tars = log_check_output([ 'pristine-tar', 'list' ], cwd = path)
-    except CalledProcessError:
-        log('Error in pristine-tar - giving up.', LOW)
-        return None
-    # let's hope that no non-utf8 files are stored
-    thelist = tars.decode('utf-8').split()
-    log('Pristine tarballs: {}'.format(thelist), LOW)
-    matches = list(set(thelist) & set(candidates))
-    if len(matches) > 0:
-        m = matches[0]
-        log("Found a match: '{}'.".format(m), LOW)
-        log_check_call([ 'pristine-tar', 'checkout', m ],
-                       cwd = path, stderr = DEVNULL)
-        try:
-            src = join(path, m)
-            dst = tmppath(m)
-            copyfile(src, dst)
-            log("Tarball extracted to '{}'.".format(dst), LOW)
-        finally:
-            os.unlink(src)
-        return dst
-    else:
-        log('No matching pristine tar found.', LOW)
-        return None
-
 class Package:
 
     def __init__(self, path):
diff --git a/src/debocker/debian.py b/src/debocker/debian.py
new file mode 100644 (file)
index 0000000..2be25f1
--- /dev/null
@@ -0,0 +1,38 @@
+# debian-related functionality
+
+import os
+from shutil import which, copyfile
+from .log import log, LOW
+from .utils import log_check_call, log_check_output, \
+    tmppath, join
+from subprocess import CalledProcessError, DEVNULL
+
+def extract_pristine_tar(path, candidates):
+    if which('pristine-tar') is None:
+        log('No pristine-tar available.', LOW)
+        return None
+    try:
+        tars = log_check_output([ 'pristine-tar', 'list' ], cwd = path)
+    except CalledProcessError:
+        log('Error in pristine-tar - giving up.', LOW)
+        return None
+    # let's hope that no non-utf8 files are stored
+    thelist = tars.decode('utf-8').split()
+    log('Pristine tarballs: {}'.format(thelist), LOW)
+    matches = list(set(thelist) & set(candidates))
+    if len(matches) > 0:
+        m = matches[0]
+        log("Found a match: '{}'.".format(m), LOW)
+        log_check_call([ 'pristine-tar', 'checkout', m ],
+                       cwd = path, stderr = DEVNULL)
+        try:
+            src = join(path, m)
+            dst = tmppath(m)
+            copyfile(src, dst)
+            log("Tarball extracted to '{}'.".format(dst), LOW)
+        finally:
+            os.unlink(src)
+        return dst
+    else:
+        log('No matching pristine tar found.', LOW)
+        return None