예제 #1
0
 def test_version_command(self):
     actual_output = StringIO()
     with contextlib.redirect_stdout(actual_output):
         main(['version'])
     self.assertEqual(
         actual_output.getvalue().strip(),
         "lbrynet {lbrynet_version}".format(**get_platform())
     )
예제 #2
0
파일: cli.py 프로젝트: walidmujahid/lbry
def main(argv=None):
    argv = argv or sys.argv[1:]
    if not argv:
        print_help()
        return 1

    conf_path = None
    if len(argv) and argv[0] == "--conf":
        if len(argv) < 2:
            print("No config file specified for --conf option")
            print_help()
            return 1

        conf_path = argv[1]
        argv = argv[2:]

    method, args = argv[0], argv[1:]

    if method in ['help', '--help', '-h']:
        if len(args) == 1:
            print_help_for_command(args[0])
        else:
            print_help()
        return 0

    elif method in ['version', '--version', '-v']:
        print("{lbrynet_name} {lbrynet_version}".format(
            lbrynet_name=lbrynet_name, **get_platform()
        ))
        return 0

    elif method == 'start':
        sys.exit(daemon_main(args, conf_path))

    elif method == 'console':
        sys.exit(daemon_console())

    elif method not in Daemon.callable_methods:
        if method not in Daemon.deprecated_methods:
            print(f'{method} is not a valid command.')
            return 1

        new_method = Daemon.deprecated_methods[method].new_command
        if new_method is None:
            print(f"{method} is permanently deprecated and does not have a replacement command.")
            return 0

        print(f"{method} is deprecated, using {new_method}.")
        method = new_method

    fn = Daemon.callable_methods[method]
    parsed = docopt(fn.__doc__, args)
    params = set_kwargs(parsed)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(execute_command(method, params, conf_path))

    return 0
예제 #3
0
 def __init__(self, analytics_api, context=None, installation_id=None, session_id=None):
     self.analytics_api = analytics_api
     self._tracked_data = collections.defaultdict(list)
     self.looping_call_manager = self._setup_looping_calls()
     self.context = context or self._make_context(
         system_info.get_platform(), conf.settings['wallet'])
     self.installation_id = installation_id or conf.settings.installation_id
     self.session_id = session_id or conf.settings.get_session_id()
     self.is_started = False
예제 #4
0
 def __init__(self, conf: Config, installation_id: str, session_id: str):
     self.cookies = {}
     self.url = ANALYTICS_ENDPOINT
     self._write_key = utils.deobfuscate(ANALYTICS_TOKEN)
     self._enabled = conf.share_usage_data
     self._tracked_data = collections.defaultdict(list)
     self.context = self._make_context(system_info.get_platform(), 'torba')
     self.installation_id = installation_id
     self.session_id = session_id
     self.task: asyncio.Task = None
예제 #5
0
def start(argv=None, conf_path=None):
    if conf_path is not None:
        conf.conf_file = conf_path

    conf.initialize_settings()

    parser = argparse.ArgumentParser()
    parser.add_argument("--http-auth",
                        dest="useauth",
                        action="store_true",
                        default=conf.settings['use_auth_http'])
    parser.add_argument('--quiet',
                        dest='quiet',
                        action="store_true",
                        help='Disable all console output.')
    parser.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    parser.add_argument('--version',
                        action="store_true",
                        help='Show daemon version and quit')

    args = parser.parse_args(argv)
    if args.useauth:
        conf.settings.update({'use_auth_http': args.useauth},
                             data_types=(conf.TYPE_CLI, ))

    if args.version:
        version = system_info.get_platform()
        version['installation_id'] = conf.settings.installation_id
        print(utils.json_dumps_pretty(version))
        return

    lbrynet_log = conf.settings.get_log_filename()
    log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
    log_support.configure_loggly_handler()
    log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())

    log.info("Starting lbrynet-daemon from command line")

    if test_internet_connection():
        daemon = Daemon()
        daemon.start_listening()
        reactor.run()
    else:
        log.info("Not connected to internet, unable to start")
예제 #6
0
def start_daemon_with_cli_args(argv=None,
                               data_dir: typing.Optional[str] = None,
                               wallet_dir: typing.Optional[str] = None,
                               download_dir: typing.Optional[str] = None):
    parser = argparse.ArgumentParser()
    parser.add_argument("--http-auth",
                        dest="useauth",
                        action="store_true",
                        default=False)
    parser.add_argument('--quiet',
                        dest='quiet',
                        action="store_true",
                        help='Disable all console output.')
    parser.add_argument(
        '--verbose',
        nargs="*",
        help=
        ('Enable debug output. Optionally specify loggers for which debug output '
         'should selectively be applied.'))
    parser.add_argument('--version',
                        action="store_true",
                        help='Show daemon version and quit')

    args = parser.parse_args(argv)
    settings = {}
    if args.useauth:
        settings['use_auth_http'] = True

    verbose = None
    if args.verbose:
        verbose = args.verbose

    console_output = not args.quiet

    if args.version:
        print(json_dumps_pretty(get_platform()))
        return

    return start_daemon(settings, console_output, verbose, data_dir,
                        wallet_dir, download_dir)
예제 #7
0
def main(argv=None):
    argv = argv or sys.argv[1:]
    if not argv:
        print_help()
        return 1

    dir_args = {}
    if len(argv) >= 2:
        dir_arg_keys = ['data_dir', 'wallet_dir', 'download_directory']

        for arg in argv:
            found_dir_arg = False
            for key in dir_arg_keys:
                if arg.startswith(f'--{key}='):
                    if key in dir_args:
                        print(f"Multiple values provided for '{key}' argument")
                        print_help()
                        return 1
                    dir_args[key] = os.path.expanduser(
                        os.path.expandvars(arg.lstrip(f'--{key}=')))
                    found_dir_arg = True
            if not found_dir_arg:
                break
        argv = argv[len(dir_args):]

    data_dir = dir_args.get('data_dir')
    wallet_dir = dir_args.get('wallet_dir')
    download_dir = dir_args.get('download_directory')

    for k, v in dir_args.items():
        if not os.path.isdir(v):
            print(f"'{data_dir}' is not a directory, cannot use it for {k}")
            return 1

    method, args = argv[0], argv[1:]

    if method in ['help', '--help', '-h']:
        if len(args) == 1:
            print_help_for_command(args[0])
        else:
            print_help()
        return 0

    elif method in ['version', '--version', '-v']:
        print("{lbrynet_name} {lbrynet_version}".format(
            lbrynet_name=lbrynet_name, **get_platform()))
        return 0

    elif method == 'start':
        sys.exit(
            start_daemon_with_cli_args(args, data_dir, wallet_dir,
                                       download_dir))

    elif method == 'console':
        sys.exit(daemon_console())

    elif method not in Daemon.callable_methods:
        if method not in Daemon.deprecated_methods:
            print(f'{method} is not a valid command.')
            return 1

        new_method = Daemon.deprecated_methods[method].new_command
        if new_method is None:
            print(
                f"{method} is permanently deprecated and does not have a replacement command."
            )
            return 0

        print(f"{method} is deprecated, using {new_method}.")
        method = new_method

    fn = Daemon.callable_methods[method]
    parsed = docopt(fn.__doc__, args)
    params = set_kwargs(parsed)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        execute_command(method, params, data_dir, wallet_dir, download_dir))

    return 0
예제 #8
0
 def test_version_command(self):
     self.assertEqual("lbrynet {lbrynet_version}".format(**get_platform()),
                      self.shell(['--version']))