Exemplo n.º 1
0
    def __init__(self, args):
        """
        :param args: CLI args
        """
        global manager
        assert not manager, 'Only one instance of Manager should be created at a time!'

        if args is None:
            # Decode all arguments to unicode before parsing
            args = unicode_argv()[1:]
        self.args = args
        self.config_base = None
        self.config_name = None
        self.config_path = None
        self.db_filename = None
        self.engine = None
        self.lockfile = None
        self.database_uri = None
        self.db_upgraded = False
        self._has_lock = False
        self.is_daemon = False
        self.ipc_server = None
        self.task_queue = None
        self.persist = None
        self.initialized = False

        self.config = {}

        if '--help' in args or '-h' in args:
            # TODO: This is a bit hacky, but we can't call parse on real arguments when --help is used because it will
            # cause a system exit before plugins are loaded and print incomplete help. This will get us a default
            # options object and we'll parse the real args later, or send them to daemon. #2807
            self.options, extra = CoreArgumentParser().parse_known_args(['execute'])
        else:
            try:
                self.options, extra = CoreArgumentParser().parse_known_args(args)
            except ParserError:
                # If a non-built-in command was used, we need to parse with a parser that doesn't define the subparsers
                self.options, extra = manager_parser.parse_known_args(args)
        try:
            self.find_config(create=False)
        except:
            logger.start(level=self.options.loglevel.upper(), to_file=False)
            raise
        else:
            log_file = os.path.expanduser(self.options.logfile)
            # If an absolute path is not specified, use the config directory.
            if not os.path.isabs(log_file):
                log_file = os.path.join(self.config_base, log_file)
            logger.start(log_file, self.options.loglevel.upper(), to_console=not self.options.cron)

        manager = self

        log.debug('sys.defaultencoding: %s' % sys.getdefaultencoding())
        log.debug('sys.getfilesystemencoding: %s' % sys.getfilesystemencoding())
        log.debug('os.path.supports_unicode_filenames: %s' % os.path.supports_unicode_filenames)
        if codecs.lookup(sys.getfilesystemencoding()).name == 'ascii' and not os.path.supports_unicode_filenames:
            log.warning('Your locale declares ascii as the filesystem encoding. Any plugins reading filenames from '
                        'disk will not work properly for filenames containing non-ascii characters. Make sure your '
                        'locale env variables are set up correctly for the environment which is launching FlexGet.')
Exemplo n.º 2
0
    def __init__(self, args):
        """
        :param args: CLI args
        """
        global manager
        assert not manager, 'Only one instance of Manager should be created at a time!'

        if args is None:
            # Decode all arguments to unicode before parsing
            args = unicode_argv()[1:]
        self.args = args
        self.config_base = None
        self.config_name = None
        self.config_path = None
        self.db_filename = None
        self.engine = None
        self.lockfile = None
        self.database_uri = None
        self.db_upgraded = False
        self._has_lock = False
        self.is_daemon = False
        self.ipc_server = None
        self.task_queue = None
        self.persist = None
        self.initialized = False

        self.config = {}

        if '--help' in args or '-h' in args:
            # TODO: This is a bit hacky, but we can't call parse on real arguments when --help is used because it will
            # cause a system exit before plugins are loaded and print incomplete help. This will get us a default
            # options object and we'll parse the real args later, or send them to daemon. #2807
            self.options, extra = CoreArgumentParser().parse_known_args(['execute'])
        else:
            try:
                self.options, extra = CoreArgumentParser().parse_known_args(args)
            except ParserError:
                # If a non-built-in command was used, we need to parse with a parser that doesn't define the subparsers
                self.options, extra = manager_parser.parse_known_args(args)
        try:
            self.find_config(create=False)
        except:
            logger.start(level=self.options.loglevel.upper(), to_file=False)
            raise
        else:
            log_file = os.path.expanduser(self.options.logfile)
            # If an absolute path is not specified, use the config directory.
            if not os.path.isabs(log_file):
                log_file = os.path.join(self.config_base, log_file)
            logger.start(log_file, self.options.loglevel.upper(), to_console=not self.options.cron)

        manager = self

        log.debug('sys.defaultencoding: %s' % sys.getdefaultencoding())
        log.debug('sys.getfilesystemencoding: %s' % sys.getfilesystemencoding())
        log.debug('os.path.supports_unicode_filenames: %s' % os.path.supports_unicode_filenames)
        if codecs.lookup(sys.getfilesystemencoding()).name == 'ascii' and not os.path.supports_unicode_filenames:
            log.warning('Your locale declares ascii as the filesystem encoding. Any plugins reading filenames from '
                        'disk will not work properly for filenames containing non-ascii characters. Make sure your '
                        'locale env variables are set up correctly for the environment which is launching FlexGet.')
