session.add(cf)
if privatetrans:
session.commit()
+ session.close()
+ else:
+ session.flush()
return cf.cafilename_id
else:
return q.one().cafilename_id
__all__.append('ContentFilepath')
-def get_or_set_contents_path_id(filepath, session):
+def get_or_set_contents_path_id(filepath, session=None):
"""
Returns database id for given path.
session.add(cf)
if privatetrans:
session.commit()
+ session.close()
+ else:
+ session.flush()
return cf.cafilepath_id
else:
return q.one().cafilepath_id
privatetrans = True
try:
+ # Insert paths
+ pathcache = {}
for fullpath in fullpaths:
+ # Get the necessary IDs ...
(path, file) = os.path.split(fullpath)
- # Get the necessary IDs ...
+ filepath_id = get_or_set_contents_path_id(path, session)
+ filename_id = get_or_set_contents_file_id(file, session)
+
+ pathcache[fullpath] = (filepath_id, filename_id)
+
+ for fullpath, dat in pathcache.items():
ca = ContentAssociation()
ca.binary_id = binary_id
- ca.filename_id = get_or_set_contents_file_id(file)
- ca.filepath_id = get_or_set_contents_path_id(path)
+ ca.filepath_id = dat[0]
+ ca.filename_id = dat[1]
session.add(ca)
# Only commit if we set up the session ourself
if privatetrans:
session.commit()
+ session.close()
+ else:
+ session.flush()
return True
+
except:
traceback.print_exc()
# Only rollback if we set up the session ourself
if privatetrans:
session.rollback()
+ session.close()
return False
q.delete()
# Insert paths
+ pathcache = {}
for fullpath in fullpaths:
(path, file) = os.path.split(fullpath)
if path.startswith( "./" ):
path = path[2:]
+ filepath_id = get_or_set_contents_path_id(path, session)
+ filename_id = get_or_set_contents_file_id(file, session)
+
+ pathcache[fullpath] = (filepath_id, filename_id)
+
+ for fullpath, dat in pathcache.items():
pca = PendingContentAssociation()
pca.package = package['Package']
pca.version = package['Version']
- pca.filename_id = get_or_set_contents_file_id(file, session)
- pca.filepath_id = get_or_set_contents_path_id(path, session)
+ pca.filepath_id = dat[0]
+ pca.filename_id = dat[1]
pca.architecture = arch_id
session.add(pca)
# Only commit if we set up the session ourself
if privatetrans:
session.commit()
+ else:
+ session.flush()
return True
except:
__all__.append('get_priority')
+def get_priorities(session=None):
+ """
+ Returns dictionary of priority names -> id mappings
+
+ @type session: Session
+ @param session: Optional SQL session object (a temporary one will be
+ generated if not supplied)
+
+ @rtype: dictionary
+ @return: dictionary of priority names -> id mappings
+ """
+ if session is None:
+ session = DBConn().session()
+
+ ret = {}
+ q = session.query(Priority)
+ for x in q.all():
+ ret[x.priority] = x.priority_id
+
+ return ret
+
+__all__.append('get_priorities')
+
################################################################################
class Queue(object):
dest = os.path.join(dest_dir, file_entry)
# TODO: Move into database as above
- if Cnf.FindB("Dinstall::SecurityQueueBuild"):
+ if conf.FindB("Dinstall::SecurityQueueBuild"):
# Copy it since the original won't be readable by www-data
utils.copy(src, dest)
else:
__all__.append('get_section')
+def get_sections(session=None):
+ """
+ Returns dictionary of section names -> id mappings
+
+ @type session: Session
+ @param session: Optional SQL session object (a temporary one will be
+ generated if not supplied)
+
+ @rtype: dictionary
+ @return: dictionary of section names -> id mappings
+ """
+ if session is None:
+ session = DBConn().session()
+
+ ret = {}
+ q = session.query(Section)
+ for x in q.all():
+ ret[x.section] = x.section_id
+
+ return ret
+
+__all__.append('get_sections')
+
################################################################################
class DBSource(object):