[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Support dpkg's new tupletable



---
 daklib/architecture.py | 76 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 29 deletions(-)

diff --git a/daklib/architecture.py b/daklib/architecture.py
index 8354de0..cab454d 100644
--- a/daklib/architecture.py
+++ b/daklib/architecture.py
@@ -18,6 +18,8 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import errno
+
 def _load_table(path):
     table = []
     with open(path, 'r') as fh:
@@ -34,66 +36,82 @@ def _cputable():
         _cached_cputable = _load_table('/usr/share/dpkg/cputable')
     return _cached_cputable
 
-_cached_arch2triplet = None
-_cached_triplet2arch = None
-def _triplettable():
-    global _cached_arch2triplet, _cached_triplet2arch
-    if _cached_arch2triplet is None or _cached_triplet2arch is None:
-        table = _load_table('/usr/share/dpkg/triplettable')
-        arch2triplet = {}
-        triplet2arch = {}
+_cached_arch2tuple = None
+_cached_tuple2arch = None
+def _tupletable():
+    global _cached_arch2tuple, _cached_tuple2arch
+    if _cached_arch2tuple is None or _cached_tuple2arch is None:
+        try:
+            tripletable = False
+            table = _load_table('/usr/share/dpkg/tupletable')
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                raise
+            tripletable = True
+            table = _load_table('/usr/share/dpkg/tripletable')
+
+        arch2tuple = {}
+        tuple2arch = {}
+
+        def add_tuple(tuple, arch):
+            if tripletable:
+                tuple = "base-{}".format(tuple)
+            arch2tuple[arch] = tuple
+            tuple2arch[tuple] = arch
+
         for row in table:
             if '<cpu>' in row[0] or '<cpu>' in row[1]:
                 for cpu in _cputable():
                     replaced_row = [ column.replace('<cpu>', cpu[0]) for column in row ]
-                    arch2triplet[replaced_row[1]] = replaced_row[0]
-                    triplet2arch[replaced_row[0]] = replaced_row[1]
+                    add_tuple(replaced_row[0], replaced_row[1])
             else:
-                arch2triplet[row[1]] = row[0]
-                triplet2arch[row[0]] = row[1]
-        _cached_arch2triplet = arch2triplet
-        _cached_triplet2arch = triplet2arch
-    return _cached_triplet2arch, _cached_arch2triplet
+                add_tuple(row[0], row[1])
+
+        _cached_arch2tuple = arch2tuple
+        _cached_tuple2arch = tuple2arch
+    return _cached_tuple2arch, _cached_arch2tuple
 
 class InvalidArchitecture(Exception):
     pass
 
-def Debian_arch_to_Debian_triplet(arch):
+def Debian_arch_to_Debian_tuple(arch):
     parts = arch.split('-')
 
     # Handle architecture wildcards
     if 'any' in parts:
-        if len(parts) == 3:
+        if len(parts) == 4:
             return parts
+        elif len(parts) == 3:
+            return 'any', parts[0], parts[1], parts[2]
         elif len(parts) == 2:
-            return 'any', parts[0], parts[1]
+            return 'any', 'any', parts[0], parts[1]
         else:
-            return 'any', 'any', 'any'
+            return 'any', 'any', 'any', 'any'
 
     if len(parts) == 2 and parts[0] == 'linux':
         arch = parts[1]
 
-    triplet = _triplettable()[1].get(arch, None)
-    if triplet is None:
+    tuple = _tupletable()[1].get(arch, None)
+    if tuple is None:
         return None
-    return triplet.split('-', 2)
+    return tuple.split('-', 3)
 
 def match_architecture(arch, wildcard):
-    # 'all' has no valid triplet
+    # 'all' has no valid tuple
     if arch == 'all' or wildcard == 'all':
         return arch == wildcard
     if wildcard is 'any' or arch == wildcard:
         return True
 
-    triplet_arch = Debian_arch_to_Debian_triplet(arch)
-    triplet_wildcard = Debian_arch_to_Debian_triplet(wildcard)
+    tuple_arch = Debian_arch_to_Debian_tuple(arch)
+    tuple_wildcard = Debian_arch_to_Debian_tuple(wildcard)
 
-    if triplet_arch is None or len(triplet_arch) != 3:
+    if tuple_arch is None or len(tuple_arch) != 4:
         raise InvalidArchitecture('{0} is not a valid architecture name'.format(arch))
-    if triplet_wildcard is None or len(triplet_wildcard) != 3:
+    if tuple_wildcard is None or len(tuple_wildcard) != 4:
         raise InvalidArchitecture('{0} is not a valid architecture name or wildcard'.format(wildcard))
 
-    for i in range(0,3):
-        if triplet_arch[i] != triplet_wildcard[i] and triplet_wildcard[i] != 'any':
+    for i in range(0,4):
+        if tuple_arch[i] != tuple_wildcard[i] and tuple_wildcard[i] != 'any':
             return False
     return True
-- 
2.1.4


Reply to: