# Don't remove this, we re-export the exceptions to scripts which import us
from sqlalchemy.exc import *
+from sqlalchemy.orm.exc import NoResultFound
# Only import Config until Queue stuff is changed to store its config
# in the database
q = session.query(Architecture).filter_by(arch_string=architecture)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_architecture')
q = session.query(Archive).filter_by(archive_name=archive)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_archive')
q = session.query(DBBinary).filter_by(binary_id=id)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_binary_from_id')
q = session.query(Component).filter_by(component_name=component)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_component')
privatetrans = True
q = session.query(ContentFilename).filter_by(filename=filename)
- if q.count() < 1:
+
+ try:
+ ret = q.one().cafilename_id
+ except NoResultFound:
cf = ContentFilename()
cf.filename = filename
session.add(cf)
else:
session.flush()
ret = cf.cafilename_id
- else:
- ret = q.one().cafilename_id
if privatetrans:
session.close()
privatetrans = True
q = session.query(ContentFilepath).filter_by(filepath=filepath)
- if q.count() < 1:
+
+ try:
+ ret = q.one().cafilepath_id
+ except NoResultFound:
cf = ContentFilepath()
cf.filepath = filepath
session.add(cf)
else:
session.flush()
ret = cf.cafilepath_id
- else:
- ret = q.one().cafilepath_id
if privatetrans:
session.close()
q = session.query(PoolFile).filter_by(file_id=file_id)
- if q.count() > 0:
- ret = q.one()
- else:
- ret = None
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_poolfile_by_id')
privatetrans = True
q = session.query(Fingerprint).filter_by(fingerprint=fpr)
- if q.count() < 1:
+
+ try:
+ ret = q.one()
+ except NoResultFound:
fingerprint = Fingerprint()
fingerprint.fingerprint = fpr
session.add(fingerprint)
else:
session.flush()
ret = fingerprint
- else:
- ret = q.one()
if privatetrans:
session.close()
if component is not None:
q = q.join(Component).filter_by(component_name=component)
- if q.count() < 1:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_location')
privatetrans = True
q = session.query(Maintainer).filter_by(name=name)
- if q.count() < 1:
+ try:
+ ret = q.one()
+ except NoResultFound:
maintainer = Maintainer()
maintainer.name = name
session.add(maintainer)
else:
session.flush()
ret = maintainer
- else:
- ret = q.one()
if privatetrans:
session.close()
q = session.query(OverrideType).filter_by(overridetype=override_type)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
return ret
q = session.query(Priority).filter_by(priority=priority)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_priority')
"""
q = session.query(Queue).filter_by(queue_name=queuename)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_queue')
q = session.query(QueueBuild).filter_by(filename=filename)
q = q.join(Suite).filter_by(suite_name=suite)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_queue_build')
"""
q = session.query(Section).filter_by(section=section)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_section')
q = q.join('source').filter_by(source=source)
q = q.join('suite').filter_by(suite_name=suite)
- if q.count() == 0:
- ret = None
- else:
- # ???: Maybe we should just return the SrcAssociation object instead
- ret = q.one().source
-
- return ret
+ try:
+ return q.one().source
+ except NoResultFound:
+ return None
__all__.append('get_source_in_suite')
q = q.join(Architecture).filter_by(arch_string=architecture)
q = q.join(Suite).filter_by(suite_name=suite)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_suite_architecture')
q = session.query(Suite).filter_by(suite_name=suite)
- if q.count() == 0:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_suite')
q = session.query(Uid).filter_by(uid=uidname)
- if q.count() < 1:
+ try:
+ ret = q.one()
+ except NoResultFound:
uid = Uid()
uid.uid = uidname
session.add(uid)
else:
session.flush()
ret = uid
- else:
- ret = q.one()
if privatetrans:
session.close()
q = session.query(Uid)
q = q.join(Fingerprint).filter_by(fingerprint=fpr)
- if q.count() != 1:
- ret = None
- else:
- ret = q.one()
-
- return ret
+ try:
+ return q.one()
+ except NoResultFound:
+ return None
__all__.append('get_uid_from_fingerprint')