예제 #1
0
def clean(job, cluster=None):
    """Remove job log files.

    :param job: the job to be cleaned
    :type job: `jip.db.Job`
    :param cluster: the cluster instance used to resolve logs. If not
                    specified, the cluster instance is loaded from the
                    configuration
    """
    if len(job.pipe_from) != 0:
        return
    if not cluster:
        cluster = jip.cluster.get()

    with utils.ignored(Exception):
        stderr = cluster.resolve_log(job, job.stderr)
        if os.path.exists(stderr):
            log.info("Removing job stderr log file: %s", stderr)
            os.remove(stderr)

    with utils.ignored(Exception):
        stdout = cluster.resolve_log(job, job.stdout)
        if os.path.exists(stdout):
            log.info("Removing job stdout log file: %s", stdout)
            os.remove(stdout)
예제 #2
0
파일: jobs.py 프로젝트: Atemia/pyjip
def clean(job, cluster=None):
    """Remove job log files.

    :param job: the job to be cleaned
    :type job: `jip.db.Job`
    :param cluster: the cluster instance used to resolve logs. If not
                    specified, the cluster instance is loaded from the
                    configuration
    """
    if len(job.pipe_from) != 0:
        return
    if not cluster:
        cluster = jip.cluster.get()

    with utils.ignored(Exception):
        stderr = cluster.resolve_log(job, job.stderr)
        if os.path.exists(stderr):
            log.info("Removing job stderr log file: %s", stderr)
            os.remove(stderr)

    with utils.ignored(Exception):
        stdout = cluster.resolve_log(job, job.stdout)
        if os.path.exists(stdout):
            log.info("Removing job stdout log file: %s", stdout)
            os.remove(stdout)
예제 #3
0
파일: jip_clean.py 프로젝트: Atemia/pyjip
def main():
    args = parse_args(__doc__, options_first=False)
    job_ids, cluster_ids = parse_job_ids(args)
    jobs = jip.db.query(job_ids=job_ids,
                        cluster_ids=cluster_ids,
                        archived=None)
    jobs = jip.jobs.resolve_jobs(jobs)
    logs = args['--logs']
    data = args['--data']
    dry = args['--dry']

    if not logs and not data:
        print colorize(
            "Neither --logs nor --data selected."
            "\nNothing to delete", RED)
        return

    if data and not confirm("You are about to delete job output!\n" + colorize(
            "The will remove result files from disk!\n", RED) +
                            "Are you sure ?"):
        return
    if confirm("Are you sure you want " "to clean %d jobs" % len(jobs), False):
        cluster = jip.cluster.get()
        for job in jobs:
            if logs:
                print "Removing logs for", job
                stdout = cluster.resolve_log(job, job.stdout)
                _remove(stdout, dry=dry)
                stderr = cluster.resolve_log(job, job.stderr)
                _remove(stderr, dry=dry)
            if data:
                print "Removing data for", job
                files = job.get_output_files()
                for f in files:
                    _remove(f, dry=dry)
예제 #4
0
파일: jip_logs.py 프로젝트: Poshi/pyjip
def show_log(job, cluster, args):
    both = not args["--error"] and not args["--output"]
    if both or args["--output"]:
        stdout = cluster.resolve_log(job, job.stdout)
        if stdout and exists(stdout):
            _tail(job, stdout, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head")

    if both or args["--error"]:
        stderr = cluster.resolve_log(job, job.stderr)
        if stderr and exists(stderr):
            _tail(job, stderr, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head",
                  is_error=True)
예제 #5
0
def show_log(job, cluster, args):
    both = not args["--error"] and not args["--output"]
    if both or args["--output"]:
        log.debug("Resolving stdout for %s : %s", job.name, job.stdout)
        stdout = cluster.resolve_log(job, job.stdout)
        log.debug("Resolved stdout for %s : %s", job.name, stdout)
        if stdout and exists(stdout):
            _tail(job, stdout, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head")

    if both or args["--error"]:
        log.debug("Resolving stderr for %s : %s", job.name, job.stderr)
        stderr = cluster.resolve_log(job, job.stderr)
        log.debug("Resolved stderr for %s : %s", job.name, stdout)
        if stderr and exists(stderr):
            _tail(job, stderr, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head",
                  is_error=True)
예제 #6
0
def show_log(job, cluster, args):
    both = not args["--error"] and not args["--output"]
    if both or args["--output"]:
        log.debug("Resolving stdout for %s : %s", job.name, job.stdout)
        stdout = cluster.resolve_log(job, job.stdout)
        log.debug("Resolved stdout for %s : %s", job.name, stdout)
        if stdout and exists(stdout):
            _tail(job, stdout, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head")

    if both or args["--error"]:
        log.debug("Resolving stderr for %s : %s", job.name, job.stderr)
        stderr = cluster.resolve_log(job, job.stderr)
        log.debug("Resolved stderr for %s : %s", job.name, stderr)
        if stderr and exists(stderr):
            _tail(job, stderr, lines=int(args["--lines"]),
                  cmd="tail" if not args["--head"] else "head",
                  is_error=True)
예제 #7
0
def main():
    args = parse_args(__doc__, options_first=False)
    job_ids, cluster_ids = parse_job_ids(args)
    jobs = jip.db.query(job_ids=job_ids, cluster_ids=cluster_ids,
                        archived=None)
    jobs = jip.jobs.resolve_jobs(jobs)
    logs = args['--logs']
    data = args['--data']
    dry = args['--dry']

    if not logs and not data:
        print colorize("Neither --logs nor --data selected."
                       "\nNothing to delete", RED)
        return

    if data and not confirm("You are about to delete job output!\n" +
                            colorize(
                                "The will remove result files from disk!\n",
                                RED
                            ) +
                            "Are you sure ?"):
        return
    if confirm("Are you sure you want "
               "to clean %d jobs" % len(jobs),
               False):
        cluster = jip.cluster.get()
        for job in jobs:
            if logs:
                print "Removing logs for", job
                stdout = cluster.resolve_log(job, job.stdout)
                _remove(stdout, dry=dry)
                stderr = cluster.resolve_log(job, job.stderr)
                _remove(stderr, dry=dry)
            if data:
                print "Removing data for", job
                files = job.get_output_files()
                for f in files:
                    _remove(f, dry=dry)