Exemplo n.º 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()
Exemplo n.º 2
0
 def confirm_initialization(self):
     if not self.force:
         response = utils.ask(
             'Your %s database does not appear to be initialized.  Do you '
             'want to recreate it (this will result in loss of any existing '
             'data) (yes/No)? ' % self.get_db_name())
         if response != 'yes':
             raise Exception('User has chosen to abort migration')
Exemplo n.º 3
0
 def confirm_initialization(self):
     if not self.force:
         response = utils.ask(
             'Your %s database does not appear to be initialized.  Do you '
             'want to recreate it (this will result in loss of any existing '
             'data) (yes/No)? ' % self.get_db_name())
         if response != 'yes':
             raise Exception('User has chosen to abort migration')
Exemplo n.º 4
0
    def __init__(self,
                 patch=None,
                 patchwork_id=None,
                 github_id=None,
                 pwhost=None,
                 vcs=None,
                 confirm=False):
        self.confirm = confirm
        self.files_failed_check = []
        self.base_dir = os.getcwd()
        if pwhost is None:
            self.pwhost = PWHOST
        else:
            self.pwhost = pwhost

        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()
Exemplo n.º 5
0
    def _check_files_modified_patch(self):
        modified_files_after = []
        files_failed_check = []
        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)
                if not file_checker.report():
                    files_failed_check.append(modified_file)
        if files_failed_check:
            return (False, files_failed_check)
        else:
            return (True, [])
Exemplo n.º 6
0
    def _check_files_modified_patch(self):
        modified_files_after = []
        files_failed_check = []
        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)
                if not file_checker.report():
                    files_failed_check.append(modified_file)
        if files_failed_check:
            return (False, files_failed_check)
        else:
            return (True, [])
Exemplo n.º 7
0
 def report(self, skip_unittest=False):
     """
     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()
         if not skip_unittest:
             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)
Exemplo n.º 8
0
 def report(self, skip_unittest=False):
     """
     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()
         if not skip_unittest:
             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)