Beispiel #1
0
    def __init__(self, maintainerfile):
        self._maintainerfile = os.path.expandvars(maintainerfile)
        self._maintainer_entrys = []
        self._env_parser = EnvParser.EnvPathParser()

        try:
            file_ = codecs.open(self._maintainerfile, encoding='utf-8', mode='r')
        except IOError:
            logger.critical("Could not open %s this should be impossible at this stage!", self._maintainerfile)
            exit(-1)

        maintainerfile = []

        # Filter out empty lines and comments
        while 1:
            lines = file_.readlines()
            if not lines:
                break
            for line in lines:
                if len(line.lstrip()) != 0:
                    if line.lstrip()[0] != '#':
                        maintainerfile.append(line.strip().encode('utf-8'))
        self._read_maintainer_scopes(maintainerfile)
        self._verify_paths()
        self._tree = self._make_rule_tree()
Beispiel #2
0
    def find_all_defects(self, file_, since_date=None, changeinfo=False):
        """
        Finds all defects for file_, this is achieved by:
        _git:
        Parsing status line (or Activity tag) matching something in the line of GGSN----- or defect----.
        CC:
        Parsing branchname looking for name matching something in the line of GGSN----- or defect----.

        Args:
            file_(str): The file to lookup defects on
            since_date(datetime): Only return defect commits created since since_date
            changeinfo(bool): If enabled, performs diff for each defect including changed-function metrics
        Returns:
            dict(defect_ud): entry['version'](str): file element id (CC = elemid, _git = commit hash)
                             entry['datetime'](datetime): creation date for element
                             entry['user'](str): user who created element
                             entry['functions'](list[str]) : list of functions (changed classes/functions)
                                                            only available if changeinfo=True
                             ---- _git specific elements ----
                             entry['email'](str): email of user
                             entry['subject'](str): subject of commit
                             entry['is_root'](bool): Indicating that this is the first version in the tree
        Raises:
            None
        """
        defects = self._find_defects_in_commit_history(file_, since_date)
        if changeinfo:
            for defect_list in defects.itervalues():
                for defect in defect_list:
                    version = defect['version']
                    filealias = defect['filealias']
                    '''
                    This awkwardness is due to that in python2, __file__ points to the compiled file.
                    While, git can only accept a single binary as --extcmd, therefore its not possible to
                    do the "python PyDiffer.pyc" version of things. Instead we point directly to PyDiffer
                    relying on that the shell will correctly identify this as a python file (this may not work
                    in windows).
                    '''
                    pydiffer = PyDiffer.__file__
                    if pydiffer.endswith('c'):
                        pydiffer = pydiffer[:-1]

                    args = [
                        'difftool', '-M', '--no-prompt',
                        '--extcmd="' + os.path.realpath(pydiffer) + '"'
                    ]
                    args += [version + "^!", "--", filealias]
                    output = self._git(args)
                    try:
                        stats = pickle.loads(output)
                    except EOFError:
                        logger.critical(
                            "Cought EOFError from pickle when executing:%s",
                            'git ' + ' '.join(args))
                        defect['functions'] = []
                    else:
                        defect['functions'] = list(stats.iterkeys())
        return defects
Beispiel #3
0
    def find_all_defects(self, file_, since_date=None, changeinfo=False):
        """
        Finds all defects for file_, this is achieved by:
        _git:
        Parsing status line (or Activity tag) matching something in the line of GGSN----- or defect----.
        CC:
        Parsing branchname looking for name matching something in the line of GGSN----- or defect----.

        Args:
            file_(str): The file to lookup defects on
            since_date(datetime): Only return defect commits created since since_date
            changeinfo(bool): If enabled, performs diff for each defect including changed-function metrics
        Returns:
            dict(defect_ud): entry['version'](str): file element id (CC = elemid, _git = commit hash)
                             entry['datetime'](datetime): creation date for element
                             entry['user'](str): user who created element
                             entry['functions'](list[str]) : list of functions (changed classes/functions)
                                                            only available if changeinfo=True
                             ---- _git specific elements ----
                             entry['email'](str): email of user
                             entry['subject'](str): subject of commit
                             entry['is_root'](bool): Indicating that this is the first version in the tree
        Raises:
            None
        """
        self._setup_git(file_)
        defects = self._find_defects_in_commit_history(file_, since_date)
        if changeinfo:
            for defect_list in defects.itervalues():
                for defect in defect_list:
                    version = defect['version']
                    filealias = defect['filealias']

                    '''
                    This awkwardness is due to that in python2, __file__ points to the compiled file.
                    While, git can only accept a single binary as --extcmd, therefore its not possible to
                    do the "python PyDiffer.pyc" version of things. Instead we point directly to PyDiffer
                    relying on that the shell will correctly identify this as a python file (this may not work
                    in windows).
                    '''
                    pydiffer = PyDiffer.__file__
                    if pydiffer.endswith('c'):
                        pydiffer = pydiffer[:-1]

                    args = ['difftool', '-M', '--no-prompt',
                            '--extcmd="' + os.path.realpath(pydiffer) + '"']
                    args += [version + "^!", "--", filealias]
                    output = self._git(args)
                    try:
                        stats = pickle.loads(output)
                    except EOFError:
                        logger.critical("Cought EOFError from pickle when executing:%s", 'git ' + ' '.join(args))
                        defect['functions'] = []
                    else:
                        defect['functions'] = list(stats.iterkeys())
        return defects
