def run(): # get args parser = argparse__ArgumentParser() parser.add_argument('--refname', nargs=1, required=True) parser.add_argument('--stagedir', nargs=1, required=True) parser.add_argument('--repodir', nargs=1, required=True) args = parser.parse_args() refname: str = args.refname[0] stagedir: pathlib.Path = pathlib__Path(args.stagedir[0]) repodir: pathlib.Path = pathlib__Path(args.repodir[0]) assert stagedir.is_dir() and repodir.is_dir() repo: git.Repo = repo_create_ensure(str(repodir)) # repo clean repo.git.clean(d=True, f=True) repo.git.rm('.', r=True) # stage copy to repo copy_fromdir_todir(srcdir=stagedir, dstdir=repodir) # repo add files and commit repo.git.add(A=True) commit: git.Commit = repo.index.commit('ccc') # repo set ref ref = git.Reference(repo, refname) ref.set_object(commit)
def get_latest(p: dirname_t) -> float: walk: List[Tuple[dirname_t, List[dirname_t], List[fname_t]]] = list(os__walk(p)) dirs: List[dirname_t] = [w[0] for w in walk] files: List[fname_t] = [ pathlib__Path(w[0]) / str(f) for w in walk for f in w[2] ] dirs_max = max([getmtime(v) for v in dirs]) if len(dirs) else 0 files_max = max([getmtime(v) for v in files]) if len(files) else 0 any_max = max(dirs_max, files_max) return any_max
def build(): bifdir: str = server_app.config['PS']['BUILDINFODIR'] stgdir: str = server_app.config['PS']['STAGEDIR'] deploy: str = server_app.config['PS']['DEPLOYSCRIPT'] try: p0: subprocess.CompletedProcess = subprocess__run([deploy, '--build'], timeout=300, check=True, capture_output=True, text=True) p0.check_returncode() except: raise RuntimeError(p0) write_next(pathlib__Path(bifdir), p0.stdout) ts: str = timestamp__get_latest_str(stgdir) return f'''<p>Timestamp: <b>{ts}</b></p>'''
def buildinfo(): bifdir: pathlib.Path = pathlib__Path( server_app.config['PS']['BUILDINFODIR']) files: typing.List[pathlib.Path] = [ x for x in bifdir.iterdir() if x.is_file() ] fnams: typing.List[str] = sorted([fnameint(x.name) for x in files], reverse=True) tvars: dict = {'fnams': fnams, 'ps_url_for': ps_url_for} return flask__render_template_string( ''' <ul> {% for f in fnams %} <li><a href="{{ ps_url_for('buildinfo/' + f) }}">{{ f }}</a></li> {% endfor %} </ul> ''', **tvars)
def copy_fromdir_todir(srcdir: pathlib.Path, dstdir: pathlib.Path): for x in [pathlib__Path(a) for a in glob__glob(str(srcdir.joinpath('*')))]: copy_from_todir(src=x, dstdir=dstdir)