Exemplo n.º 3
0
 def _init_options(args: List[str]) -> argparse.Namespace:
     """Initialize argument parsing"""
     try:
         options = CoreArgumentParser().parse_known_args(args, do_help=False)[0]
     except ParserError as exc:
         try:
             # If a non-built-in command was used, we need to parse with a parser that
             # doesn't define the subparsers
             options = manager_parser.parse_known_args(args, do_help=False)[0]
         except ParserError:
             manager_parser.print_help()
             print(f'\nError: {exc.message}')
             sys.exit(1)
     return options
Exemplo n.º 4
0
 def _init_options(self, args):
     """
     Initialize argument parsing
     """
     if '--help' in args or '-h' in args:
         # TODO: This is a bit hacky, but we can't call parse on real arguments when --help is used because it will
         # cause a system exit before plugins are loaded and print incomplete help. This will get us a default
         # options object and we'll parse the real args later, or send them to daemon. #2807
         # TODO: this will cause command failure in case of config.yml does not
         # exists and user runs "flexget -c some.yml --help"
         options = CoreArgumentParser().parse_known_args(['execute'])[0]
     else:
         try:
             options = CoreArgumentParser().parse_known_args(args)[0]
         except ParserError:
             try:
                 # If a non-built-in command was used, we need to parse with a parser that
                 # doesn't define the subparsers
                 options = manager_parser.parse_known_args(args)[0]
             except ParserError as e:
                 manager_parser.print_help()
                 print('\nError: %s' % e.message)
                 sys.exit(1)
     try:
         if options.cli_command is None:
             # TODO: another hack ...
             # simply running "flexget -c config.yml" fails, let's fix that
             manager_parser.print_help()
             print('\nCommand missing, eg. execute or daemon ...')
             # TODO: oh dear ...
             if '--help' in args or '-h' in args:
                 print(
                     'NOTE: The help may be incomplete due issues with argparse. Try without --help.'
                 )
             else:
                 print(
                     'NOTE: The help may be incomplete due issues with argparse. Try with --help.'
                 )
             sys.exit(1)
     except AttributeError:
         pass  # TODO: hack .. this is getting out of hand
     return options
Exemplo n.º 5
0
 def _init_options(self, args):
     """
     Initialize argument parsing
     """
     if '--help' in args or '-h' in args:
         # TODO: This is a bit hacky, but we can't call parse on real arguments when --help is used because it will
         # cause a system exit before plugins are loaded and print incomplete help. This will get us a default
         # options object and we'll parse the real args later, or send them to daemon. #2807
         # TODO: this will cause command failure in case of config.yml does not
         # exists and user runs "flexget -c some.yml --help"
         options = CoreArgumentParser().parse_known_args(['execute'])[0]
     else:
         try:
             options = CoreArgumentParser().parse_known_args(args)[0]
         except ParserError:
             try:
                 # If a non-built-in command was used, we need to parse with a parser that
                 # doesn't define the subparsers
                 options = manager_parser.parse_known_args(args)[0]
             except ParserError as e:
                 manager_parser.print_help()
                 print('\nError: %s' % e.message)
                 sys.exit(1)
     try:
         if options.cli_command is None:
             # TODO: another hack ...
             # simply running "flexget -c config.yml" fails, let's fix that
             manager_parser.print_help()
             print('\nCommand missing, eg. execute or daemon ...')
             # TODO: oh dear ...
             if '--help' in args or '-h' in args:
                 print(
                     'NOTE: The help may be incomplete due issues with argparse. Try without --help.'
                 )
             else:
                 print(
                     'NOTE: The help may be incomplete due issues with argparse. Try with --help.'
                 )
             sys.exit(1)
     except AttributeError:
         pass  # TODO: hack .. this is getting out of hand
     return options