def wrapper(*args): cache_key = cache_key_templ.format(":".join(args)).replace( "/", "%") container_id = utils.plash_call("map", cache_key) if not container_id: container_id = func(*args) utils.plash_call("map", cache_key, container_id) return hint("image", container_id)
def from_github(user_repo_pair, file='plashfile'): "build and use a file (default 'plashfile') from github repo" from urllib.request import urlopen url = 'https://raw.githubusercontent.com/{}/master/{}'.format( user_repo_pair, file) with utils.catch_and_die([Exception], debug=url): resp = urlopen(url) plashstr = resp.read().decode() return utils.plash_call('build', '--eval-stdin', input=plashstr)
def eval_github(user_repo_pair, file="plashfile"): "eval a file (default 'plashfile') from a github repo" from urllib.request import urlopen url = "https://raw.githubusercontent.com/{}/master/{}".format( user_repo_pair, file) with utils.catch_and_die([Exception], debug=url): resp = urlopen(url) plashstr = resp.read().decode() return utils.plash_call("eval", "--eval-stdin", input=plashstr)
def eval_file(file): "evaluate file content as expressions" fname = os.path.realpath(os.path.expanduser(file)) with open(fname) as f: inscript = f.read() sh = utils.plash_call("eval", "--eval-stdin", strip=False, input=inscript) # we remove an possibly existing newline # because else this macros would add one if sh.endswith("\n"): return sh[:-1] return sh
def from_map(map_key): 'use resolved map as image' image_id = utils.plash_call('map', map_key) if not image_id: raise MapDoesNotExist('map {} not found'.format(repr(map_key))) return hint('image', image_id)
def from_url(url): 'import image from an url' return utils.plash_call('import-url', url)
def from_lxc(image): 'use images from images.linuxcontainers.org' return utils.plash_call('import-lxc', image)
def from_docker(image): 'use image from local docker' utils.plash_call('import-docker', image)
def eval_string(stri): "evaluate expressions passed as string" import shlex tokens = shlex.split(stri) return utils.plash_call("eval", *tokens, strip=False)
def eval_stdin(): "evaluate expressions read from stdin" tokens = [i.rstrip("\n") for i in sys.stdin.readlines()] return utils.plash_call("eval", *tokens, strip=False)
def from_github(user_repo_pair, file="plashfile"): "build and use a file (default 'plashfile') from a github repo" return utils.plash_call("build", "--eval-github", user_repo_pair, file)
def from_map(map_key): "use resolved map as image" image_id = utils.plash_call("map", map_key) if not image_id: raise MapDoesNotExist("map {} not found".format(repr(map_key))) return hint("image", image_id)
def from_url(url): "import image from an url" return utils.plash_call("import-url", url)
def from_lxc(image): "use images from images.linuxcontainers.org" return utils.plash_call("import-lxc", image)
def from_docker(image): "use image from local docker" return utils.plash_call("import-docker", image)
def eval_string(stri): 'evaluate expressions passed as string' import shlex tokens = shlex.split(stri) return utils.plash_call('eval', input='\n'.join(tokens), strip=False)