]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/srcformats.py
Add get_format_from_string utility method
[dak.git] / daklib / srcformats.py
index bcb2e2bbae4e373df2e0c2cb1a130a58d15cfa1e..ade3c45388b6a32d2e27c27d15a4a33a11e98b5a 100644 (file)
@@ -5,6 +5,19 @@ from dak_exceptions import UnknownFormatError
 
 srcformats = []
 
+def get_format_from_string(txt):
+    """
+    Returns the SourceFormat class that corresponds to the specified .changes
+    Format value. If the string does not match any class, UnknownFormatError
+    is raised.
+    """
+
+    for format in srcformats:
+        if format.re_format.match(txt):
+            return format
+
+    raise UnknownFormatError, "Unknown format %r" % txt
+
 def parse_format(txt):
     """
     Parse a .changes Format string into a tuple representation for easy