コード例 #1
0
def main():
    args = parse_args(__doc__, options_first=False)
    job = jip.db.get(args['--job'])
    if not job:
        print(colorize("No job found!", RED), file=sys.stderr)
        sys.exit(1)
    editor = os.getenv("EDITOR", 'vim')
    if job.state in jip.db.STATES_ACTIVE:
        print("You can not edit a job that is currently queued or running!",
              file=sys.stderr)
        sys.exit(1)
    tmp = create_temp_file()
    tmp.write(job.command)
    tmp.close()
    p = subprocess.Popen([editor, tmp.name])
    if p.wait() == 0:
        with open(tmp.name) as f:
            job.command = "".join(f.readlines())
        jip.db.save(job)
        print(colorize("Job updated", GREEN))
        print("You can restart the change job with:",
              colorize("jip restart -j %s" % (str(job.id)), YELLOW))
コード例 #2
0
ファイル: jip_edit.py プロジェクト: Arhodes-CGRB-OSU/pyjip
def main():
    args = parse_args(__doc__, options_first=False)
    job = jip.db.get(args['--job'])
    if not job:
        print >>sys.stderr, colorize("No job found!", RED)
        sys.exit(1)
    editor = os.getenv("EDITOR", 'vim')
    if job.state in jip.db.STATES_ACTIVE:
        print >>sys.stderr, "You can not edit a job that is " \
            "currently queued or running!"
        sys.exit(1)
    tmp = create_temp_file()
    tmp.write(job.command)
    tmp.close()
    p = subprocess.Popen([editor, tmp.name])
    if p.wait() == 0:
        with open(tmp.name) as f:
            job.command = "".join(f.readlines())
        jip.db.save(job)
        print colorize("Job updated", GREEN)
        print "You can restart the change job with:", colorize(
            "jip restart -j %s" % (str(job.id)), YELLOW
        )
コード例 #3
0
ファイル: db.py プロジェクト: heathsc/pyjip
    def run(self):
        """Execute a single job. Note that no further checks on the
        job are performed and this method assumes that the jobs stream_in
        and stream_out are properly connected.

        .. note: This method does not wait for the job's process to finish!

        :returns: the process
        :raises Exception: if the interpreter was not found
        """
        log.info("%s | start", self)
        self._load_job_env()
        # write template to named temp file and run with interpreter
        script_file = create_temp_file()
        try:
            if self.interpreter == 'bash':
                log.debug("Setting up default bash environment "
                          "and enable pipefail")
                script_file.write(b"set -o pipefail\n\n")

            log.debug("Writing command: %s", self.command)
            script_file.write(self.command.encode('utf-8'))
            script_file.close()
            cmd = [self.interpreter if self.interpreter else "bash"]
            #if self.interpreter_args:
                #cmd += self.interpreter_args
            log.debug("%s | starting process with in: %s out: %s", self,
                      self.stream_in, self.stream_out)
            # handle pseudo files
            sin = self.stream_in
            sout = self.stream_out
            cwd = self.working_directory if self.working_directory \
                else os.getcwd()
            try:
                self._process = subprocess.Popen(
                    cmd + [script_file.name],
                    stdin=sin,
                    stdout=sout,
                    cwd=cwd
                )
            except ValueError as err:
                if str(err) == "redirected Stdin is pseudofile, "\
                        "has no fileno()":
                    log.error("pseudo file found for stdin! We work around"
                              "this and start the process without any "
                              "stream setup to make the doctest work! "
                              "Don't tell me, I know this is dirty and "
                              "if you reach this message outside of a doctest "
                              "please let us now and we have to find another "
                              "workaround!")
                    if isinstance(sout, StringIO):
                        self._process = subprocess.Popen(
                            cmd + [script_file.name])
                    else:
                        self._process = subprocess.Popen(
                            cmd + [script_file.name], stdout=sout)
                    return self._process
                else:
                    raise
            return self._process
        except OSError as err:
            # catch the errno 2 No such file or directory, which indicates the
            # interpreter is not available
            if err.errno == 2:
                log.error("No interpreter found for script: %s", script_file,
                          exc_info=True)
                raise Exception("Interpreter %s not found!" % self.interpreter)
            raise err
コード例 #4
0
ファイル: db.py プロジェクト: Arhodes-CGRB-OSU/pyjip
    def run(self):
        """Execute a single job. Note that no further checks on the
        job are performed and this method assumes that the jobs stream_in
        and stream_out are properly connected.

        .. note: This method does not wait for the job's process to finish!

        :returns: the process
        :raises Exception: if the interpreter was not found
        """
        log.info("%s | start", self)
        self._load_job_env()
        # write template to named temp file and run with interpreter
        script_file = create_temp_file()
        try:
            if self.interpreter == 'bash':
                log.debug("Setting up default bash environment "
                          "and enable pipefail")
                script_file.write("set -o pipefail\n\n")

            log.debug("Writing command: %s", self.command)
            script_file.write(self.command)
            script_file.close()
            cmd = [self.interpreter if self.interpreter else "bash"]
            #if self.interpreter_args:
                #cmd += self.interpreter_args
            log.debug("%s | starting process with in: %s out: %s", self,
                      self.stream_in, self.stream_out)
            # handle pseudo files
            sin = self.stream_in
            sout = self.stream_out
            cwd = self.working_directory if self.working_directory \
                else os.getcwd()
            try:
                self._process = subprocess.Popen(
                    cmd + [script_file.name],
                    stdin=sin,
                    stdout=sout,
                    cwd=cwd
                )
            except ValueError as err:
                if str(err) == "redirected Stdin is pseudofile, "\
                        "has no fileno()":
                    log.error("pseudo file found for stdin! We work around"
                              "this and start the process without any "
                              "stream setup to make the doctest work! "
                              "Don't tell me, I know this is dirty and "
                              "if you reach this message outside of a doctest "
                              "please let us now and we have to find another "
                              "workaround!")
                    import StringIO
                    if isinstance(sout, StringIO.StringIO):
                        self._process = subprocess.Popen(
                            cmd + [script_file.name])
                    else:
                        self._process = subprocess.Popen(
                            cmd + [script_file.name], stdout=sout)
                    return self._process
                else:
                    raise
            return self._process
        except OSError, err:
            # catch the errno 2 No such file or directory, which indicates the
            # interpreter is not available
            if err.errno == 2:
                log.error("No interpreter found for script: %s", script_file,
                          exc_info=True)
                raise Exception("Interpreter %s not found!" % self.interpreter)
            raise err