Пример #1
0
 def process(self, msg):
     """All task's work is done here."""
     self.debug("processing")
     run_cmd(["sleep", "1"])  # Hardly working on it
     # make sure there are no files from previous run
     assert not listdir(self.tmpdir.name)
     _, self.tmpfile = mkstemp(dir=self.tmpdir.name)
     self.error("error message example")
     return f"Hello, I'm FooBarBot. {msg}"
Пример #2
0
    def call_git_cmd(cmd,
                     return_output=True,
                     msg=None,
                     git_dir=None,
                     shell=True):
        """
        Runs the GIT command with specified arguments
        :param cmd: list or string, git subcommand for execution
        :param return_output: bool, return output of the command ?
        :param msg: log this before running the command
        :param git_dir: run the command in another directory
        :param shell: bool, run git commands in shell by default
        :return: output of the git command
        """
        if msg:
            logger.info(msg)

        command = 'git'
        # use git_dir as work-tree git parameter and git-dir parameter (with added git.postfix)
        if git_dir:
            command += f" --git-dir {git_dir}/.git"
            command += f" --work-tree {git_dir}"
        if isinstance(cmd, str):
            command += f" {cmd}"
        elif isinstance(cmd, list):
            command += f" {' '.join(cmd)}"
        else:
            raise ValueError(f"{cmd} is not a list nor a string")

        output = run_cmd(command, return_output=return_output, shell=shell)
        logger.debug(output)
        return output
Пример #3
0
 def has_ssh_access(url: str, port: int, username=None) -> bool:
     """
     Check if SSH keys are able to push changes into Pagure
     :param url: Pagure URL address
     :param port: port for checking SSH keys
     :param username: specify username if port is not defined
     :return: False if SSH keys are not valid for Pagure
              True if SSH Keys are valid for using with Pagure
     """
     cmd = f"ssh -T git@git.{url} -p {port}"
     if not port:
         cmd = f"ssh -T {username}@pkgs.fedoraproject.org"
     retval = run_cmd(cmd.split())
     return retval == 0
Пример #4
0
 def test_run_cmd(self, cmd, ok):
     """Test run_cmd()."""
     if ok:
         assert run_cmd(cmd, return_output=True).startswith('total ')
         assert run_cmd(cmd, return_output=False) == 0
     else:
         with pytest.raises(CalledProcessError):
             run_cmd(cmd, ignore_error=False)
         assert run_cmd(cmd, ignore_error=True, return_output=True)
         assert run_cmd(cmd, ignore_error=True, return_output=False) > 0
Пример #5
0
 def _call_openshift_cmd(self, cmd, status=False):
     cmd = cmd.split(" ")
     return run_cmd(logger, cmd, return_output=True, ignore_error=status)
Пример #6
0
 def setup_method(self):
     self.API_TOKEN = run_cmd(logger, ["oc", "whoami", "-t"], return_output=True)