X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fsrcformats.py;h=7d7dd940e3837c1c5c99a7f8708ae3663ae53d44;hb=4e9d67806b0cf200b68f2a199dd0fdf183b4c6de;hp=0a74c19262f99fe91e6476487cabd39bf8f22faa;hpb=32dc9d52c53207a6524ecf63ac7866435ae40374;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)