From: Mathieu Bridon <[email protected]>

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.
---
 src/pyrpkg/__init__.py | 10 +++++++++-
 src/pyrpkg/sources.py  |  9 +++++----
 test/test_sources.py   |  2 +-
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 5c4dbc5..f9606fe 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -1568,7 +1568,15 @@ 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
+                hashtype = self.lookasidehash
+
+            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

--
buildsys mailing list
[email protected]
https://admin.fedoraproject.org/mailman/listinfo/buildsys

Reply via email to