def delete_version(self, path): if path not in self.list_versions(): raise Exception("Not an available version") if os.path.basename(path) in self.get_protected_versions(): raise Exception("Refusing to delete protected version") logger.info("Deleting {}".format(q(self.c.versions_dir + "/" + path))) self.c_usr.run("rm -rf {}".format(q(self.c.versions_dir + "/" + path)))
def prepare_version(self, path, code_commit, config_commit): logger.info("Creating code and config files at {}".format(path)) self.c_usr.run("mkdir {}".format(path)) with self.c_usr.cd(path): self.c_usr.run("mkdir {}".format(self.c.static_subdir)) # Download code self._download_repository(self.c.code_repo_url, self.c.code_subdir, code_commit, self.c.code_branch) # Download config self._download_repository(self.c.config_repo_url, self.c.config_subdir, config_commit, self.c.config_branch) # Prepare venv logger.info("Creating virtualenv") self.c_usr.run("python -m venv {}".format(q(self.c.venv_subdir))) with self.c_usr.prefix("source {}/{}/bin/activate" .format(path, q(self.c.venv_subdir))): if self.c.build_script is None: code_requirements = self.c.code_subdir + "/requirements.txt" if os.path.isfile(code_requirements): self.c_usr.run("pip install -r " + q(code_requirements)) config_requirements = self.c.config_subdir + "/requirements.txt" if os.path.isfile(config_requirements): self.c_usr.run("pip install -r " + q(config_requirements)) else: self.c_usr.run(self.c.build_script)
def _download_repository(self, url, path, commit, branch): logger.info("Downloading repository {} to {}, commit {}" .format(url, path, commit)) self.c_usr.run("git clone {} {}".format(q(url), q(path))) with self.c_usr.cd(path): self.c_usr.run("git checkout {}".format(q(commit))) self.c_usr.run("git branch -D master") self.c_usr.run("git checkout -b {}".format(branch)) self.c_usr.run( "git branch --set-upstream-to=origin/{}".format(branch))
def delete_versions(self, to_delete): versions_list = self.list_versions() protected_versions = self.get_protected_versions() for path in to_delete: if path not in versions_list: logger.error("Not an available version: {}".format(path)) continue if os.path.basename(path) in protected_versions: logger.warning( "Refusing to delete protected version: {}".format(path)) continue logger.info("Deleting {}".format(q(self.c.versions_dir + "/" + path))) self.c_usr.run("rm -rf {}".format(q(self.c.versions_dir + "/" + path)))
def mark_working(self, new_path): if new_path == self.get_working_version(): return self.c_usr.run("rm -f {}".format(self.c.previous_working)) self.c_usr.run( "mv {} {}".format(self.c.current_working, self.c.previous_working)) self.c_usr.run("ln -s {} {}".format(q(new_path), self.c.current_working))
def change_codebase(self, new_path): logger.info("Changing codebase to {}".format(new_path)) self.c_usr.run("rm -f {}".format(self.c.previous_main)) self.c_usr.run("mv {} {}".format(self.c.current_main, self.c.previous_main)) self.c_usr.run("ln -s {} {}".format(q(new_path), self.c.current_main))
from shlex import quote as q transitions = [ { "id": "transition", "error": q('errors/{{.Input 0}}'), "stderr": q('logs/{{.Input 0}}'), "inputs": [q('input/(?P<id>.*).*')], "outputs": [q('output/{{.Input 0}}')], "cmd": "echo", } ]
from shlex import quote as q complete_transition = {'inputs': ['/tmp/input0/'+q('(?P<id>...)_(?P<suffix>.*)\.txt'), '/tmp/input1/'+q('(?P<prefix>.*)_(?P<id>...)\.txt'), ], 'errors': ['/tmp/error0/'+q('{{.Input 0}}'), '/tmp/error1/'+q('{{.Input 1}}')], 'stderr': '/tmp/log/{{.Invariant}}.log', 'log': '/tmp/log/Arbitrary.log', 'id': 'Arbitrary', 'side_effects': ['Side_effect1', 'Side_effect2'], 'outputs': ['/tmp/outputA/{{.NamedMatches.id}}' '_{{.NamedMatches.prefix}}_' '{{.NamedMatches.suffix}}.txt', '/tmp/outputB/{{.Invariant}}.txt'], 'quit_empty': True, 'invariant': '$id', 'cmd': 'sha256sum'}