def main(): sys.excepthook = excepthook argp = argparse.ArgumentParser( description='Sell GPU hash power on the NiceHash market.') argp_benchmark = argp.add_mutually_exclusive_group() argp_benchmark.add_argument('--benchmark-all', action='store_true', help='benchmark all algorithms on all devices') argp_benchmark.add_argument( '--benchmark-missing', action='store_true', help='benchmark algorithm-device combinations not measured') argp.add_argument('--list-devices', action='store_true', help='list all devices') argp.add_argument('-v', '--verbose', action='store_true', help='print more information to the console log') argp.add_argument( '--show-mining', action='store_true', help='print output from mining processes, implies --verbose') argp.add_argument('-c', '--configdir', nargs=1, default=[settings.DEFAULT_CONFIGDIR], help=('directory for configuration and benchmark files' + ' (default: ~/.config/nuxhash/)')) argp.add_argument('--version', action='store_true', help='show nuxhash version') args = argp.parse_args() config_dir = Path(args.configdir[0]) if args.version: print(f'nuxhash daemon {__version__}') return if args.show_mining: log_level = logging.DEBUG elif args.verbose: log_level = logging.INFO else: log_level = logging.WARN logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=log_level) all_devices = nvidia_devices() nx_settings = settings.load_settings(config_dir) nx_benchmarks = settings.load_benchmarks(config_dir, all_devices) # If no wallet configured, do initial setup prompts. if nx_settings['nicehash']['wallet'] == '': wallet, workername, region = initial_setup() nx_settings['nicehash']['wallet'] = wallet nx_settings['nicehash']['workername'] = workername nx_settings['nicehash']['region'] = region # Download and initialize miners. downloadables = make_miners(config_dir) for d in downloadables: if not d.verify(): logging.info(f'Downloading {d.name}') d.download() nx_miners = [miner(config_dir) for miner in all_miners] for miner in nx_miners: miner.settings = nx_settings # Select code path(s), benchmarks and/or mining. if args.benchmark_all: nx_benchmarks = run_missing_benchmarks(nx_miners, nx_settings, all_devices, settings.EMPTY_BENCHMARKS) elif args.benchmark_missing: nx_benchmarks = run_missing_benchmarks(nx_miners, nx_settings, all_devices, nx_benchmarks) elif args.list_devices: list_devices(all_devices) else: nx_benchmarks = run_missing_benchmarks(nx_miners, nx_settings, all_devices, nx_benchmarks) session = MiningSession(nx_miners, nx_settings, nx_benchmarks, all_devices) # Attach the SIGINT signal for quitting. # NOTE: If running in a shell, Ctrl-C will get sent to our subprocesses too, # because we are the foreground process group. Miners will get killed # before we have a chance to properly shut them down. signal.signal(signal.SIGINT, lambda signum, frame: session.stop()) session.run() settings.save_settings(config_dir, nx_settings) settings.save_benchmarks(config_dir, nx_benchmarks) terminate()
def main(): argp = argparse.ArgumentParser( description='Sell GPU hash power on the NiceHash market.') argp_benchmark = argp.add_mutually_exclusive_group() argp_benchmark.add_argument( '--benchmark-all', action='store_true', help='benchmark all algorithms on all devices') argp_benchmark.add_argument( '--benchmark-missing', action='store_true', help='benchmark algorithm-device combinations not measured') argp.add_argument('--list-devices', action='store_true', help='list all devices') argp.add_argument('-v', '--verbose', action='store_true', help='print more information to the console log') argp.add_argument('--show-mining', action='store_true', help='print output from mining processes, implies --verbose') argp.add_argument( '-c', '--configdir', nargs=1, default=[settings.DEFAULT_CONFIGDIR], help=('directory for configuration and benchmark files' + ' (default: ~/.config/nuxhash/)')) argp.add_argument('--version', action='store_true', help='show nuxhash version') args = argp.parse_args() config_dir = Path(args.configdir[0]) if args.version: print('nuxhash daemon %s' % __version__) return if args.show_mining: log_level = logging.DEBUG elif args.verbose: log_level = logging.INFO else: log_level = logging.WARN logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=log_level) all_devices = nvidia_devices() nx_settings = settings.load_settings(config_dir) nx_benchmarks = settings.load_benchmarks(config_dir, all_devices) # If no wallet configured, do initial setup prompts. if nx_settings['nicehash']['wallet'] == '': wallet, workername, region = initial_setup() nx_settings['nicehash']['wallet'] = wallet nx_settings['nicehash']['workername'] = workername nx_settings['nicehash']['region'] = region # Download and initialize miners. downloadables = make_miners(config_dir) for d in downloadables: if not d.verify(): logging.info('Downloading %s' % d.name) d.download() nx_miners = [miner(config_dir) for miner in all_miners] for miner in nx_miners: miner.settings = nx_settings # Select code path(s), benchmarks and/or mining. if args.benchmark_all: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, settings.EMPTY_BENCHMARKS) elif args.benchmark_missing: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, nx_benchmarks) elif args.list_devices: list_devices(all_devices) else: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, nx_benchmarks) session = MiningSession(nx_miners, nx_settings, nx_benchmarks, all_devices) session.run() settings.save_settings(config_dir, nx_settings) settings.save_benchmarks(config_dir, nx_benchmarks)