def resolve_build(buildstring):
    if buildstring is None:
        return
    mo = PROJECT_RE.search(buildstring)
    if mo:
        try:
            pname, major, minor, sub, build = mo.groups()
            major = int(major); minor = int(minor); sub = int(sub); build = int(build)
        except ValueError:
            return None
        try:
            proj = dbsession.query(models.Project).filter(models.Project.name==pname).one()
        except NoResultFound:
            return None
        try:
            projectversion = dbsession.query(models.ProjectVersion).filter(and_(
                    models.ProjectVersion.project==proj,
                    models.ProjectVersion.valid==True,
                    models.ProjectVersion.major==major,
                    models.ProjectVersion.minor==minor,
                    models.ProjectVersion.subminor==sub,
                    models.ProjectVersion.build==build)
                    ).one()
        except NoResultFound:
            projectversion = models.create(
                    models.ProjectVersion, project=proj, valid=True,
                    major=major, minor=minor, subminor=sub, build=build)
            dbsession.add(projectversion)
        return projectversion
    else:
        return None
dataset/ETHPy150Open kdart/pycopia/storage/pycopia/db/webhelpers.py/resolve_build/original