Skip to content

Instantly share code, notes, and snippets.

@jkinred
Created February 12, 2013 21:37
Show Gist options
  • Save jkinred/4773609 to your computer and use it in GitHub Desktop.
Save jkinred/4773609 to your computer and use it in GitHub Desktop.
class BuildResultKey(object):
def __init__(self, project_key, plan_key, job_key, build_number=None):
self.project_key = project_key
self.plan_key = plan_key
self.job_key = job_key
self.build_number = build_number
def __str__(self):
return "%s-%s-%s" % (self.project_key, self.plan_key, self.job_key)
@classmethod
def from_string(cls, strng):
"""Instantiates a build key object from a string"""
pattern = r"([A-Z0-9]+)-([A-Z0-9]+)-([A-Z0-9]+)-*(\d+)*"
m = re.match(pattern, strng)
if m is not None:
return cls(m.group(1), m.group(2), m.group(3), m.group(4))
else:
raise ValueError("Cannot parse build key from %s" % strng)
@classmethod
def from_directory(cls, directory):
"""Instantiates a build key from a directory"""
if os.path.isdir(directory) is True:
newcls = cls.from_string(os.path.basename(directory))
newcls.build_number = get_build_number_from_file(
os.path.join(directory, "build-number.txt"))
return newcls
else:
raise ValueError("%s is not a directory" % directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment