Beispiel #1
0
 def save(self, data=True):
     assert self.id
     if data:
         self.write_data()
     self.modified = now()
     self.db.execute('UPDATE task SET title=?,status=?,pid=?,'
                     ' size=?,cpu_time=?,modified=? WHERE id=?',
                     self.title,
                     self.status,
                     self.pid,
                     self.size,
                     self.cpu_time,
                     self.modified,
                     self.id)
     self.db.commit()
Beispiel #2
0
 def create(self, account):
     assert self.id is None
     assert account
     self.iui = uuid.uuid4().hex
     self._status = configuration.CREATED
     self.account = account
     self.write_data()
     self.modified = now()
     cursor = self.db.execute('INSERT INTO task(iui,tool,title,status,'
                              ' pid,size,cpu_time,account,modified)'
                              ' VALUES(?,?,?,?,?,?,?,?,?)',
                              self.iui,
                              self.tool,
                              self.title,
                              self.status,
                              self.pid,
                              self.size,
                              self.cpu_time,
                              self.account,
                              self.modified)
     self.id = cursor.lastrowid
     self.db.commit()
Beispiel #3
0
 def __init__(self, db, doc=None, values=dict(), force=False):
     self.db = db
     self.doc = doc or dict()
     if self.doc.has_key('_id'):
         if values:
             try:
                 rev = values.get('_rev', values['rev'])
                 if rev != self.doc['_rev']:
                     raise ValueError('document revision mismatch;'
                                      ' document has been edited'
                                      ' by someone else')
             except KeyError:
                 raise ValueError('document revision missing')
         elif force:
             try:
                 doc['_rev'] = db.revisions(doc['_id']).next().rev
             except StopIteration:
                 pass
     else:
         self.doc['_id'] = uuid.uuid4().hex
         if self.entitytype and not self.doc.has_key('entitytype'):
             self.doc['entitytype'] = self.entitytype
             self.doc['created'] = now()
Beispiel #4
0
 def __exit__(self, type, value, tb):
     if type is not None: return False # No exceptions handled here
     if self.entitytype:
         self.doc['modified'] = now()
     self.db.save(self.doc)
Beispiel #5
0
            pmids = set()
            for year in years:
                search = pubmed.Search()
                for affiliation in affiliations:
                    pmids.update(search(author=pi,
                                        affiliation=affiliation,
                                        published=year))
            record['count'] = len(pmids)
            record['added'] = []
            for pmid in pmids:
                if add_publication(db, pmid):
                    record['added'].append(pmid)
            doc['pis'].append(record)
    except Exception, message:
        doc['error'] = traceback.format_exc(limit=20)
    doc['created'] = now()
    db.save(doc)

def get_pis_affiliations(db, explicit=[]):
    """Get the list of (PI name, affiliations).
    If any explicit names given (e.g. from command-line arguments),
    then pick only those from the db, else get all.
    """
    pis = db['pilist']['pis']
    names = set([n.lower().replace('_', ' ') for n in explicit])
    if names:
        for i, pi in enumerate(pis):
            name = pi.get('normalized_name', pi['name'])
            if name.lower() not in names:
                pis[i] = None
        pis = [pi for pi in pis if pi is not None]