Beispiel #1
0
    def __init__(self, patch=None, patchwork_id=None, github_id=None, vcs=None,
                 confirm=False):
        self.confirm = confirm
        self.base_dir = os.getcwd()

        if patch:
            self.patch = os.path.abspath(patch)

        if patchwork_id:
            self.patch = self._fetch_from_patchwork(patchwork_id)

        if github_id:
            self.patch = self._fetch_from_github(github_id)

        if not os.path.isfile(self.patch):
            logging.error("Invalid patch file %s provided. Aborting.",
                          self.patch)
            sys.exit(1)

        self.vcs = vcs
        changed_files_before = self.vcs.get_modified_files()
        if changed_files_before:
            logging.error("Repository has changed files prior to patch "
                          "application. ")
            answer = utils.ask("Would you like to revert them?", auto=self.confirm)
            if answer == "n":
                logging.error("Not safe to proceed without reverting files.")
                sys.exit(1)
            else:
                for changed_file in changed_files_before:
                    self.vcs.revert_file(changed_file)

        self.untracked_files_before = self.vcs.get_unknown_files()
        self.vcs.update()
Beispiel #2
0
    def _check_files_modified_patch(self):
        untracked_files_after = self.vcs.get_unknown_files()
        modified_files_after = self.vcs.get_modified_files()
        add_to_vcs = []
        for untracked_file in untracked_files_after:
            if untracked_file not in self.untracked_files_before:
                add_to_vcs.append(untracked_file)

        if add_to_vcs:
            logging.info("The files: ")
            for untracked_file in add_to_vcs:
                logging.info(untracked_file)
            logging.info("Might need to be added to VCS")
            answer = utils.ask("Would you like to add them to VCS ?")
            if answer == "y":
                for untracked_file in add_to_vcs:
                    self.vcs.add_untracked_file(untracked_file)
                    modified_files_after.append(untracked_file)
            elif answer == "n":
                pass

        for modified_file in modified_files_after:
            # Additional safety check, new commits might introduce
            # new directories
            if os.path.isfile(modified_file):
                file_checker = FileChecker(modified_file)
                file_checker.report()
Beispiel #3
0
    def _check_files_modified_patch(self):
        untracked_files_after = self.vcs.get_unknown_files()
        modified_files_after = self.vcs.get_modified_files()
        add_to_vcs = []
        for untracked_file in untracked_files_after:
            if untracked_file not in self.untracked_files_before:
                add_to_vcs.append(untracked_file)

        if add_to_vcs:
            logging.info("The files: ")
            for untracked_file in add_to_vcs:
                logging.info(untracked_file)
            logging.info("Might need to be added to VCS")
            answer = utils.ask("Would you like to add them to VCS ?")
            if answer == "y":
                for untracked_file in add_to_vcs:
                    self.vcs.add_untracked_file(untracked_file)
                    modified_files_after.append(untracked_file)
            elif answer == "n":
                pass

        for modified_file in modified_files_after:
            # Additional safety check, new commits might introduce
            # new directories
            if os.path.isfile(modified_file):
                file_checker = FileChecker(modified_file)
                file_checker.report()
Beispiel #4
0
    def __init__(self, patch=None, patchwork_id=None, confirm=False):
        self.confirm = confirm
        self.base_dir = os.getcwd()
        if patch:
            self.patch = os.path.abspath(patch)
        if patchwork_id:
            self.patch = self._fetch_from_patchwork(patchwork_id)

        if not os.path.isfile(self.patch):
            logging.error("Invalid patch file %s provided. Aborting.",
                          self.patch)
            sys.exit(1)

        self.vcs = VCS()
        changed_files_before = self.vcs.get_modified_files()
        if changed_files_before:
            logging.error("Repository has changed files prior to patch "
                          "application. ")
            answer = utils.ask("Would you like to revert them?",
                               auto=self.confirm)
            if answer == "n":
                logging.error("Not safe to proceed without reverting files.")
                sys.exit(1)
            else:
                for changed_file in changed_files_before:
                    self.vcs.revert_file(changed_file)

        self.untracked_files_before = self.vcs.get_unknown_files()
        self.vcs.update()