Beispiel #4
0
def VcsFactory(config, **kwargs):
    '''
    Factory for creating a VCS instance, basically checks vcs_config against known classes and then creates an instance
    '''
    vcs_mapping = {'ClearCase': ClearCase.ClearCase, 'Git': Git.Git}

    vcs_config = config.get_vcs()
    try:
        return vcs_mapping[vcs_config](config, **kwargs)
    except KeyError:
        logger.critical("Unknown VCS %s" % vcs_config)
Beispiel #5
0
def VcsFactory(config, **kwargs):
    '''
    Factory for creating a VCS instance, basically checks vcs_config against known classes and then creates an instance
    '''
    vcs_mapping = {'ClearCase': ClearCase.ClearCase,
                   'Git': Git.Git}

    vcs_config = config.get_vcs()
    try:
        return vcs_mapping[vcs_config](config, **kwargs)
    except KeyError:
        logger.critical("Unknown VCS %s" % vcs_config)
Beispiel #6
0
    def _verify_paths(self):
        is_ok = True
        all_envs = {}
        for path in self._srcroots_include:
            match = re.match(r'.*\$(\w+).*', path)
            if match is not None and match.group(1) is not None:
                all_envs[match.group(1)] = None

        for env in all_envs.iterkeys():
            if env not in os.environ:
                logger.critical("Could not find $%s envrionment variable!", env)
                is_ok = False

        assert is_ok
Beispiel #7
0
    def __init__(self, config=default_config):
        SafeConfigParser.__init__(self)

        self.config = config
        self.defaults = defaults

        if not self._read_config():
            logger.critical('Could not find %s, creating new %s' % (self.config, default_config))
            shutil.copy(default_config_template, default_config)
            logger.critical('Please update %s accordingly!', default_config)
            raise ConfigValidationException

        self._populate_defaults()
        self._validate_config()
Beispiel #8
0
    def __init__(self, config=default_config):
        SafeConfigParser.__init__(self)

        self.config = config
        self.defaults = defaults

        if not self._read_config():
            logger.critical('Could not find %s, creating new %s' %
                            (self.config, default_config))
            shutil.copy(default_config_template, default_config)
            logger.critical('Please update %s accordingly!', default_config)
            raise ConfigValidationException

        self._populate_defaults()
        self._validate_config()
Beispiel #9
0
    def _verify_paths(self):
        is_ok = True
        all_envs = {}
        for path in self._srcroots_include:
            match = re.match(r'.*\$(\w+).*', path)
            if match is not None and match.group(1) is not None:
                all_envs[match.group(1)] = None

        for env in all_envs.iterkeys():
            if env not in os.environ:
                logger.critical("Could not find $%s envrionment variable!",
                                env)
                is_ok = False

        assert is_ok
Beispiel #10
0
    def _validate_config(self):
        '''
        Validates the entire project. Each sub validator should print errors as logger.critical and raise AssertionError
        The reason for why we catch it is that we want to print ALL errors before exiting, so that user dont have
        continously iterate like update->run->update->run.
        '''
        sub_validators = [self._validate_vcs]
        success = True

        for validator in sub_validators:
            try:
                validator()
            except AssertionError:
                success = False

        if success is False:
            logger.critical('Validation of %s failed, exiting!' % self.config)
            raise ConfigValidationException
Beispiel #11
0
    def _validate_config(self):
        '''
        Validates the entire project. Each sub validator should print errors as logger.critical and raise AssertionError
        The reason for why we catch it is that we want to print ALL errors before exiting, so that user dont have
        continously iterate like update->run->update->run.
        '''
        sub_validators = [self._validate_vcs]
        success = True

        for validator in sub_validators:
            try:
                validator()
            except AssertionError:
                success = False

        if success is False:
            logger.critical('Validation of %s failed, exiting!' % self.config)
            raise ConfigValidationException
Beispiel #12
0
    def verify_if_files_exist_in_srcroot_paths(self, files):
        """
        Verify:s if files exists one way or another in the src-root-paths.
        Args:
            files(list): the list of files to verify
        Returns:
            found_files(list): list of files that is found inside include-paths, and not excluded.
        Raises:
            None
            Exits application if file does not seem to physically exist
        """
        local_files = []
        # First validation on absolute paths and that file do exist within the SRC_PATH
        for file_ in files:
            is_exists = False
            do_skip = False

            # First check if file contains any of the src-root-path exclude entrys
            for path in self._srcroots_exclude:
                if path in file_:
                    logger.critical(
                        "Skipping %s since it resides within exclude path %s",
                        file_, path)
                    do_skip = True
                    break

            if do_skip:
                continue

            # First check if file contains any of the src-root-path include entrys
            for path in self._srcroots_include:
                if path in file_ and os.path.exists(file_):
                    is_exists = True
                    break

            if not is_exists:
                logger.critical("%s does not seem to exist!", file_)
                exit(1)

            local_files.append(file_)
        return local_files
