Esempio n. 1
0
 def exec_wrapper_full(self, job):
     job_dir = job.job_id
     os.mkdir(job_dir)
     os.chmod(job_dir, os.stat(job_dir).st_mode | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
     os.chdir(job_dir)
     with open('__in__.json', 'w') as fp:
         logging.debug('Writing job order to %s', os.path.abspath('__in__.json'))
         to_json(job, fp)
     self.runner.run_wrapper('__in__.json', cwd=job_dir)
     with open('__out__.json') as fp:
         logging.debug('Reading job output from %s', os.path.abspath('__out__.json'))
         result = from_json(fp)
     os.chdir('..')
     return result
Esempio n. 2
0
 def exec_wrapper_job(self, job):
     job_dir = job.job_id
     os.mkdir(job_dir)
     os.chmod(job_dir, os.stat(job_dir).st_mode | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
     in_file, out_file = [os.path.join(job_dir, f) for f in '__in__.json', '__out__.json']
     with open(in_file, 'w') as fp:
         logging.debug('Writing job order to %s', in_file)
         to_json(job, fp)
     self.runner.run_job('__in__.json', '__out__.json', cwd=job_dir)
     with open(out_file) as fp:
         logging.debug('Reading job output from %s', out_file)
         result = from_json(fp)
     from subprocess import Popen
     Popen(['sudo chmod -R 777 ' + job_dir], shell=True)  # TODO: remove
     Popen(['sudo chown -R 1001:1001 ' + job_dir], shell=True)  # TODO: remove
     return result
Esempio n. 3
0
File: cli.py Progetto: ntijanic/pdl
def cmd_run(cwd, input, output, run_method=run_job, **kwargs):
    if not os.path.isdir(cwd):
        raise Exception('No such directory: %s', cwd)
    os.chdir(cwd)

    if not os.path.isfile(input):
        raise Exception('No such file: %s' % input)
    with open(input) as fp:
        job = from_json(fp)
    if not isinstance(job, Job):
        raise NotAJobError('Input JSON must describe a job.')

    try:
        result = run_method(job)
    except JobError as e:
        result = e

    with open(output, 'w') as fp:
        to_json(result, fp)
Esempio n. 4
0
File: cli.py Progetto: ntijanic/pdl
def run_script():
    args = vars(create_parser().parse_args())
    if args['logging_config']:
        with open(args['logging_config']) as fp:
            logging.config.dictConfig(from_json(fp))
    try:
        args['cmd_func'](**args)
    except ProtocolError as e:
        logging.exception("Bad Job: %s", args)
        return exit_code_for_exception(e)
    except ValidationError as e:
        logging.exception("Input or params validation failed: %s", args)
        return exit_code_for_exception(e)
    except JobError as e:
        logging.exception("Wrapper error: %s", args)
        return exit_code_for_exception(e)
    except Exception:
        logging.exception("Internal error: %s", args)
        return 120
    return 0