Beispiel #5
0
 def report(self):
     """
     Executes all required checks, if problems are found, the possible
     corrective actions are listed.
     """
     self._check_permissions()
     if self.is_python:
         self._check_indent()
         self._check_code()
         self._check_unittest()
     if self.corrective_actions:
         for action in self.corrective_actions:
             answer = utils.ask("Would you like to execute %s?" % action,
                                auto=self.confirm)
             if answer == "y":
                 rc = utils.system(action, ignore_status=True)
                 if rc != 0:
                     logging.error("Error executing %s" % action)
Beispiel #6
0
 def report(self):
     """
     Executes all required checks, if problems are found, the possible
     corrective actions are listed.
     """
     self._check_permissions()
     if self.is_python:
         self._check_indent()
         self._check_code()
         self._check_unittest()
     if self.corrective_actions:
         for action in self.corrective_actions:
             answer = utils.ask("Would you like to execute %s?" % action,
                                auto=self.confirm)
             if answer == "y":
                 rc = utils.system(action, ignore_status=True)
                 if rc != 0:
                     logging.error("Error executing %s" % action)
Beispiel #7
0
    def _check_files_modified_patch(self):
        modified_files_after = []
        if self.vcs.type == "subversion":
            untracked_files_after = self.vcs.get_unknown_files()
            modified_files_after = self.vcs.get_modified_files()
            add_to_vcs = []
            for untracked_file in untracked_files_after:
                if untracked_file not in self.untracked_files_before:
                    add_to_vcs.append(untracked_file)

            if add_to_vcs:
                logging.info("The files: ")
                for untracked_file in add_to_vcs:
                    logging.info(untracked_file)
                logging.info("Might need to be added to VCS")
                answer = utils.ask("Would you like to add them to VCS ?")
                if answer == "y":
                    for untracked_file in add_to_vcs:
                        self.vcs.add_untracked_file(untracked_file)
                        modified_files_after.append(untracked_file)
                elif answer == "n":
                    pass
        elif self.vcs.type == "git":
            patch = open(self.patch)
            for line in patch.readlines():
                if line.startswith("diff --git"):
                    m_file = line.split()[-1][2:]
                    if m_file not in modified_files_after:
                        modified_files_after.append(m_file)
            patch.close()

        for modified_file in modified_files_after:
            # Additional safety check, new commits might introduce
            # new directories
            if os.path.isfile(modified_file):
                file_checker = FileChecker(path=modified_file,
                                           vcs=self.vcs,
                                           confirm=self.confirm)
                file_checker.report()
Beispiel #8
0
    def _check_files_modified_patch(self):
        modified_files_after = []
        if self.vcs.type == "subversion":
            untracked_files_after = self.vcs.get_unknown_files()
            modified_files_after = self.vcs.get_modified_files()
            add_to_vcs = []
            for untracked_file in untracked_files_after:
                if untracked_file not in self.untracked_files_before:
                    add_to_vcs.append(untracked_file)

            if add_to_vcs:
                logging.info("The files: ")
                for untracked_file in add_to_vcs:
                    logging.info(untracked_file)
                logging.info("Might need to be added to VCS")
                answer = utils.ask("Would you like to add them to VCS ?")
                if answer == "y":
                    for untracked_file in add_to_vcs:
                        self.vcs.add_untracked_file(untracked_file)
                        modified_files_after.append(untracked_file)
                elif answer == "n":
                    pass
        elif self.vcs.type == "git":
            patch = open(self.patch)
            for line in patch.readlines():
                if line.startswith("diff --git"):
                    m_file = line.split()[-1][2:]
                    if m_file not in modified_files_after:
                        modified_files_after.append(m_file)
            patch.close()

        for modified_file in modified_files_after:
            # Additional safety check, new commits might introduce
            # new directories
            if os.path.isfile(modified_file):
                file_checker = FileChecker(path=modified_file, vcs=self.vcs,
                                           confirm=self.confirm)
                file_checker.report()