hasher = hashlib.sha512() for fname in sorted(collect_files): perm = str(oct(stat.S_IMODE(os.lstat(fname).st_mode))).encode() with open(fname, "rb") as f: fread = f.read() # well, no buffering? hasher.update(fname.encode()) hasher.update(perm) hasher.update(utils.hashstr(fread).encode()) hash = hasher.hexdigest() return ": hash: {}".format(hash) register_macro("hash-path")(HashPaths()) @register_macro() def entrypoint(exec_path): "hint default command for this build" return hint("exec", exec_path) @register_macro() def entrypoint_script(*lines): "write lines to /entrypoint and hint it as default command" lines = list(lines) if lines and not lines[0].startswith("#!"): lines.insert(0, "#!/bin/sh") return eval([["entrypoint", "/entrypoint"],
x=[["run"]], l=[["layer"]], f=[["from"]], # pin down whatever will last the longest like that in the source # code A=[["from", "alpine:edge"], ["apk"]], U=[["from", "ubuntu:bionic"], ["apt"]], F=[["from", "fedora:31"], ["dnf"]], D=[["from", "debian:sid"], ["apt"]], C=[["from", "centos:8"], ["yum"]], R=[["from", "archlinux:current"], ["pacman"]], G=[["from", "gentoo:current"], ["emerge"]], ) for name, macro in ALIASES.items(): def bounder(macro=macro): def func(*args): # list(args) throws an exception exception for some really funny reason # therefore the list comprehension args = [i for i in args] return eval(macro[:-1] + [macro[-1] + args]) func.__doc__ = "alias for: {}[ARG1 [ARG2 [...]]]".format(" ".join( "--" + i[0] + " " + " ".join(i[1:]) for i in macro)) return func func = bounder() register_macro(name=name, group="macros")(func)
hasher = hashlib.sha1() for fname in sorted(collect_files): perm = str(oct(stat.S_IMODE(os.lstat(fname).st_mode))).encode() with open(fname, 'rb') as f: fread = f.read() # well, no buffering? hasher.update(fname.encode()) hasher.update(perm) hasher.update(hashstr(fread).encode()) hash = hasher.hexdigest() return ": hash: {}".format(hash) register_macro('hash-path')(HashPaths()) @register_macro() def entrypoint(exec_path): 'hint default command for this build' return hint('exec', exec_path) @register_macro() def entrypoint_script(*lines): 'write lines to /entrypoint and hint it as default command' lines = list(lines) if lines and not lines[0].startswith('#!'): lines.insert(0, '#!/bin/sh') return eval([['entrypoint', '/entrypoint'],
from plash.eval import eval, register_macro ALIASES = dict( x=[['run']], l=[['layer']], f=[['from']], A=[['from', 'alpine'], ['apk']], U=[['from', 'ubuntu'], ['apt']], F=[['from', 'fedora'], ['dnf']], D=[['from', 'debian'], ['apt']], C=[['from', 'centos'], ['yum']], R=[['from', 'archlinux'], ['pacman']], G=[['from', 'gentoo'], ['emerge']], ) for name, macro in ALIASES.items(): def bounder(macro=macro): def func(*args): # list(args) throws an exception exception for some really funny reason # therefore the list comprehension args = [i for i in args] return eval(macro[:-1] + [macro[-1] + args]) func.__doc__ = 'alias for: {}[ARG1 [ARG2 [...]]]'.format(' '.join( '--' + i[0] + ' ' + ' '.join(i[1:]) for i in macro)) return func func = bounder() register_macro(name=name, group='macros')(func)