def __init__(self, path, **kwargs): if not os.path.exists(os.path.join(path, '.qogir')): raise CommandError('Invalid Job Path') self.root_dir = qogir.__path__[0] self.path = os.path.abspath(path) self.env = os.path.join(self.path, '.venv') config_path = os.path.join(path, 'config.yaml') self.config = yaml.load(open(config_path))
async def __init__(self, path, **kwargs): if not os.path.exists(os.path.join(path, '.qogir')): raise CommandError('Invalid Job Path') self.root_dir = qogir.__path__[0] self.path = os.path.abspath(path) self.env = os.path.join(self.path, '.venv') self.params = None config_path = os.path.join(path, 'config.yaml') async with aiofiles.open(config_path) as f: self.config = yaml.load(await f.read())
def run(self, *args, **kwargs): self.params = None if 'params' in kwargs: if isinstance(kwargs['params'], dict): self.params = json.dumps(kwargs['params']) else: self.params = kwargs['params'] self.configure() self._check_venv() if run_bash_command(self.command_) != 0: raise CommandError('Command finished with a nonzero return code.')
def run_bash_command(command): proc = Popen( command, stdout=sys.stdout, stderr=sys.stderr, executable='/bin/bash', shell=True, ) proc.communicate() if proc.returncode != 0: raise CommandError('Command finished with a nonzero return code.')
def _check_venv(self): _include_paths = self.config.get('include_paths') if not _include_paths: include_paths = [] else: if isinstance(_include_paths, str): _include_paths = [_include_paths] include_paths = [repr(_path) for _path in _include_paths] tpl_path = os.path.join(self.root_dir, 'templates', 'check_venv.sh.tpl') _command = open(tpl_path).read() _command = _command.format(job_path=self.path, python=self.config['python'], include_paths=' '.join(include_paths)) if run_bash_command(_command) != 0: raise CommandError('Command finished with a nonzero return code.')
def _is_valid_name(self, name): if not re.match(r'^[a-zA-Z]+[\w_]+$', name): raise CommandError('Invalid project name')