Beispiel #13
0
    def _verify_paths(self):
        is_ok = True

        filepaths = []
        for maint in self.get_maintainer_list():
            filepaths.extend(maint['file-include-pattern'])
            filepaths.extend(maint['file-exclude-pattern'])

        all_envs = {}
        for path in filepaths:
            match = re.match(r'.*\$(\w+).*', path)
            if match is not None and match.group(1) is not None:
                all_envs[match.group(1)] = None

        for env in all_envs.iterkeys():
            if env not in os.environ:
                logger.critical("Could not find $%s envrionment variable! Perhaps you need to run setup_workspace?",
                                env)
                is_ok = False

        assert is_ok
Beispiel #14
0
    def _verify_paths(self):
        is_ok = True

        filepaths = []
        for maint in self.get_maintainer_list():
            filepaths.extend(maint['file-include-pattern'])
            filepaths.extend(maint['file-exclude-pattern'])

        all_envs = {}
        for path in filepaths:
            match = re.match(r'.*\$(\w+).*', path)
            if match is not None and match.group(1) is not None:
                all_envs[match.group(1)] = None

        for env in all_envs.iterkeys():
            if env not in os.environ:
                logger.critical("Could not find $%s envrionment variable! Perhaps you need to run setup_workspace?",
                                env)
                is_ok = False

        assert is_ok
Beispiel #15
0
    def verify_if_files_exist_in_srcroot_paths(self, files):
        """
        Verify:s if files exists one way or another in the src-root-paths.
        Args:
            files(list): the list of files to verify
        Returns:
            found_files(list): list of files that is found inside include-paths, and not excluded.
        Raises:
            None
            Exits application if file does not seem to physically exist
        """
        local_files = []
        # First validation on absolute paths and that file do exist within the SRC_PATH
        for file_ in files:
            is_exists = False
            do_skip = False

            # First check if file contains any of the src-root-path exclude entrys
            for path in self._srcroots_exclude:
                if path in file_:
                    logger.critical("Skipping %s since it resides within exclude path %s", file_, path)
                    do_skip = True
                    break

            if do_skip:
                continue

            # First check if file contains any of the src-root-path include entrys
            for path in self._srcroots_include:
                if path in file_ and os.path.exists(file_):
                    is_exists = True
                    break

            if not is_exists:
                logger.critical("%s does not seem to exist!", file_)
                exit(1)

            local_files.append(file_)
        return local_files
Beispiel #16
0
 def __call__(self, *args, **kwargs):
     try:
         return self.func(*args, **kwargs)
     except Exception as e:  # pylint: disable=W0703
         logger.critical(traceback.format_exc())
         logger.critical("Cought exception in worker %s", e)
         logger.critical("Args: %s", args)
         exit(-1)
Beispiel #17
0
 def __call__(self, *args, **kwargs):
     try:
         return self.func(*args, **kwargs)
     except Exception as e:  # pylint: disable=W0703
         logger.critical(traceback.format_exc())
         logger.critical("Cought exception in worker %s", e)
         logger.critical("Args: %s", args)
         exit(-1)
Beispiel #18
0
    def __init__(self, maintainerfile):
        self._maintainerfile = os.path.expandvars(maintainerfile)
        self._maintainer_entrys = []
        self._env_parser = EnvParser.EnvPathParser()

        try:
            file_ = codecs.open(self._maintainerfile, encoding='utf-8', mode='r')
        except IOError:
            logger.critical("Could not open %s this should be impossible at this stage!", self._maintainerfile)
            exit(-1)

        maintainerfile = []

        # Filter out empty lines and comments
        while 1:
            lines = file_.readlines()
            if not lines:
                break
            for line in lines:
                if len(line.lstrip()) != 0:
                    if line.lstrip()[0] != '#':
                        maintainerfile.append(line.strip().encode('utf-8'))
        self._read_maintainer_scopes(maintainerfile)
        self._verify_paths()
Beispiel #19
0
    def _validate_vcs(self):
        vcs_backends = [vcs for vcs in ProjectConfig.vcs_types if self.has_section(vcs)]
        if len(vcs_backends) >= 2:
            logger.critical('Found multiple entries for VCS backends, make sure you only have one!')
            logger.critical('VCS backends %s' % ",".join(vcs_backends))
            raise AssertionError

        if len(vcs_backends) <= 0:
            logger.critical('Found NO VCS backends, you must have atleast one!')
            raise AssertionError
Beispiel #20
0
    def _validate_vcs(self):
        vcs_backends = [
            vcs for vcs in ProjectConfig.vcs_types if self.has_section(vcs)
        ]
        if len(vcs_backends) >= 2:
            logger.critical(
                'Found multiple entries for VCS backends, make sure you only have one!'
            )
            logger.critical('VCS backends %s' % ",".join(vcs_backends))
            raise AssertionError

        if len(vcs_backends) <= 0:
            logger.critical(
                'Found NO VCS backends, you must have atleast one!')
            raise AssertionError