def autodetect(): """Probe to find all connected DMCCs. By setting the verify flag, the I2C address associated with each possible BBB cape is probed at a relevant register. Those that respond accordingly will be added to the dictionary. """ capes = {} logger = lib.get_logger() for i in range(4): try: cape = DMCC(i, verify=True) capes[i] = cape except RuntimeError: logger.debug('No DMCC at index {} (bad response)'.format(i)) continue except IOError: logger.debug('No DMCC at index {} (no response)'.format(i)) continue return capes
def __init__(self, id, verify=False, bus=1, logger=None): """Create I2C interface, optionally verify DMCC :param id: The cape index or I2C address of the DMCC to initialzie :param verify: Perform an active test to verify the presence of a DMCC """ if logger == None: self.logger = lib.get_logger() else: self.logger = logger if not (0 <= id <= 3) and not (BASE_ADDR <= id <= BASE_ADDR+3): err_msg = ("DMCC id can either be an index (0-3) " + "or an address ({}-{})".format(BASE_ADDR, BASE_ADDR+3)) self.logger.error(err_msg) raise ValueError(err_msg) if (id <= 3): self.cape_num = id else: self.cape_num = id - BASE_ADDR self.i2c = I2CDevice(bus, address=self.address, config='dmcc_i2c.yaml') self.logger.debug("Verifying {:#04x}".format(self.address)) if verify and not self.verify(): msg = "Failed to verify DMCC at {:#04x}".format(self.address) self.logger.warning(msg) raise RuntimeError() self.motors = {} for i in [1,2]: self.motors[i] = Motor(self.i2c, i) self.logger.debug("DMCC {} ({:#04x}) initialized".format( self.cape_num, self.address))
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--dataset', choices=['mnist', 'fashionmnist'], default='mnist') parser.add_argument('--iterations', type=int, default=50000) parser.add_argument('--batch-size', type=int, default=256) parser.add_argument('--val-interval', type=int, default=5000) parser.add_argument('--log-interval', type=int, default=1000) parser.add_argument('--seed', type=int, default=666) parser.add_argument('--test', action='store_true') parser.add_argument('--workdir', required=True) FLAGS = parser.parse_args() wdir = lib.create_unique_dir(FLAGS.workdir) os.chdir(wdir) logger = lib.get_logger() logger.info(wdir) logger.info(FLAGS) config = tf.ConfigProto() config.gpu_options.allow_growth = True config.allow_soft_placement = True with tf.Session(config=config) as sess: tf.set_random_seed(FLAGS.seed) # Global variables global_step_op = tf.train.get_or_create_global_step() is_training = tf.placeholder(tf.bool, shape=[], name='is_training') # Dataset loading and switching logic if FLAGS.dataset == 'mnist':
def __init__(self): """ Get Logger Object """ self.logger = lib.get_logger() self.arm_state = "retracted" self.logger.debug("Arm built")
def __init__(self): self.logger = get_logger(__name__) self.dynamodb = Dynamodb() self.converter = Converter() self.validation = Validation() self.slack = Slack()
def __init__(self): self.logger = get_logger(__name__)
def __init__(self): self.logger = get_logger(__name__) self.slacker = Slacker(settings.API_TOKEN)
def __init__(self): self.logger = get_logger(__name__) self.dynamodb = Dynamodb() self.converter = Converter() self.default_record_num = 20
def __init__(self): self.logger = get_logger(__name__) self.amount = Amount() self.converter = Converter() self.slack = Slack()
def __init__(self): self.logger = get_logger(__name__) self.botname = "bookbot"
def main(): global LOGGER global CONFIG CONFIG = lib.get_config() LOGGER = lib.get_logger(PROCESS) LOGGER.warn("=== Starting {}".format(PROCESS)) # DB connection details db_host = CONFIG["db"]["address"] + ":" + CONFIG["db"]["port"] db_user = CONFIG["db"]["user"] db_password = CONFIG["db"]["password"] db_name = CONFIG["db"]["db_name"] mysqlcontsraints = MysqlConstants(db_host, db_user, db_password, db_name) # Connect to DB database.db = database_details(MYSQL_CONSTANTS=mysqlcontsraints) database.db.initialize() wallet_dir = CONFIG[PROCESS]["wallet_dir"] minimum_payout = int(CONFIG[PROCESS]["minimum_payout"]) os.chdir(wallet_dir) utxos = Pool_utxo.getPayable(minimum_payout) database.db.getSession().commit() # XXX TODO: Use the current balance, timestamp, the last_attempt timestamp, last_payout, and failed_attempts # XXX TODO: to filter and sort by order we want to make payment attempts for utxo in utxos: try: LOGGER.warn("Trying to pay: {} {} {}".format( utxo.id, utxo.address, utxo.amount)) # Lock just this current record for update locked_utxo = Pool_utxo.get_locked_by_id(utxo.id) # Save and Zero the balance original_balance = locked_utxo.amount locked_utxo.amount = 0 # Savepoint changes - if we crash after sending coins but before commit we roll back to here. # The pool audit service finds lost payouts and restores user balance database.db.getSession().begin_nested() # Attempt to make the payment timestamp = "{:%B %d, %Y %H:%M:%S.%f}".format(datetime.now()) status = makePayout(locked_utxo.address, original_balance) LOGGER.warn("Payout status: {}".format(status)) if status == 0: LOGGER.warn("Made payout for {} {} {}".format( locked_utxo.id, locked_utxo.address, original_balance)) # Update timestamp of last payout, number of failed payout attempts locked_utxo.amount = 0 locked_utxo.failure_count = 0 locked_utxo.last_try = timestamp locked_utxo.last_success = timestamp # Commit changes database.db.getSession().commit() else: LOGGER.error("Failed to make payout: {} {} {}".format( locked_utxo.id, locked_utxo.address, original_balance)) # Restore the users balance locked_utxo.amount = original_balance # Update number of failed payout attempts if locked_utxo.failure_count is None: locked_utxo.failure_count = 0 locked_utxo.failure_count += 1 locked_utxo.last_try = timestamp # Commit changes database.db.getSession().commit() database.db.getSession().commit() except Exception as e: LOGGER.error("Failed to process utxo: {} because {}".format( utxo.id, str(e))) database.db.getSession().rollback() sys.exit(1) LOGGER.warn("=== Completed {}".format(PROCESS))
def __init__(self): self.logger = get_logger(__name__) self.dynamodb = Dynamodb() self.converter = Converter() self.list_history = ListHistory()
def test_type(self): """Test the type of the logger object""" assert type(lib.get_logger()) is logging.Logger