X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fsrcformats.py;h=7d7dd940e3837c1c5c99a7f8708ae3663ae53d44;hb=d0779ef69d429a210405002f252067806ddfa6f2;hp=0a74c19262f99fe91e6476487cabd39bf8f22faa;hpb=3a044cf559c390a0a4dc0658ec565b6a327f136a;p=dak.git diff --git a/daklib/srcformats.py b/daklib/srcformats.py index 0a74c192..7d7dd940 100644 --- a/daklib/srcformats.py +++ b/daklib/srcformats.py @@ -1,7 +1,22 @@ import re +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 + class SourceFormat(type): def __new__(cls, name, bases, attrs): klass = super(SourceFormat, cls).__new__(cls, name, bases, attrs)