示例#1
0
def add_new_file_to_database(session, filedata, commit=False):
    key = filedata["key"]
    try:
        keyobj = session.query(AnnexKey).filter_by(name=key).one()
    except NoResultFound:
        keyobj = AnnexKey()
        keyobj.name = key
        session.add(keyobj)
        keyobj = session.merge(keyobj)
    dbobj = AnnexFile()
    _add_new_annexfile_attributes(keyobj.id, dbobj, filedata)
    session.add(dbobj)
示例#2
0
def initialize_annex_keys(session, find_output_filename):
    filename = find_output_filename
    keys = set()
    with file(filename) as infile:
        while True:
            try:
                line = infile.next()
            except StopIteration:
                break
            data = gitannex.parse_json_line(line, convert_to_unicode=True, verbose_warning=True)
            keys.add(data["key"])
    for k in keys:
        dbk = AnnexKey()
        dbk.name = k
        session.add(dbk)
    print "added %d keys" % len(keys)
    print datetime.now()
    session.commit()
    print "successful commit", datetime.now()
示例#3
0
 def add_key(self, key):
     dbkey = AnnexKey()
     dbkey.name = key
     self.session.add(dbkey)
     return self.session.merge(dbkey)