Ejemplo n.º 1
0
Archivo: cli.py Proyecto: ntijanic/pdl
def cmd_schema(output, **kwargs):
    sch = get_wrapper_schemas(kwargs.pop('package', None))
    if output:
        with open(output, 'w') as fp:
            to_json(sch, fp)
    else:
        print(to_json(sch))
Ejemplo n.º 2
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
Ejemplo n.º 3
0
 def execute(self, job):
     logging.debug('Job started: %s' % to_json(job))
     if job.job_id in self.results:
         return self.results[job.job_id]
     for key, val in job.args.iteritems():
         job.resolved_args[key] = self.resolve(val)
     if job.__class__ not in self.job_executors and not callable(job):
         raise NotImplementedError('Tassadar unable to run job of type %s.' % job.__class__.__name__)
     job.status = BaseJob.RUNNING
     result = job() if callable(job) else self.job_executors[job.__class__](job)
     self.results[job.job_id] = result
     job.status = BaseJob.DONE
     if isinstance(result, BaseJob):
         return self.execute(result)
     logging.debug('Job result: %s' % to_json(result))
     return result
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def execute(self, job, one_container=False):
        logging.info('Job started: %s' % job.job_id)
        logging.debug('Job: %s' % to_json(job))

        if one_container:
            return self.exec_wrapper_full(job)

        job.resolved_args = self.resolve(job.args)
        job.status = Job.RUNNING
        result = self.exec_wrapper_job(job)
        if isinstance(result, JobError):
            raise result
        job.status = Job.DONE
        if isinstance(result, Job):
            return self.execute(result)
        logging.info('Job finished: %s' % to_json(job))
        return result
Ejemplo n.º 6
0
Archivo: cli.py Proyecto: 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)