def __init__(self, **kwargs): self.db = None try: self.dbfact = DatabaseFactory(**kwargs) self.database = self.dbfact.get_database() self.db = db self.db.initialize(self.database) self.db.connect() except (AttributeError, PeeweeException) as err: fatal("Can't create database object: %s" % str(err))
def check_table_exists(cls, table): """Check a table exists in the database Args: table (:obj:`str`): Database `table` name to check. Returns: True Raises: SystemExit: if `table` does not exist """ if not table.table_exists(): fatal("Table %s does not exist" % (str(table.get_table_name()))) return True
def check_list_ids(ids): """Check the list of ids is not longer that MAX_LIST Args: ids (:obj:`list`): List of bind values Returns: True Raises: SystemExit: If `len` of the list of greater than `MAX_LIST`. """ if len(ids) > TaxaDB.MAX_LIST: fatal("Too many accession entries to request (%d), max %d" % (len(ids), TaxaDB.MAX_LIST)) return True
def set_accession_file(self, acc_file): """Set the accession file to use Args: acc_file (:obj:`str`): File to be set Returns: True Raises: SystemExit: If `acc_file` is None or not a file (`check_file`) """ if acc_file is None: fatal("Please provide an accession file to set") self.check_file(acc_file) self.acc_file = acc_file return True
def set_names_file(self, names_file): """Set names_file Set the accession file to use Args: names_file (:obj:`str`): Nodes file to be set Returns: True Raises: SystemExit: If `names_file` is None or not a file (`check_file`) """ if names_file is None: fatal("Please provide an names file to set") self.check_file(names_file) self.names_file = names_file return True
def check_file(element): """Make some check on a file This method is used to check an `element` is a real file. Args: element (:obj:`type`): File to check Returns: True Raises: SystemExit: if `element` file does not exist SystemExit: if `element` is not a file """ if element is None: fatal("Please provide an input file to check") if not os.path.exists(element): fatal("File %s does not exist" % str(element)) if not os.path.isfile(element): fatal("%s is not a file" % str(element)) return True
def test_fatal_throws(self): """Check fatal throws SystemExit""" with self.assertRaises(SystemExit): fatal("failed")