def check_csv(option, opt, value):
    """check a csv value by trying to split it
    return the list of separated values
    """
    if isinstance(value, (list, tuple)):
        return value
    try:
        return splitstrip(value)
    except ValueError:
        raise OptionValueError("option %s: invalid csv value: %r" % (opt, value))
def check_csv(option, opt, value):
    """check a csv value by trying to split it
    return the list of separated values
    """
    if isinstance(value, (list, tuple)):
        return value
    try:
        return splitstrip(value)
    except ValueError:
        raise OptionValueError("option %s: invalid csv value: %r" %
                               (opt, value))
Beispiel #3
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     for (tok_type, content, start, _, _) in tokens:
         if tok_type != tokenize.COMMENT:
             continue
         match = OPTION_RGX.search(content)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all" or \
                 match.group(1).strip() == 'skip-file':
             if match.group(1).strip() == "disable-all":
                 self.add_message('deprecated-pragma',
                                  line=start[0],
                                  args=('disable-all', 'skip-file'))
             self.add_message('file-ignored', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('bad-inline-option',
                              args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 # found a "(dis|en)able-msg" pragma deprecated suppresssion
                 self.add_message('deprecated-pragma',
                                  line=start[0],
                                  args=(opt, opt.replace('-msg', '')))
             for msgid in splitstrip(value):
                 try:
                     if (opt, msgid) == ('disable', 'all'):
                         self.add_message('deprecated-pragma',
                                          line=start[0],
                                          args=('disable=all', 'skip-file'))
                         self.add_message('file-ignored', line=start[0])
                         self._ignore_file = True
                         return
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('bad-option-value',
                                      args=msgid,
                                      line=start[0])
         else:
             self.add_message('unrecognized-inline-option',
                              args=opt,
                              line=start[0])
Beispiel #4
0
def set_debug(debugmode):
    """change the repository debugging mode"""
    global DEBUG
    if not debugmode:
        DEBUG = 0
        return
    if isinstance(debugmode, str):
        for mode in splitstrip(debugmode, sep='|'):
            DEBUG |= globals()[mode]
    else:
        DEBUG |= debugmode
Beispiel #5
0
def check_csv(
    option: Optional["Option"], opt: str, value: Union[List[str], Tuple[str, ...], str]
) -> Union[List[str], Tuple[str, ...]]:
    """check a csv value by trying to split it
    return the list of separated values
    """
    if isinstance(value, (list, tuple)):
        return value
    try:
        return splitstrip(value)
    except ValueError:
        raise OptionValueError("option %s: invalid csv value: %r" % (opt, value))
Beispiel #6
0
 def bootstrap_cubes(self):
     from logilab.common.textutils import splitstrip
     with open(join(self.apphome, 'bootstrap_cubes')) as f:
         for line in f:
             line = line.strip()
             if not line or line.startswith('#'):
                 continue
             self.init_cubes(self.expand_cubes(splitstrip(line)))
             break
         else:
             # no cubes
             self.init_cubes(())
Beispiel #7
0
    def run(self, args):
        from subprocess import Popen
        from tempfile import NamedTemporaryFile
        from logilab.common.textutils import splitstrip
        from logilab.common.graph import GraphGenerator, DotBackend
        from yams import schema2dot as s2d, BASE_TYPES
        from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES,
                                     WORKFLOW_TYPES, INTERNAL_TYPES)
        cubes = splitstrip(args[0])
        dev_conf = DevConfiguration(*cubes)
        schema = dev_conf.load_schema()
        out, viewer = self['output-file'], self['viewer']
        if out is None:
            tmp_file = NamedTemporaryFile(suffix=".svg")
            out = tmp_file.name
        skiptypes = BASE_TYPES | SCHEMA_TYPES
        if not self['show-meta']:
            skiptypes |= META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES
        if not self['show-workflow']:
            skiptypes |= WORKFLOW_TYPES
        if not self['show-cw-user']:
            skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress'))
        skiptypes |= set(self['exclude-type'].split(','))
        skiptypes -= set(self['include-type'].split(','))

        if not self['show-etype']:
            s2d.schema2dot(schema, out, skiptypes=skiptypes)
        else:
            etype = self['show-etype']
            visitor = s2d.OneHopESchemaVisitor(schema[etype],
                                               skiptypes=skiptypes)
            propshdlr = s2d.SchemaDotPropsHandler(visitor)
            backend = DotBackend('schema',
                                 'BT',
                                 ratio='compress',
                                 size=None,
                                 renderer='dot',
                                 additionnal_param={
                                     'overlap': 'false',
                                     'splines': 'true',
                                     'sep': '0.2'
                                 })
            generator = s2d.GraphGenerator(backend)
            generator.generate(visitor, propshdlr, out)

        if viewer:
            p = Popen((viewer, out))
            p.wait()
Beispiel #8
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all" or match.group(
                 1).strip() == 'skip-file':
             if match.group(1).strip() == "disable-all":
                 self.add_message('I0014', line=start[0])
             self.add_message('I0013', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('I0010',
                              args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 warn(
                     '%s is deprecated, replace it with %s (%s, line %s)' %
                     (opt, opt.split('-')[0], self.current_file, line),
                     DeprecationWarning)
             for msgid in splitstrip(value):
                 try:
                     if (opt, msgid) == ('disable', 'all'):
                         self.add_message('I0014', line=start[0])
                         self.add_message('I0013', line=start[0])
                         self._ignore_file = True
                         return
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('E0012', args=msgid, line=start[0])
         else:
             self.add_message('E0011', args=opt, line=start[0])
Beispiel #9
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all" or match.group(1).strip() == "skip-file":
             if match.group(1).strip() == "disable-all":
                 self.add_message("I0014", line=start[0])
             self.add_message("I0013", line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split("=", 1)
         except ValueError:
             self.add_message("I0010", args=match.group(1).strip(), line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 warn(
                     "%s is deprecated, replace it with %s (%s, line %s)"
                     % (opt, opt.split("-")[0], self.current_file, line),
                     DeprecationWarning,
                 )
             for msgid in splitstrip(value):
                 try:
                     if (opt, msgid) == ("disable", "all"):
                         self.add_message("I0014", line=start[0])
                         self.add_message("I0013", line=start[0])
                         self._ignore_file = True
                         return
                     meth(msgid, "module", start[0])
                 except UnknownMessage:
                     self.add_message("E0012", args=msgid, line=start[0])
         else:
             self.add_message("E0011", args=opt, line=start[0])
Beispiel #10
0
 def _ask_for_dependencies(self):
     from logilab.common.shellutils import ASK
     from logilab.common.textutils import splitstrip
     depcubes = []
     for cube in ServerConfiguration.available_cubes():
         answer = ASK.ask("Depends on cube %s? " % cube,
                          ('N', 'y', 'skip', 'type'), 'N')
         if answer == 'y':
             depcubes.append(cube)
         if answer == 'type':
             depcubes = splitstrip(input('type dependencies: '))
             break
         elif answer == 'skip':
             break
     return dict(
         ('cubicweb-' + cube, ServerConfiguration.cube_version(cube))
         for cube in depcubes)
Beispiel #11
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all" or \
                 match.group(1).strip() == 'skip-file':
             if match.group(1).strip() == "disable-all":
                 self.add_message('I0014', line=start[0])
             self.add_message('I0013', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('I0010', args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 # found a "(dis|en)able-msg" pragma deprecated suppresssion
                 self.add_message('deprecated-pragma', line=start[0])
             for msgid in splitstrip(value):
                 try:
                     if (opt, msgid) == ('disable', 'all'):
                         self.add_message('I0014', line=start[0])
                         self.add_message('I0013', line=start[0])
                         self._ignore_file = True
                         return
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('E0012', args=msgid, line=start[0])
         else:
             self.add_message('E0011', args=opt, line=start[0])
Beispiel #12
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     for (tok_type, content, start, _, _) in tokens:
         if tok_type != tokenize.COMMENT:
             continue
         match = OPTION_RGX.search(content)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all" or \
                 match.group(1).strip() == 'skip-file':
             if match.group(1).strip() == "disable-all":
                 self.add_message('deprecated-pragma', line=start[0],
                                  args=('disable-all', 'skip-file'))
             self.add_message('file-ignored', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('bad-inline-option', args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 # found a "(dis|en)able-msg" pragma deprecated suppresssion
                 self.add_message('deprecated-pragma', line=start[0], args=(opt, opt.replace('-msg', '')))
             for msgid in splitstrip(value):
                 try:
                     if (opt, msgid) == ('disable', 'all'):
                         self.add_message('deprecated-pragma', line=start[0], args=('disable=all', 'skip-file'))
                         self.add_message('file-ignored', line=start[0])
                         self._ignore_file = True
                         return
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('bad-option-value', args=msgid, line=start[0])
         else:
             self.add_message('unrecognized-inline-option', args=opt, line=start[0])
Beispiel #13
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all":
             self.add_message('I0013', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('I0010', args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         if opt in self._options_methods or opt in self._bw_options_methods:
             try:
                 meth = self._options_methods[opt]
             except KeyError:
                 meth = self._bw_options_methods[opt]
                 warn('%s is deprecated, replace it by %s (%s)' % (
                     opt, opt.split('-')[0], self.current_file),
                      DeprecationWarning)
             for msgid in splitstrip(value):
                 try:
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('E0012', args=msgid, line=start[0])
         else:
             self.add_message('E0011', args=opt, line=start[0])
Beispiel #14
0
 def iter_modified_fields(self, editedfields=None, entity=None):
     """return a generator on field that has been modified by the posted
     form.
     """
     if editedfields is None:
         try:
             editedfields = self._cw.form['_cw_fields']
         except KeyError:
             raise RequestError(self._cw._('no edited fields specified'))
     entityform = entity and len(inspect.getargspec(
         self.field_by_name)) == 4  # XXX
     for editedfield in splitstrip(editedfields):
         try:
             name, role = editedfield.split('-')
         except Exception:
             name = editedfield
             role = None
         if entityform:
             field = self.field_by_name(name, role, eschema=entity.e_schema)
         else:
             field = self.field_by_name(name, role)
         if field.has_been_modified(self):
             yield field
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     #line_num = 0
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         #if start[0] == line_num:
         #    continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all":
             self.add_message('I0013', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('I0010',
                              args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         #line_num = start[0]
         if opt in self._options_methods and not opt.endswith('-report'):
             meth = self._options_methods[opt]
             for msgid in splitstrip(value):
                 try:
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('E0012', args=msgid, line=start[0])
         else:
             self.add_message('E0011', args=opt, line=start[0])
Beispiel #16
0
 def process_tokens(self, tokens):
     """process tokens from the current module to search for module/block
     level options
     """
     comment = tokenize.COMMENT
     newline = tokenize.NEWLINE
     #line_num = 0
     for (tok_type, _, start, _, line) in tokens:
         if tok_type not in (comment, newline):
             continue
         #if start[0] == line_num:
         #    continue
         match = OPTION_RGX.search(line)
         if match is None:
             continue
         if match.group(1).strip() == "disable-all":
             self.add_message('I0013', line=start[0])
             self._ignore_file = True
             return
         try:
             opt, value = match.group(1).split('=', 1)
         except ValueError:
             self.add_message('I0010', args=match.group(1).strip(),
                              line=start[0])
             continue
         opt = opt.strip()
         #line_num = start[0]
         if opt in self._options_methods and not opt.endswith('-report'):
             meth = self._options_methods[opt]
             for msgid in splitstrip(value):
                 try:
                     meth(msgid, 'module', start[0])
                 except UnknownMessage:
                     self.add_message('E0012', args=msgid, line=start[0])
         else:
             self.add_message('E0011', args=opt, line=start[0])
Beispiel #17
0
 def cb_help_message(self, option, optname, value, parser):
     """optik callback for printing some help about a particular message"""
     self.linter.msgs_store.help_message(splitstrip(value))
     sys.exit(0)
Beispiel #18
0
class Run(object):
    """helper class to use as main for pylint :

    run(*sys.argv[1:])
    """
    LinterClass = PyLinter
    option_groups = (('Commands',
                      'Options which are actually commands. Options in this \
group are mutually exclusive.'), )

    def __init__(self, args, reporter=None, exit=True):
        self._rcfile = None
        self._plugins = []
        try:
            preprocess_options(
                args,
                {
                    # option: (callback, takearg)
                    'init-hook': (cb_init_hook, True),
                    'rcfile': (self.cb_set_rcfile, True),
                    'load-plugins': (self.cb_add_plugins, True),
                })
        except ArgumentPreprocessingError, ex:
            print >> sys.stderr, ex
            sys.exit(32)

        self.linter = linter = self.LinterClass((
            ('rcfile', {
                'action': 'callback',
                'callback': lambda *args: 1,
                'type': 'string',
                'metavar': '<file>',
                'help': 'Specify a configuration file.'
            }),
            ('init-hook', {
                'action':
                'callback',
                'callback':
                lambda *args: 1,
                'type':
                'string',
                'metavar':
                '<code>',
                'level':
                1,
                'help':
                'Python code to execute, usually for sys.path '
                'manipulation such as pygtk.require().'
            }),
            ('help-msg', {
                'action':
                'callback',
                'type':
                'string',
                'metavar':
                '<msg-id>',
                'callback':
                self.cb_help_message,
                'group':
                'Commands',
                'help':
                'Display a help message for the given message id and '
                'exit. The value may be a comma separated list of message ids.'
            }),
            ('list-msgs', {
                'action': 'callback',
                'metavar': '<msg-id>',
                'callback': self.cb_list_messages,
                'group': 'Commands',
                'level': 1,
                'help': "Generate pylint's messages."
            }),
            ('full-documentation', {
                'action': 'callback',
                'metavar': '<msg-id>',
                'callback': self.cb_full_documentation,
                'group': 'Commands',
                'level': 1,
                'help': "Generate pylint's full documentation."
            }),
            ('generate-rcfile', {
                'action':
                'callback',
                'callback':
                self.cb_generate_config,
                'group':
                'Commands',
                'help':
                'Generate a sample configuration file according to '
                'the current configuration. You can put other options '
                'before this one to get them in the generated '
                'configuration.'
            }),
            ('generate-man', {
                'action': 'callback',
                'callback': self.cb_generate_manpage,
                'group': 'Commands',
                'help': "Generate pylint's man page.",
                'hide': True
            }),
            ('errors-only', {
                'action':
                'callback',
                'callback':
                self.cb_error_mode,
                'short':
                'E',
                'help':
                'In error mode, checkers without error messages are '
                'disabled and for others, only the ERROR messages are '
                'displayed, and no reports are done by default'
                ''
            }),
            ('profile', {
                'type': 'yn',
                'metavar': '<y_or_n>',
                'default': False,
                'hide': True,
                'help': 'Profiled execution.'
            }),
        ),
                                                option_groups=self.
                                                option_groups,
                                                pylintrc=self._rcfile)
        # register standard checkers
        linter.load_default_plugins()
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section('Environment variables',
                                config.ENV_HELP,
                                level=1)
        # pylint: disable=bad-continuation
        linter.add_help_section(
            'Output',
            'Using the default text output, the message format is :                          \n'
            '                                                                                \n'
            '        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                \n'
            '                                                                                \n'
            'There are 5 kind of message types :                                             \n'
            '    * (C) convention, for programming standard violation                        \n'
            '    * (R) refactor, for bad code smell                                          \n'
            '    * (W) warning, for python specific problems                                 \n'
            '    * (E) error, for probable bugs in the code                                  \n'
            '    * (F) fatal, if an error occurred which prevented pylint from doing further\n'
            'processing.\n',
            level=1)
        linter.add_help_section(
            'Output status code',
            'Pylint should leave with following status code:                                 \n'
            '    * 0 if everything went fine                                                 \n'
            '    * 1 if a fatal message was issued                                           \n'
            '    * 2 if an error message was issued                                          \n'
            '    * 4 if a warning message was issued                                         \n'
            '    * 8 if a refactor message was issued                                        \n'
            '    * 16 if a convention message was issued                                     \n'
            '    * 32 on usage error                                                         \n'
            '                                                                                \n'
            'status 1 to 16 will be bit-ORed so you can know which different categories has\n'
            'been issued by analysing pylint output status code\n',
            level=1)
        # read configuration
        linter.disable('pointless-except')
        linter.disable('suppressed-message')
        linter.disable('useless-suppression')
        linter.read_config_file()
        config_parser = linter.cfgfile_parser
        # run init hook, if present, before loading plugins
        if config_parser.has_option('MASTER', 'init-hook'):
            cb_init_hook('init-hook',
                         unquote(config_parser.get('MASTER', 'init-hook')))
        # is there some additional plugins in the file configuration, in
        if config_parser.has_option('MASTER', 'load-plugins'):
            plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()
        if reporter:
            # if a custom reporter is provided as argument, it may be overridden
            # by file parameters, so re-set it here, but before command line
            # parsing so it's still overrideable by command line option
            linter.set_reporter(reporter)
        try:
            args = linter.load_command_line_configuration(args)
        except SystemExit, exc:
            if exc.code == 2:  # bad options
                exc.code = 32
            raise
Beispiel #19
0
 def cb_help_message(self, option, optname, value, parser):
     """optik callback for printing some help about a particular message"""
     self.linter.msgs_store.help_message(splitstrip(value))
     sys.exit(0)
Beispiel #20
0
 def cb_add_plugins(self, name, value):
     """callback for option preprocessing (i.e. before option parsing)"""
     self._plugins.extend(splitstrip(value))
Beispiel #21
0
 def run(self, args):
     """run the command with its specific arguments"""
     from logilab.common.textutils import splitstrip
     check_options_consistency(self.config)
     configname = self.config.config
     cubes, appid = args
     cubes = splitstrip(cubes)
     # get the configuration and helper
     config = cwcfg.config_for(appid, configname, creating=True)
     cubes = config.expand_cubes(cubes)
     config.init_cubes(cubes)
     helper = self.config_helper(config)
     # check the cube exists
     try:
         templdirs = [cwcfg.cube_dir(cube)
                      for cube in cubes]
     except ConfigurationError as ex:
         print(ex)
         print('\navailable cubes:', end=' ')
         print(', '.join(available_cube_names(cwcfg)))
         return
     # create the registry directory for this instance
     print('\n' + underline_title('Creating the instance %s' % appid))
     create_dir(config.apphome)
     # cubicweb-ctl configuration
     if not self.config.automatic:
         print('\n' + underline_title('Configuring the instance (%s.conf)'
                                      % configname))
         config.input_config('main', self.config.config_level)
     # configuration'specific stuff
     print()
     helper.bootstrap(cubes, self.config.automatic, self.config.config_level)
     # input for cubes specific options
     if not self.config.automatic:
         sections = set(sect.lower() for sect, opt, odict in config.all_options()
                        if 'type' in odict
                        and odict.get('level', 0) <= self.config.config_level)
         for section in sections:
             if section not in ('main', 'email', 'web'):
                 print('\n' + underline_title('%s options' % section))
                 config.input_config(section, self.config.config_level)
     # write down configuration
     config.save()
     print('-> generated config %s' % config.main_config_file())
     # handle i18n files structure
     # in the first cube given
     from cubicweb import i18n
     langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))]
     errors = config.i18ncompile(langs)
     if errors:
         print('\n'.join(errors))
         if self.config.automatic \
             or not ASK.confirm('error while compiling message catalogs, '
                                'continue anyway ?'):
             print('creation not completed')
             return
     # create the additional data directory for this instance
     if config.appdatahome != config.apphome:  # true in dev mode
         create_dir(config.appdatahome)
     create_dir(join(config.appdatahome, 'backup'))
     if config['uid']:
         from logilab.common.shellutils import chown
         # this directory should be owned by the uid of the server process
         print('set %s as owner of the data directory' % config['uid'])
         chown(config.appdatahome, config['uid'])
     print('\n-> creation done for %s\n' % repr(config.apphome)[1:-1])
     if not self.config.no_db_create:
         helper.postcreate(self.config.automatic, self.config.config_level)
Beispiel #22
0
    def __init__(self, args, reporter=None):
        self._rcfile = None
        self._plugins = []
        preprocess_options(args, {
            # option: (callback, takearg)
            'rcfile':       (self.cb_set_rcfile, True),
            'load-plugins': (self.cb_add_plugins, True),
            })
        self.linter = linter = self.LinterClass((
            ('rcfile',
             {'action' : 'callback', 'callback' : lambda *args: 1,
              'type': 'string', 'metavar': '<file>',
              'help' : 'Specify a configuration file.'}),

            ('init-hook',
             {'action' : 'callback', 'type' : 'string', 'metavar': '<code>',
              'callback' : cb_init_hook,
              'help' : 'Python code to execute, usually for sys.path \
manipulation such as pygtk.require().'}),

            ('help-msg',
             {'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>',
              'callback' : self.cb_help_message,
              'group': 'Commands',
              'help' : '''Display a help message for the given message id and \
exit. The value may be a comma separated list of message ids.'''}),

            ('list-msgs',
             {'action' : 'callback', 'metavar': '<msg-id>',
              'callback' : self.cb_list_messages,
              'group': 'Commands',
              'help' : "Generate pylint's messages."}),

            ('full-documentation',
             {'action' : 'callback', 'metavar': '<msg-id>',
              'callback' : self.cb_full_documentation,
              'group': 'Commands',
              'help' : "Generate pylint's full documentation."}),

            ('generate-rcfile',
             {'action' : 'callback', 'callback' : self.cb_generate_config,
              'group': 'Commands',
              'help' : '''Generate a sample configuration file according to \
the current configuration. You can put other options before this one to get \
them in the generated configuration.'''}),

            ('generate-man',
             {'action' : 'callback', 'callback' : self.cb_generate_manpage,
              'group': 'Commands',
              'help' : "Generate pylint's man page.",'hide': 'True'}),

            ('errors-only',
             {'action' : 'callback', 'callback' : self.cb_error_mode,
              'short': 'e',
              'help' : '''In error mode, checkers without error messages are \
disabled and for others, only the ERROR messages are displayed, and no reports \
are done by default'''}),

            ('profile',
             {'type' : 'yn', 'metavar' : '<y_or_n>',
              'default': False,
              'help' : 'Profiled execution.'}),

            ), option_groups=self.option_groups,
               reporter=reporter, pylintrc=self._rcfile)
        # register standard checkers
        from pylint import checkers
        checkers.initialize(linter)
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section('Environment variables', config.ENV_HELP)
        linter.add_help_section('Output', '''
Using the default text output, the message format is :                          
                                                                                
        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                
                                                                                
There are 5 kind of message types :                                             
    * (C) convention, for programming standard violation                        
    * (R) refactor, for bad code smell                                          
    * (W) warning, for python specific problems                                 
    * (E) error, for probable bugs in the code                                  
    * (F) fatal, if an error occurred which prevented pylint from doing further
processing.
        ''')
        linter.add_help_section('Output status code', '''
Pylint should leave with following status code:                                 
    * 0 if everything went fine                                                 
    * 1 if a fatal message was issued                                           
    * 2 if an error message was issued                                          
    * 4 if a warning message was issued                                         
    * 8 if a refactor message was issued                                        
    * 16 if a convention message was issued                                     
    * 32 on usage error                                                         
                                                                                
status 1 to 16 will be bit-ORed so you can know which different categories has
been issued by analysing pylint output status code
        ''')
        # read configuration
        linter.disable_message('W0704')
        linter.read_config_file()
        # is there some additional plugins in the file configuration, in
        config_parser = linter._config_parser
        if config_parser.has_option('MASTER', 'load-plugins'):
            plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()
        if reporter:
            # if a custom reporter is provided as argument, it may be overridden
            # by file parameters, so re-set it here, but before command line
            # parsing so it's still overrideable by command line option
            linter.set_reporter(reporter)
        args = linter.load_command_line_configuration(args)
        if not args:
            print linter.help()
            sys.exit(32)
        # insert current working directory to the python path to have a correct
        # behaviour
        sys.path.insert(0, os.getcwd())
        if self.linter.config.profile:
            print >> sys.stderr, '** profiled run'
            from hotshot import Profile, stats
            prof = Profile('stones.prof')
            prof.runcall(linter.check, args)
            prof.close()
            data = stats.load('stones.prof')
            data.strip_dirs()
            data.sort_stats('time', 'calls')
            data.print_stats(30)
        else:
            linter.check(args)
        sys.path.pop(0)
        sys.exit(self.linter.msg_status)
 def test_known(self):
     self.assertEqual(tu.splitstrip('a, b,c '), ['a', 'b', 'c'])
Beispiel #24
0
    def __init__(self, args, reporter=None, exit=True):
        self._rcfile = None
        self._plugins = []
        try:
            preprocess_options(args, {
                # option: (callback, takearg)
                'rcfile':       (self.cb_set_rcfile, True),
                'load-plugins': (self.cb_add_plugins, True),
                })
        except ArgumentPreprocessingError as ex:
            print('Argument %s expects a value.' % (ex.args[0],), file=sys.stderr)
            sys.exit(32)

        self.linter = linter = self.LinterClass((
            ('rcfile',
             {'action' : 'callback', 'callback' : lambda *args: 1,
              'type': 'string', 'metavar': '<file>',
              'help' : 'Specify a configuration file.'}),

            ('init-hook',
             {'action' : 'callback', 'type' : 'string', 'metavar': '<code>',
              'callback' : cb_init_hook, 'level': 1,
              'help' : 'Python code to execute, usually for sys.path \
manipulation such as pygtk.require().'}),

            ('help-msg',
             {'action' : 'callback', 'type' : 'string', 'metavar': '<msg-id>',
              'callback' : self.cb_help_message,
              'group': 'Commands',
              'help' : '''Display a help message for the given message id and \
exit. The value may be a comma separated list of message ids.'''}),

            ('list-msgs',
             {'action' : 'callback', 'metavar': '<msg-id>',
              'callback' : self.cb_list_messages,
              'group': 'Commands', 'level': 1,
              'help' : "Generate pylint's messages."}),

            ('full-documentation',
             {'action' : 'callback', 'metavar': '<msg-id>',
              'callback' : self.cb_full_documentation,
              'group': 'Commands', 'level': 1,
              'help' : "Generate pylint's full documentation."}),

            ('generate-rcfile',
             {'action' : 'callback', 'callback' : self.cb_generate_config,
              'group': 'Commands',
              'help' : '''Generate a sample configuration file according to \
the current configuration. You can put other options before this one to get \
them in the generated configuration.'''}),

            ('generate-man',
             {'action' : 'callback', 'callback' : self.cb_generate_manpage,
              'group': 'Commands',
              'help' : "Generate pylint's man page.", 'hide': True}),

            ('errors-only',
             {'action' : 'callback', 'callback' : self.cb_error_mode,
              'short': 'E',
              'help' : '''In error mode, checkers without error messages are \
disabled and for others, only the ERROR messages are displayed, and no reports \
are done by default'''}),

            ('profile',
             {'type' : 'yn', 'metavar' : '<y_or_n>',
              'default': False, 'hide': True,
              'help' : 'Profiled execution.'}),

            ), option_groups=self.option_groups, pylintrc=self._rcfile)
        # register standard checkers
        linter.load_default_plugins()
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section('Environment variables', config.ENV_HELP, level=1)
        linter.add_help_section('Output',
'Using the default text output, the message format is :                          \n'
'                                                                                \n'
'        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                \n'
'                                                                                \n'
'There are 5 kind of message types :                                             \n'
'    * (C) convention, for programming standard violation                        \n'
'    * (R) refactor, for bad code smell                                          \n'
'    * (W) warning, for python specific problems                                 \n'
'    * (E) error, for probable bugs in the code                                  \n'
'    * (F) fatal, if an error occurred which prevented pylint from doing further\n'
'processing.\n'
        , level=1)
        linter.add_help_section('Output status code',
'Pylint should leave with following status code:                                 \n'
'    * 0 if everything went fine                                                 \n'
'    * 1 if a fatal message was issued                                           \n'
'    * 2 if an error message was issued                                          \n'
'    * 4 if a warning message was issued                                         \n'
'    * 8 if a refactor message was issued                                        \n'
'    * 16 if a convention message was issued                                     \n'
'    * 32 on usage error                                                         \n'
'                                                                                \n'
'status 1 to 16 will be bit-ORed so you can know which different categories has\n'
'been issued by analysing pylint output status code\n',
        level=1)
        # read configuration
        linter.disable('W0704')
        linter.disable('I0020')
        linter.disable('I0021')
        linter.read_config_file()
        # is there some additional plugins in the file configuration, in
        config_parser = linter.cfgfile_parser
        if config_parser.has_option('MASTER', 'load-plugins'):
            plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()
        if reporter:
            # if a custom reporter is provided as argument, it may be overridden
            # by file parameters, so re-set it here, but before command line
            # parsing so it's still overrideable by command line option
            linter.set_reporter(reporter)
        try:
            args = linter.load_command_line_configuration(args)
        except SystemExit as exc:
            if exc.code == 2: # bad options
                exc.code = 32
            raise
        if not args:
            print(linter.help())
            sys.exit(32)
        # insert current working directory to the python path to have a correct
        # behaviour
        linter.prepare_import_path(args)
        if self.linter.config.profile:
            print('** profiled run', file=sys.stderr)
            import cProfile, pstats
            cProfile.runctx('linter.check(%r)' % args, globals(), locals(),
                            'stones.prof')
            data = pstats.Stats('stones.prof')
            data.strip_dirs()
            data.sort_stats('time', 'calls')
            data.print_stats(30)
        else:
            linter.check(args)
        linter.cleanup_import_path()
        if exit:
            sys.exit(self.linter.msg_status)
Beispiel #25
0
 def cb_add_plugins(self, name, value):
     """callback for option preprocessing (i.e. before option parsing)"""
     self._plugins.extend(splitstrip(value))
Beispiel #26
0
    def __init__(self, args, reporter=None, exit=True):
        self._rcfile = None
        self._plugins = []
        preprocess_options(
            args,
            {
                # option: (callback, takearg)
                "rcfile": (self.cb_set_rcfile, True),
                "load-plugins": (self.cb_add_plugins, True),
            },
        )
        self.linter = linter = self.LinterClass(
            (
                (
                    "rcfile",
                    {
                        "action": "callback",
                        "callback": lambda *args: 1,
                        "type": "string",
                        "metavar": "<file>",
                        "help": "Specify a configuration file.",
                    },
                ),
                (
                    "init-hook",
                    {
                        "action": "callback",
                        "type": "string",
                        "metavar": "<code>",
                        "callback": cb_init_hook,
                        "level": 1,
                        "help": "Python code to execute, usually for sys.path \
manipulation such as pygtk.require().",
                    },
                ),
                (
                    "help-msg",
                    {
                        "action": "callback",
                        "type": "string",
                        "metavar": "<msg-id>",
                        "callback": self.cb_help_message,
                        "group": "Commands",
                        "help": """Display a help message for the given message id and \
exit. The value may be a comma separated list of message ids.""",
                    },
                ),
                (
                    "list-msgs",
                    {
                        "action": "callback",
                        "metavar": "<msg-id>",
                        "callback": self.cb_list_messages,
                        "group": "Commands",
                        "level": 1,
                        "help": "Generate pylint's messages.",
                    },
                ),
                (
                    "full-documentation",
                    {
                        "action": "callback",
                        "metavar": "<msg-id>",
                        "callback": self.cb_full_documentation,
                        "group": "Commands",
                        "level": 1,
                        "help": "Generate pylint's full documentation.",
                    },
                ),
                (
                    "generate-rcfile",
                    {
                        "action": "callback",
                        "callback": self.cb_generate_config,
                        "group": "Commands",
                        "help": """Generate a sample configuration file according to \
the current configuration. You can put other options before this one to get \
them in the generated configuration.""",
                    },
                ),
                (
                    "generate-man",
                    {
                        "action": "callback",
                        "callback": self.cb_generate_manpage,
                        "group": "Commands",
                        "help": "Generate pylint's man page.",
                        "hide": True,
                    },
                ),
                (
                    "errors-only",
                    {
                        "action": "callback",
                        "callback": self.cb_error_mode,
                        "short": "E",
                        "help": """In error mode, checkers without error messages are \
disabled and for others, only the ERROR messages are displayed, and no reports \
are done by default""",
                    },
                ),
                (
                    "profile",
                    {
                        "type": "yn",
                        "metavar": "<y_or_n>",
                        "default": False,
                        "hide": True,
                        "help": "Profiled execution.",
                    },
                ),
            ),
            option_groups=self.option_groups,
            reporter=reporter,
            pylintrc=self._rcfile,
        )
        # register standard checkers
        from pylint import checkers

        checkers.initialize(linter)
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section("Environment variables", config.ENV_HELP, level=1)
        linter.add_help_section(
            "Output",
            """
Using the default text output, the message format is :                          
                                                                                
        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                
                                                                                
There are 5 kind of message types :                                             
    * (C) convention, for programming standard violation                        
    * (R) refactor, for bad code smell                                          
    * (W) warning, for python specific problems                                 
    * (E) error, for probable bugs in the code                                  
    * (F) fatal, if an error occurred which prevented pylint from doing further
processing.
        """,
            level=1,
        )
        linter.add_help_section(
            "Output status code",
            """
Pylint should leave with following status code:                                 
    * 0 if everything went fine                                                 
    * 1 if a fatal message was issued                                           
    * 2 if an error message was issued                                          
    * 4 if a warning message was issued                                         
    * 8 if a refactor message was issued                                        
    * 16 if a convention message was issued                                     
    * 32 on usage error                                                         
                                                                                
status 1 to 16 will be bit-ORed so you can know which different categories has
been issued by analysing pylint output status code
        """,
            level=1,
        )
        # read configuration
        linter.disable("W0704")
        linter.read_config_file()
        # is there some additional plugins in the file configuration, in
        config_parser = linter.cfgfile_parser
        if config_parser.has_option("MASTER", "load-plugins"):
            plugins = splitstrip(config_parser.get("MASTER", "load-plugins"))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()
        if reporter:
            # if a custom reporter is provided as argument, it may be overridden
            # by file parameters, so re-set it here, but before command line
            # parsing so it's still overrideable by command line option
            linter.set_reporter(reporter)
        args = linter.load_command_line_configuration(args)
        if not args:
            print linter.help()
            sys.exit(32)
        # insert current working directory to the python path to have a correct
        # behaviour
        sys.path.insert(0, os.getcwd())
        if self.linter.config.profile:
            print >> sys.stderr, "** profiled run"
            from hotshot import Profile, stats

            prof = Profile("stones.prof")
            prof.runcall(linter.check, args)
            prof.close()
            data = stats.load("stones.prof")
            data.strip_dirs()
            data.sort_stats("time", "calls")
            data.print_stats(30)
        else:
            linter.check(args)
        sys.path.pop(0)
        if exit:
            sys.exit(self.linter.msg_status)
 def test_known(self):
     self.assertEqual(tu.splitstrip('a, b,c '), ['a', 'b', 'c'])
    def __init__(self, args, reporter=None):
        self._rcfile = None
        self._plugins = []
        preprocess_options(
            args,
            {
                # option: (callback, takearg)
                'rcfile': (self.cb_set_rcfile, True),
                'load-plugins': (self.cb_add_plugins, True),
            })
        self.linter = linter = self.LinterClass(
            (
                ('rcfile', {
                    'action': 'callback',
                    'callback': lambda *args: 1,
                    'type': 'string',
                    'metavar': '<file>',
                    'help': 'Specify a configuration file.'
                }),
                ('init-hook', {
                    'action':
                    'callback',
                    'type':
                    'string',
                    'metavar':
                    '<code>',
                    'callback':
                    cb_init_hook,
                    'help':
                    'Python code to execute, usually for sys.path \
manipulation such as pygtk.require().'
                }),
                ('help-msg', {
                    'action':
                    'callback',
                    'type':
                    'string',
                    'metavar':
                    '<msg-id>',
                    'callback':
                    self.cb_help_message,
                    'group':
                    'Commands',
                    'help':
                    '''Display a help message for the given message id and \
exit. The value may be a comma separated list of message ids.'''
                }),
                ('list-msgs', {
                    'action': 'callback',
                    'metavar': '<msg-id>',
                    'callback': self.cb_list_messages,
                    'group': 'Commands',
                    'help': "Generate pylint's messages."
                }),
                ('full-documentation', {
                    'action': 'callback',
                    'metavar': '<msg-id>',
                    'callback': self.cb_full_documentation,
                    'group': 'Commands',
                    'help': "Generate pylint's full documentation."
                }),
                ('generate-rcfile', {
                    'action':
                    'callback',
                    'callback':
                    self.cb_generate_config,
                    'group':
                    'Commands',
                    'help':
                    '''Generate a sample configuration file according to \
the current configuration. You can put other options before this one to get \
them in the generated configuration.'''
                }),
                ('generate-man', {
                    'action': 'callback',
                    'callback': self.cb_generate_manpage,
                    'group': 'Commands',
                    'help': "Generate pylint's man page.",
                    'hide': 'True'
                }),
                ('errors-only', {
                    'action':
                    'callback',
                    'callback':
                    self.cb_error_mode,
                    'short':
                    'e',
                    'help':
                    '''In error mode, checkers without error messages are \
disabled and for others, only the ERROR messages are displayed, and no reports \
are done by default'''
                }),
                ('profile', {
                    'type': 'yn',
                    'metavar': '<y_or_n>',
                    'default': False,
                    'help': 'Profiled execution.'
                }),
            ),
            option_groups=self.option_groups,
            reporter=reporter,
            pylintrc=self._rcfile)
        # register standard checkers
        from pylint import checkers
        checkers.initialize(linter)
        # load command line plugins
        linter.load_plugin_modules(self._plugins)
        # add some help section
        linter.add_help_section('Environment variables', config.ENV_HELP)
        linter.add_help_section(
            'Output', '''
Using the default text output, the message format is :                          
                                                                                
        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                
                                                                                
There are 5 kind of message types :                                             
    * (C) convention, for programming standard violation                        
    * (R) refactor, for bad code smell                                          
    * (W) warning, for python specific problems                                 
    * (E) error, for probable bugs in the code                                  
    * (F) fatal, if an error occurred which prevented pylint from doing further
processing.
        ''')
        linter.add_help_section(
            'Output status code', '''
Pylint should leave with following status code:                                 
    * 0 if everything went fine                                                 
    * 1 if a fatal message was issued                                           
    * 2 if an error message was issued                                          
    * 4 if a warning message was issued                                         
    * 8 if a refactor message was issued                                        
    * 16 if a convention message was issued                                     
    * 32 on usage error                                                         
                                                                                
status 1 to 16 will be bit-ORed so you can know which different categories has
been issued by analysing pylint output status code
        ''')
        # read configuration
        linter.disable_message('W0704')
        linter.read_config_file()
        # is there some additional plugins in the file configuration, in
        config_parser = linter._config_parser
        if config_parser.has_option('MASTER', 'load-plugins'):
            plugins = splitstrip(config_parser.get('MASTER', 'load-plugins'))
            linter.load_plugin_modules(plugins)
        # now we can load file config and command line, plugins (which can
        # provide options) have been registered
        linter.load_config_file()
        if reporter:
            # if a custom reporter is provided as argument, it may be overridden
            # by file parameters, so re-set it here, but before command line
            # parsing so it's still overrideable by command line option
            linter.set_reporter(reporter)
        args = linter.load_command_line_configuration(args)
        if not args:
            print linter.help()
            sys.exit(32)
        # insert current working directory to the python path to have a correct
        # behaviour
        sys.path.insert(0, os.getcwd())
        if self.linter.config.profile:
            print >> sys.stderr, '** profiled run'
            from hotshot import Profile, stats
            prof = Profile('stones.prof')
            prof.runcall(linter.check, args)
            prof.close()
            data = stats.load('stones.prof')
            data.strip_dirs()
            data.sort_stats('time', 'calls')
            data.print_stats(30)
        else:
            linter.check(args)
        sys.path.pop(0)
        sys.exit(self.linter.msg_status)