def __init__(self, http_port=9999): conf = load() nodes = conf['nodes'] i = 0 while (i < len(nodes)) and (conf[nodes[i]]['ip'] != get_ip_by_if( conf[nodes[i]]['ifcmd'])): i = i + 1 self.ip, self.incoming_path, self.backup_path, self.storage_path = None, None, None, None if i < len(nodes): node = conf[nodes[i]] self.ip = node['ip'] self.incoming_path = node['root'] + os.sep + node['incoming_path'] self.backup_path = node['root'] + os.sep + node['backup_path'] self.storage_path = node['root'] + os.sep + node['storage_path']
def setUp(self): """ Set up the database with some orders ready for a credit :return: """ # Build the tests Logger self.log = logging.Logger("Tests") stream = logging.StreamHandler() formatter = logging.Formatter(fmt="%(message)s") stream.setFormatter(formatter) self.log.addHandler(stream) self.log.debug("TestCredits testcase") self.log.debug("running setUp") # build the database if it doesn't exist database.build(self.log) # set us up a bottle application with correct config self.app = bottle.Bottle() self.app.config.load_config("../pool_config") load_config.load(self.app, "exchange_config") # clear any existing orders in the database conn = sqlite3.connect("pool.db") c = conn.cursor() c.execute("DELETE FROM orders") c.execute("DELETE FROM credits") conn.commit() # create test data self.test_data = { "tier_1": { "TEST_USER_1": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_2": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_3": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_4": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, }, "tier_2": { "TEST_USER_1": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_2": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_3": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, "TEST_USER_4": {"bid": random.randint(0, 1000), "ask": random.randint(0, 1000)}, }, } # add some orders to the database for test_data for tier in self.test_data: for user in self.test_data[tier]: for side in self.test_data[tier][user]: c.execute( "INSERT INTO orders ('user','tier','order_id'," "'order_amount','order_type','exchange','unit') " "VALUES (?,?,?,?,?,?,?)", ( user, tier, random.randint(0, 250), self.test_data[tier][user][side], side, "test_exchange", "btc", ), ) conn.commit() conn.close() self.log.debug("ending setUp")
# Install the SQLite plugin app.install(SQLitePlugin(dbfile='pool.db', keyword='db')) # Create the Exchange wrapper objects wrappers = {'bittrex': Bittrex(), 'bter': BTER(), 'ccedk': CCEDK(), 'poloniex': Poloniex(), 'test_exchange': TestExchange()} log.info('load pool config') app.config.load_config('pool_config') log.info('load exchange config') load_config.load(app, 'exchange_config') log.info('set up a json-rpc connection with nud') rpc = AuthServiceProxy("http://{}:{}@{}:{}".format(app.config['rpc.user'], app.config['rpc.pass'], app.config['rpc.host'], app.config['rpc.port'])) if os.environ.get('RUN_TIMERS', 0) == 1: # Set the timer for credits Timer(60.0, credit.credit, kwargs={'app': app, 'rpc': rpc, 'log': log}).start() # Set the timer for payouts Timer(86400.0, payout.pay, kwargs={'rpc': rpc, 'log': log}).start() def check_headers(headers):
def setUp(self): """ Set up the database with some orders ready for a credit :return: """ # Build the tests Logger self.log = logging.Logger('Tests') stream = logging.StreamHandler() formatter = logging.Formatter(fmt='%(message)s') stream.setFormatter(formatter) self.log.addHandler(stream) self.log.debug('TestCredits testcase') self.log.debug('running setUp') # build the database if it doesn't exist database.build(self.log) # set us up a bottle application with correct config self.app = bottle.Bottle() self.app.config.load_config('../pool_config') load_config.load(self.app, 'exchange_config') # clear any existing orders in the database conn = sqlite3.connect('pool.db') c = conn.cursor() c.execute("DELETE FROM orders") c.execute("DELETE FROM credits") conn.commit() # create test data self.test_data = { 'tier_1': { 'TEST_USER_1': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_2': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_3': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_4': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}}, 'tier_2': { 'TEST_USER_1': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_2': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_3': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}, 'TEST_USER_4': { 'bid': random.randint(0, 1000), 'ask': random.randint(0, 1000)}}} # add some orders to the database for test_data for tier in self.test_data: for user in self.test_data[tier]: for side in self.test_data[tier][user]: c.execute("INSERT INTO orders ('user','tier','order_id'," "'order_amount','order_type','exchange','unit') " "VALUES (?,?,?,?,?,?,?)", (user, tier, random.randint(0, 250), self.test_data[tier][user][side], side, 'test_exchange', 'btc')) conn.commit() conn.close() self.log.debug('ending setUp')
print(ts) print(remote_cp(filepath, USERNAME + ':' + PASSWORD + '@' + tgt_ip + '@' + BACKUP)) copy_num = copy_num + 1 rs['files'][filepath]['copy_num'] = copy_num # node.manager.write_to_redis() if copy_num < int(target_copy): node.manager.redis.insert_or_update_list('cp_tasks', encrypt) node.manager.redis.insert_or_update_dict(encrypt, {'filename': filepath, 'copy_num': copy_num, 'target_copy': target_copy, 'size': size}) encrypt = node.manager.redis.lpop('cp_tasks') print('encrypt', encrypt) if ('__main__' == __name__): nodename = get_local_hostname() conf = load('../config/cicada.conf', nodename) nodes = conf['nodes'] ip = conf['ip'] incoming_path = conf['incoming_path'] backup_path = conf['backup_path'] storage_path = conf['storage_path'] max_replica = conf['max_replica'] free_limit = conf['free_limit'] node = Node() while True: backup(node, tgt=backup_path, free_limit=free_limit)
app.install(SQLitePlugin(dbfile='pool.db', keyword='db')) # Create the Exchange wrapper objects wrappers = { 'bittrex': Bittrex(), 'bter': BTER(), 'ccedk': CCEDK(), 'poloniex': Poloniex(), 'test_exchange': TestExchange() } log.info('load pool config') app.config.load_config('pool_config') log.info('load exchange config') load_config.load(app, 'exchange_config') log.info('set up a json-rpc connection with nud') rpc = AuthServiceProxy("http://{}:{}@{}:{}".format(app.config['rpc.user'], app.config['rpc.pass'], app.config['rpc.host'], app.config['rpc.port'])) if os.environ.get('RUN_TIMERS', 0) == 1: # Set the timer for credits Timer(60.0, credit.credit, kwargs={ 'app': app, 'rpc': rpc, 'log': log }).start() # Set the timer for payouts
""" user = {} """ user = userid ,fid """ jobs = {} """ jobs[0] = objectid , jobs[1] = jobid """ finished = '' ppt_finished = '' chapter_finished = '' chapters = [] speed = load_config.load() class Learn_XueXiTong(): def __init__(self): # try: # j_updates.check(__version__) # except: # print('检查更新失败,当日API接口次数已达上限,请明日再检查更新\n跳过检查更新') self.remind() self.session = requests.session() small_tools.check_path('saves') self.usernm,self.passwd = get_user.determine_user_file() self.login() def remind(self): print('程序作者:SamuelChen\n联系作者:github.com/xz454867105\n若使用满意请给该github项目Star或Fork以支持作者,谢谢\n项目链接:github.com/xz454867105/fxxk_chaoxing')