Ejemplo n.º 1
0
    def _rubocop(self,
                 serverspec_dir,
                 debug=False,
                 env=os.environ.copy(),
                 pattern='/**/*.rb',
                 out=LOG.info,
                 err=LOG.error):
        """
        Runs rubocop against specified directory with specified pattern.

        :param serverspec_dir: Directory to search for files to lint
        :param debug: Pass debug flag to rubocop
        :param pattern: Search pattern to pass to rubocop
        :param env: Environment to pass to underlying sh call
        :param out: Function to process STDOUT for underlying sh call
        :param err: Function to process STDERR for underlying sh call
        :return: sh response object
        """
        kwargs = {'_env': env, '_out': out, '_err': err, 'debug': debug}

        if 'HOME' not in kwargs['_env']:
            kwargs['_env']['HOME'] = os.path.expanduser('~')

        msg = 'Executing rubocop on *.rb files found in {}/.'.format(
            serverspec_dir)
        util.print_info(msg)
        match = serverspec_dir + pattern

        return sh.rubocop(match, **kwargs)
Ejemplo n.º 2
0
    def _rubocop(self,
                 serverspec_dir,
                 debug=False,
                 env=os.environ.copy(),
                 pattern='/**/*.rb',
                 out=LOG.info,
                 err=LOG.error):
        """
        Executes rubocop against specified directory/pattern, and returns a
        :func:`sh` response object.

        :param serverspec_dir: A string containing the directory with files
        to lint.
        :param debug: An optional bool to toggle debug output.
        :param pattern: A string containing the pattern of files to lint.
        :param env: An optional environment to pass to underlying :func:`sh`
         call.
        :param out: An optional function to process STDOUT for underlying
         :func:`sh` call.
        :param err: An optional function to process STDERR for underlying
         :func:`sh` call.
        :return: :func:`sh` response object.
        """
        kwargs = {'_env': env, '_out': out, '_err': err, 'debug': debug}

        msg = 'Executing rubocop on *.rb files found in {}/.'.format(
            serverspec_dir)
        util.print_info(msg)
        match = serverspec_dir + pattern

        return sh.rubocop(match, **kwargs)
Ejemplo n.º 3
0
    def _rubocop(self,
                 serverspec_dir,
                 debug=False,
                 pattern='/**/*.rb',
                 out=LOG.info,
                 err=LOG.error):
        """
        Executes rubocop against specified directory/pattern, and returns a
        :func:`sh` response object.

        :param serverspec_dir: A string containing the directory with files
        to lint.
        :param debug: An optional bool to toggle debug output.
        :param pattern: A string containing the pattern of files to lint.
        :param out: An optional function to process STDOUT for underlying
         :func:`sh` call.
        :param err: An optional function to process STDERR for underlying
         :func:`sh` call.
        :return: :func:`sh` response object.
        """
        kwargs = {'_out': out, '_err': err, 'debug': debug}

        msg = 'Executing rubocop on *.rb files found in {}/.'.format(
            serverspec_dir)
        util.print_info(msg)
        match = serverspec_dir + pattern

        return sh.rubocop(match, **kwargs)
Ejemplo n.º 4
0
 def _rubocop(self):
     try:
         pattern = self._config.config['molecule']['serverspec_dir'] + '/**/*.rb'
         output = sh.rubocop(pattern, _env=self._env, _out=utilities.print_stdout, _err=utilities.print_stderr)
         return output.exit_code
     except sh.ErrorReturnCode as e:
         print('ERROR: {}'.format(e))
         sys.exit(e.exit_code)
Ejemplo n.º 5
0
 def _rubocop(self):
     try:
         pattern = self._config['serverspec_dir'] + '/**/*.rb'
         output = sh.rubocop(pattern, _env=self._env, _out=self._print_line, _err=self._print_line)
         return output.exit_code
     except sh.ErrorReturnCode as e:
         print("ERROR: {0}".format(e))
         sys.exit(e.exit_code)
Ejemplo n.º 6
0
 def _rubocop(self):
     try:
         pattern = self._config['serverspec_dir'] + '/**/*.rb'
         output = sh.rubocop(pattern, _env=self._env, _out=self._print_line, _err=self._print_line)
         return output.exit_code
     except sh.ErrorReturnCode as e:
         print("ERROR: {0}".format(e))
         sys.exit(e.exit_code)
Ejemplo n.º 7
0
def rubocop(serverspec_dir,
            debug=False,
            env=os.environ.copy(),
            pattern='/**/*.rb',
            out=utilities.logger.warning,
            err=utilities.logger.error):
    """
    Runs rubocop against specified directory with specified pattern

    :param serverspec_dir: Directory to search for files to lint
    :param debug: Pass debug flag to rubocop
    :param pattern: Search pattern to pass to rubocop
    :param env: Environment to pass to underlying sh call
    :param out: Function to process STDOUT for underlying sh call
    :param err: Function to process STDERR for underlying sh call
    :return: sh response object
    """
    kwargs = {'_env': env, '_out': out, '_err': err, 'debug': debug}

    if 'HOME' not in kwargs['_env']:
        kwargs['_env']['HOME'] = os.path.expanduser('~')

    match = serverspec_dir + pattern
    return sh.rubocop(match, **kwargs)