def get_command_for_execute_with_shell(cmd, config): run_in_shell = check_bool(config.get('start_shell', False)) shelling_info = check_bool(config.get('p_open_shell', False)) shell_name = config.get('shell_name', '') return [ shell_name, cmd ] if run_in_shell and shell_name else [el for el in cmd.split(' ') if el] if not shelling_info else cmd
def work_procedure(self, iteration) -> bool: temp_global_sync = self.global_sync self.wallet_info = self.connector.get_status_info( self.chia_farm_rpc, self.chia_wallet_rpc, self.chia_harvester_rpc) if self.connector else {} if 'blockchain' in self.wallet_info and self.wallet_info['_responses'][ 'blockchain_code'] == 200: self.global_height = self.wallet_info['blockchain'][ 'blockchain_state']['peak']['height'] self.global_sync = self.wallet_info['blockchain'][ 'blockchain_state']['sync']['synced'] if 'wallet_sync' in self.wallet_info and self.wallet_info[ '_responses']['wallet_sync_code'] == 200: self.global_sync = self.wallet_info['wallet_sync'][ 'synced'] if self.global_sync is None else ( self.global_sync and self.wallet_info['wallet_sync']['synced']) if 'wallet_balance' in self.wallet_info and self.wallet_info[ '_responses']['wallets_code'] == 200: balance = self.wallet_info['wallet_balance'][ 'confirmed_wallet_balance'] if balance != self.balance and self.balance is not None: self.main_processor.messager.send_message( f'BALANCE CHANGE {self.global_sync}') self.balance = balance if self.main_processor.main_config and check_bool( self.main_processor.main_config.get('recheck_work_dir', False), False): for work_dir in self.work_dirs: self.connector.add_plot_directory(work_dir, self.chia_harvester_rpc) # ADD NODES if not self.global_sync: for local_node in self.local_nodes: self.connect_node(local_node) if self.search_nodes_site and self.search_nodes: nodes = get_nodes_from_site(self.search_nodes_site, self.global_height) for node in nodes: self.connect_node(node) if temp_global_sync != self.global_sync or temp_global_sync is None: self.main_processor.messager.send_message( f'SYNC STATUS CHANGE {self.global_sync}') return False
def get_threads_configs(): default_config = {'chia_path': '~/chia.exe', 'thread_per_plot': '2', 'parallel_plot': '2', 'temp_dir': '/tmp', 'work_dir': '/safe', 'memory': '4608', 'bucket': '128', 'k_size': '32', 'plots_count': 10, 'auto_restart': False, 'auto_find_exe': True, 'pause_before_start': 0, 'recheck_work_dir': False, 'fingerprint': None, 'pool_pub_key': None, 'farmer_pub_key': None, 'pool_contract_address': None, 'start_node': None, 'set_peer_address': None, 'start_shell': False, 'shell_name': 'powershell', 'p_open_shell': False, 'code_page': 'cp1251', 'bitfield_disable': 'False', 'web_server_port': 5050, 'web_server_debug': False, 'web_server_address': '0.0.0.0', 'web_work_dir': None, } if not os.path.exists('config.ini'): with open('config.ini', 'wt') as file: file.write('[default]\n') file.writelines([f'{k}={v if v is not None else ""}\n' for k, v in default_config.items()]) config = configparser.ConfigParser() config.read('config.ini') if 'default' in config.sections(): default_config = read_params_from_section(config, 'default', default_config) chia_path = default_config.get('chia_path', None) is_imitator = chia_path.find('python.exe') >= 0 if chia_path is None or (not is_imitator and not Path(default_config['chia_path']).exists()): if check_bool(default_config.get('auto_find_exe', True)): path_chia_exe = find_chia() else: path_chia_exe = False if path_chia_exe: default_config['chia_path'] = path_chia_exe print('WARNING: NO "chia_path" IN CONFIG FILE OR PATH INCORRECT!') print(f'USE PATH: {path_chia_exe}') else: print('ERROR: NO CHIA.EXE FILE FOUND!') sys.exit(1) password = get_hash(default_config.get('password', 'Qwerty12345')) default_config['password'] = password config_thread = [read_params_from_section(config, section, default_config, THREAD_CHIA_PROPERTY) for section in config.sections() if section != 'default'] return config_thread, default_config
def run_command_and_get_output(self, cmd, index, clear_lines=True): start_shell = self.config.get('start_shell', False) shelling_info = check_bool(self.config.get('p_open_shell', False)) code_page = self.config.get('code_page', '') if not code_page: if os.name == 'nt' and shelling_info: if start_shell: code_page = 'cp866' else: code_page = 'cp1251' else: code_page = 'utf8' cmd = get_command_for_execute_with_shell(cmd, self.config) try: self.status = f'RUN COMMAND' print( f'TRY EXECUTE CMD {cmd} IN THREAD {self.name} with code_page={code_page} shell={start_shell}' ) self.process = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=start_shell, encoding=code_page, universal_newlines=True) while self.worked and self.process and self.process.poll() is None: text = self.process.stdout.readline() if text: if clear_lines: text = text.strip() if text: yield text else: yield text except subprocess.CalledProcessError as e: self.set_status(f'ERROR {e} on plot {self.current_iteration}') self.process = None except ValueError as e: self.set_status(f'ERROR {e} on plot {self.current_iteration}') self.process = None except Exception as e: self.set_status(f'ERROR {e} on plot {self.current_iteration}') self.analise_command_output(index, str(e), True)
def __init__(self, processor): self.main_processor = processor sleep_time = int( self.main_processor.main_config.get('info_update_time', 600)) self.chia_config_path = self.main_processor.main_config.get( 'chia_config_path', '') self.chia_farm_rpc = int( self.main_processor.main_config.get('chia_farm_rpc', 8555)) self.chia_wallet_rpc = int( self.main_processor.main_config.get('chia_wallet_rpc', 9256)) self.chia_harvester_rpc = int( self.main_processor.main_config.get('chia_harvester_rpc', 8560)) self.chia_farm_host = self.main_processor.main_config.get( 'chia_farm_host', 'localhost') self.local_nodes = self.main_processor.main_config.get( 'local_nodes', '').split(',') self.search_nodes_site = self.main_processor.main_config.get( 'search_nodes_site', '') self.search_nodes = check_bool( self.main_processor.main_config.get('search_nodes', 'true')) super().__init__(name='Information Thread', inter_iteration_pause=sleep_time, pause_before=True) self.farm_info = {} self.wallet_info = { '_responses': { 'blockchain_code': -100, 'connections_code': -100, 'wallets_code': -100, 'farmed_amount_code': -100, 'wallet_sync_code': -100, 'plots_code': -100, 'dirs_code': -100, } } self.global_sync = None self.connector = None self.global_height = 0 self.balance = None self.work_dirs = []
def render_config(request, thread_info=None): message = '' new_thread = False if thread_info is None: thread_info = EmptyObject() thread_info.config = app.ctx.processor.main_config new_thread = True thread_info.name = f'new_thread_{len(app.ctx.processor.threads)}' thread_info.last = 1 thread_info.current_iteration = 0 if request.method == 'POST': try: if new_thread: thread_info.config = app.ctx.processor.main_config.copy() thread_info.config['name'] = thread_info.name new_count = int(request.form.get('count', thread_info.last)) new_bucket = int( request.form.get('bucket', thread_info.config['bucket'])) new_ksize = int( request.form.get('k_size', thread_info.config['k_size'])) new_memory = int( request.form.get('memory', thread_info.config['memory'])) new_pause = int( request.form.get('pause_before_start', thread_info.config['pause_before_start'])) new_thread_per_plot = int( request.form.get('thread_per_plot', thread_info.config['thread_per_plot'])) new_parallel_plot = int( request.form.get('parallel_plot', thread_info.config['parallel_plot'])) new_temp = request.form.get('temp_path', '') new_work = request.form.get('work_path', '') if new_temp and os.path.exists(new_temp): thread_info.config['temp_dir'] = new_temp if new_work and os.path.exists(new_work): thread_info.config['work_dir'] = new_work thread_info.last = new_count thread_info.config['bucket'] = new_bucket thread_info.config['k_size'] = new_ksize thread_info.config['thread_per_plot'] = new_thread_per_plot thread_info.config['parallel_plot'] = new_parallel_plot thread_info.config['memory'] = new_memory thread_info.config['pause_before_start'] = new_pause thread_info.config['fingerprint'] = request.form.get( 'fingerprint', thread_info.config['fingerprint']) thread_info.config['pool_pub_key'] = request.form.get( 'pool_pub_key', thread_info.config['pool_pub_key']) thread_info.config['farmer_pub_key'] = request.form.get( 'farmer_pub_key', thread_info.config['farmer_pub_key']) thread_info.config['bitfield_disable'] = check_bool( request.form.get('bitfield_disable', False), False) thread_info.config['start_shell'] = check_bool( request.form.get('start_shell', False), False) thread_info.config['p_open_shell'] = check_bool( request.form.get('p_open_shell', False), False) thread_info.config['code_page'] = request.form.get( 'code_page', thread_info.config['code_page']) thread_info.config['shell_name'] = request.form.get( 'shell_name', thread_info.config['shell_name']) thread_info.config['pool_contract_address'] = request.form.get( 'pool_contract_address', thread_info.config['pool_contract_address']) if thread_info.config['pool_contract_address'] is not None: thread_info.config['fingerprint'] = None thread_info.config['pool_pub_key'] = None if new_thread: app.ctx.processor.add_new_thread(thread_info.config) return response.redirect('/control') except ValueError as e: message = e return jinja.render( 'modify.html', request, name=thread_info.name, count_task=thread_info.last, current_task=thread_info.current_iteration, message=message, work_path=thread_info.config['work_dir'], temp_path=thread_info.config['temp_dir'], bucket=thread_info.config['bucket'], k_size=thread_info.config['k_size'], thread_per_plot=thread_info.config['thread_per_plot'], parallel_plot=thread_info.config['parallel_plot'], pause_before_start=thread_info.config['pause_before_start'], memory=thread_info.config['memory'], fingerprint=thread_info.config['fingerprint'], pool_pub_key=thread_info.config['pool_pub_key'], farmer_pub_key=thread_info.config['farmer_pub_key'], new_thread=new_thread, bitfield_disable=check_bool( thread_info.config.get('bitfield_disable', False)), start_shell=check_bool(thread_info.config.get('start_shell', False)), p_open_shell=check_bool(thread_info.config.get('p_open_shell', False)), code_page=thread_info.config['code_page'], shell_name=thread_info.config['shell_name'], )