[PATCH 1/4] Prepare for the new sources file format

Mathieu Bridon bochecha at fedoraproject.org
Fri Feb 6 10:39:24 UTC 2015


From: Mathieu Bridon <bochecha at daitauha.fr>

The current format for the 'sources file is as follows:

    $hash  $filename

We're eventually going to move to:

    $hashtype  $hash  $filename

This commit just prepares us for that, allowing to parse both formats.

If the 'sources' file doesn't contain the $hashtype, it is assumed to be
the one defined in the config file as lookasidehash.
---
This is just a new version of the previous 0001 patch, replacing the earlier
one.

It fixes an issue with the hashtype used by default when none was explicitly
specified in the 'sources' file.

 src/pyrpkg/__init__.py | 16 +++++++++++++++-
 src/pyrpkg/sources.py  |  9 +++++----
 test/test_sources.py   |  2 +-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 5c4dbc5..3a1874f 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -1568,7 +1568,21 @@ class Commands(object):
         # Default to putting the files where the module is
         if not outdir:
             outdir = self.path
-        for (csum, file) in self._read_sources():
+
+        for entry in self._read_sources():
+            if len(entry) == 2:
+                csum, file = entry
+
+                # We have to hardcode md5 here, because this is the historical
+                # default. We can't rely on self.lookasidehash (from the config
+                # file), because it represents the **current** default, which
+                # will eventually change, which would break older 'sources'
+                # files.
+                hashtype = 'md5'
+
+            else:
+                hashtype, csum, file = entry
+
             # See if we already have a valid copy downloaded
             outfile = os.path.join(outdir, file)
             if os.path.exists(outfile):
diff --git a/src/pyrpkg/sources.py b/src/pyrpkg/sources.py
index c4263ad..8d8b277 100644
--- a/src/pyrpkg/sources.py
+++ b/src/pyrpkg/sources.py
@@ -42,10 +42,11 @@ def _parse_line(line):
     stripped_line = line.strip()
     if not stripped_line:
         return []
-    entries = stripped_line.split('  ', 1)
-    if len(entries) != 2:
-        raise ValueError("Malformed line: %r." % line)
-    return entries
+    entries = stripped_line.split('  ')
+    if len(entries) in (2, 3):
+        return entries
+
+    raise ValueError("Malformed line: %r." % line)
 
 
 def _format_line(entry):
diff --git a/test/test_sources.py b/test/test_sources.py
index 997ab83..71b49fb 100644
--- a/test/test_sources.py
+++ b/test/test_sources.py
@@ -14,7 +14,7 @@ class formatLineTestCase(unittest.TestCase):
     def test_wrong_number_of_fields(self):
         WRONG_ENTRIES = [
             ('foo'),
-            ('foo', 'bar', 'foo'),
+            ('foo', 'bar', 'foo', 'bar'),
         ]
         for entry in WRONG_ENTRIES:
             self.assertRaises(ValueError, sources._format_line, entry)
-- 
2.1.0



More information about the buildsys mailing list