Exemplo n.º 1
0
 def execute(self, args):
     """Remove specified elements."""
     db = MessDB()
     cur = db.cursor()
     for row in args.inchikeys:
         inchikey = row.split()[0].strip()
         try:
             inchikey_dir = get_inchikey_dir(inchikey)
             shutil.rmtree(inchikey_dir)
             self.log_all.info('%s dir removed', inchikey)
         except OSError:
             self.log_console.info('%s did not have a directory', inchikey)
         try:
             parent = os.path.relpath(os.path.join(inchikey_dir, '../'))
             os.removedirs(parent)
         except OSError:
             pass
         records = 0
         query = 'DELETE from molecule WHERE inchikey=?'
         cur.execute(query, (inchikey,))
         records += cur.rowcount
         query = 'DELETE from molecule_synonym WHERE inchikey=?'
         cur.execute(query, (inchikey,))
         records += cur.rowcount
         query = 'DELETE from molecule_source WHERE inchikey=?'
         cur.execute(query, (inchikey,))
         records += cur.rowcount
         query = ('DELETE from molecule_state_method_property '
                  'WHERE inchikey=?')
         cur.execute(query, (inchikey,))
         records += cur.rowcount
         db.commit()
         self.log_all.info('%i %s records removed from db',
                           records, inchikey)