From d09e1f8757f7c2dfaa34a4f105b3d6690e678c5d Mon Sep 17 00:00:00 2001 From: caryoscelus Date: Thu, 4 Apr 2024 22:15:34 +0000 Subject: [PATCH] Build script --- .gitignore | 3 +++ build.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/Config.py | 6 ++++-- src/util/Git.py | 2 +- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100755 build.py diff --git a/.gitignore b/.gitignore index 0d03e87f..5a91a419 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ plugins/Multiuser plugins/NoNewSites plugins/StemPort plugins/UiPassword + +# Build files +src/Build.py diff --git a/build.py b/build.py new file mode 100755 index 00000000..7b71daf1 --- /dev/null +++ b/build.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +## Copyright (c) 2024 caryoscelus +## +## zeronet-conservancy is free software: you can redistribute it and/or modify it under the +## terms of the GNU General Public License as published by the Free Software +## Foundation, either version 3 of the License, or (at your option) any later version. +## +## zeronet-conservancy is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## zeronet-conservancy. If not, see . +## + +"""Simple build/bundle script +""" + +import argparse + +def write_to(args, target): + branch = args.branch + commit = args.commit + if branch is None or commit is None: + from src.util import Git + branch = branch or Git.branch() or 'unknown' + commit = commit or Git.commit() or 'unknown' + target.write('\n'.join([ + f"build_type = {args.type!r}", + f"branch = {branch!r}", + f"commit = {commit!r}", + f"version = {args.version!r}", + ])) + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--type', default='source') + parser.add_argument('--version') + parser.add_argument('--branch') + parser.add_argument('--commit') + parser.add_argument('--stdout', action=argparse.BooleanOptionalAction, default=False) + args = parser.parse_args() + if args.stdout: + import sys + target = sys.stdout + else: + target = open('src/Build.py', 'w') + write_to(args, target) + +if __name__ == '__main__': + main() diff --git a/src/Config.py b/src/Config.py index 57fb3a3c..12603d40 100644 --- a/src/Config.py +++ b/src/Config.py @@ -10,22 +10,24 @@ import logging.handlers import stat import time +VERSION = "0.7.10+" + class Config: def __init__(self, argv): try: from . import Build except ImportError: - print('cannot find build') from .util import Git self.build_type = 'source' self.branch = Git.branch() or 'unknown' self.commit = Git.commit() or 'unknown' + self.version = VERSION else: self.build_type = Build.build_type self.branch = Build.branch self.commit = Build.commit - self.version = "0.7.10+" + self.version = Build.version or VERSION self.version_full = f'{self.version} ({self.build_type} from {self.branch}-{self.commit})' self.user_agent = "conservancy" # for compatibility diff --git a/src/util/Git.py b/src/util/Git.py index 7b60d396..ef633abe 100644 --- a/src/util/Git.py +++ b/src/util/Git.py @@ -48,7 +48,7 @@ def _gitted(f): return lambda *args, **kwargs: None @_gitted -def commit() -> str: +def commit() -> Optional[str]: """Returns git revision, possibly suffixed with -dirty""" dirty = '-dirty' if _repo.is_dirty() else '' return f'{_repo.head.commit}{dirty}'