def present(self, client, pos): client = client or get_root() self.topleft = client.local_to_global(pos) focus = get_focus() font = self.font h = font.get_linesize() items = self._items margin = self.margin height = h * len(items) + h w1 = w2 = 0 for item in items: item.enabled = self.command_is_enabled(item, focus) w1 = max(w1, font.size(item.text)[0]) w2 = max(w2, font.size(item.keyname)[0]) width = w1 + 2 * margin self._key_margin = width if w2 > 0: width += w2 + margin self.size = (width, height) self._hilited = None root = get_root() self.rect.clamp_ip(root.rect) return Dialog.present(self, centered=False)
def present(self, client, pos): client = client or get_root() self.topleft = client.local_to_global(pos) focus = get_focus() font = self.font h = font.get_linesize() items = self._items margin = self.margin if self.scrolling: height = h * self.scroll_items + h else: height = h * len(items) + h w1 = w2 = 0 for item in items: item.enabled = self.command_is_enabled(item, focus) w1 = max(w1, font.size(item.text)[0]) w2 = max(w2, font.size(item.keyname)[0]) width = w1 + 2 * margin self._key_margin = width if w2 > 0: width += w2 + margin if self.scrolling: width += self.scroll_button_size self.size = (width, height) self._hilited = None root = get_root() self.rect.clamp_ip(root.rect) return Dialog.present(self, centered=False)
def set_config(con): config.VALIDATOR_STATE_PATH = os.path.join(root.get_root(), 'config/priv_validator_state.json') config.RANCHER_TEMPLATE_PATH = os.path.join(root.get_root(), 'config/rancher-template.json') config.ROOT_PATH = con.get('ROOT_PATH') config.DOCKER_FILE_NAME = con.get('DOCKER_FILE_NAME') config.HOST = con.get('HOST') config.PORT = con.get('PORT') config.RANCHER_ADDRESS = con.get('RANCHER_ADDRESS') config.PROJECT_ID = con.get('PROJECT_ID') config.STACK_NAME = con.get('STACK_NAME') config.MACHINE_IPS = con.get('MACHINE_IPS') config.USER_NAME = con.get('USER_NAME') config.IDENTITY = con.get('IDENTITY') config.NODE_DIR = con.get('NODE_DIR') config.DEBUG = con.get('DEBUG') config.IMAGE_ID = con.get('IMAGE_ID')
def test_json(self): file = root.get_root() + '/genesis.json' block = Block() print(file) with open(file, 'w') as f: json.dump(fp=f, obj=block, default=Block.json_parse) with open(file, 'r') as f: temp = json.load(fp=f, object_hook=Block.json_load) print(temp.__dict__)
def test_obtain_account(self): address = '0x32' account = Account.generate_account('TRG', '0x32', '323232', str(datetime.now()), "Agc") block = Block.generate_block( Block.genesis(root.get_root() + '/genesis.json')) block.accounts.setdefault( address, json.dumps(obj=account, default=Account.json_parse)) status, output = Account.obtain_account(address, block) self.assertEqual(status, 200) print(output)
def inspect_genesis(remote_file): def get_hash(file_check): file_check = [i.replace(' ', '') for i in file_check] file_check = [i.replace('\n', '') for i in file_check] file_hash = hashlib.md5() for line in file_check: file_hash.update(line.strip().encode()) return file_hash.hexdigest() local_file = os.path.join(root.get_root(), 'genesis.json') with open(local_file, 'r') as local_file_char: return get_hash(local_file_char.readlines()) == get_hash(remote_file)
def load_config(env): global config config_path = os.path.join(root.get_root(), str.format('config/config-{}.json', env)) # 读取配置文件 try: if not file_util.is_exist(config_path): logger.error('配置文件路径不存在') return config_str = file_util.read(config_path) # 将json字符串反序列化为dict类型 con = json_util.un_marshal(config_str) set_config(con) except Exception as e: logger.error(e)
def test_obtain(self): transaction = Transaction.generate_transaction(str(datetime.now()), "{dd:f}", 5, 2, 1) print(transaction.hash) block = Block.generate_block(Block.genesis(root.get_root() + '/genesis.json')) block.transactions.setdefault(transaction.hash, json.dumps(obj=transaction, default=Transaction.json_parse)) status, output = Transaction.obtain_transaction('', block) self.assertEqual(status, 400) print(output) status, output = Transaction.obtain_transaction(transaction.hash, block) self.assertEqual(status, 200) print(output) status, output = Transaction.obtain_transaction('562140165816165', block) self.assertEqual(status, 400) print(output)
# 停止容器 def _stop_docker(peer): if not shell_util.exec_cmd( str.format("docker rm -f {}", peer.container_name)): raise Exception('容器删除失败') # 启动容器 def _start_docker(peer): docker_file_path = file_util.join(peer.path, config.DOCKER_FILE_NAME) if not shell_util.exec_cmd( str.format("docker-compose -f {} up -d", docker_file_path)): raise Exception('容器删除失败') # 从目标节点读取genesis.json文件 def read_genesis(target_id): peer = config.get_peer_by_id(target_id) path = file_util.join(peer.path, GENESIS_PATH) return file_util.get_json(path) if __name__ == '__main__': # config.load_config("../network_config.json") # do_move("234", "abc") # print(read_genesis('/Users/zyj/Desktop/node1/node1_data/config/genesis.json')) print(VALIDATOR_STATE_PATH) print(root.get_root())
def test_genesis(self): file = root.get_root() block = Block.genesis(file + '/genesis.json') print(block.__dict__) self.assertEqual(block.version, "#version1", "Error")
from tornado import ioloop from tornado.web import Application from tornado.httpserver import HTTPServer from yocb.tools import Network, Logger, Tool from yocb.tools import BlockTools from handle.MainHandle import MainHandle from handle.BlockHandle import BlockHandle from yocb.chain_client import chain views_list = [ (r'/', MainHandle), (r'/block/get', BlockHandle), ] settings = { 'debug': True, 'static_path': os.path.join(root.get_root(), 'static'), } if __name__ == '__main__': # inspect all environment Logger.info_logger() _variable = Tool.get_variable() # inspect network status, output = Network.inspect_network('8.8.8.8') if status != 0: logging.info('Fail <> Your network is ill, so you cannot join us!') sys.exit(1) logging.info('Success <> Network is ok...') # inspect datadir