Esempio n. 1
0
    def get_settings(self, args, options):
        '''Return command specific settings. Default behavior is to combine
        `command_settings` with the settings received from command line.

        `self.engine` is still not initialized, so don't use it.
        '''
        custom_settings = self.command_settings.copy()

        if hasattr(options, 'set'):
            try:
                custom_settings.update(arglist_to_dict(options.set))
            except ValueError:
                raise UsageError('Invalid -s value, use -s NAME=VALUE',
                                 print_help=False)

        # logging behavior
        if getattr(options, 'logfile', None):
            custom_settings['LOG_ENABLED'] = True
            custom_settings['LOG_FILE'] = options.logfile
        if getattr(options, 'loglevel', None):
            custom_settings['LOG_ENABLED'] = True
            custom_settings['LOG_LEVEL'] = options.loglevel
        if getattr(options, 'nolog', None):
            custom_settings['LOG_ENABLED'] = False

        return Settings(custom_settings)
Esempio n. 2
0
    def get_settings(self, args, options):
        '''Return command specific settings. Default behavior is to combine
        `command_settings` with the settings received from command line.

        `self.engine` is still not initialized, so don't use it.
        '''
        custom_settings = self.command_settings.copy()

        if hasattr(options, 'set'):
            try:
                custom_settings.update(arglist_to_dict(options.set))
            except ValueError:
                raise UsageError('Invalid -s value, use -s NAME=VALUE',
                                 print_help=False)

        # logging behavior
        if getattr(options, 'logfile', None):
            custom_settings['LOG_ENABLED'] = True
            custom_settings['LOG_FILE'] = options.logfile
        if getattr(options, 'loglevel', None):
            custom_settings['LOG_ENABLED'] = True
            custom_settings['LOG_LEVEL'] = options.loglevel
        if getattr(options, 'nolog', None):
            custom_settings['LOG_ENABLED'] = False

        return Settings(custom_settings)
Esempio n. 3
0
    def get_spider(self, engine, args, options):
        if len(args) != 1:
            raise UsageError()

        try:
            spargs = arglist_to_dict(options.spargs)
        except ValueError:
            raise UsageError('Invalid -a value, use -a NAME=VALUE',
                             print_help=False)
        return engine.spiders.create_spider_by_name(args[0], spargs=spargs)
Esempio n. 4
0
 def test_arglist_to_dict(self):
     self.assertEqual(arglist_to_dict(['arg1=val1', 'arg2=val2']), {
         'arg1': 'val1',
         'arg2': 'val2'
     })
Esempio n. 5
0
 def test_arglist_to_dict(self):
     self.assertEqual(
         arglist_to_dict(['arg1=val1', 'arg2=val2']),
         {'arg1': 'val1', 'arg2': 'val2'})