Build script
This commit is contained in:
parent
3db5e10882
commit
d09e1f8757
4 changed files with 61 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -45,3 +45,6 @@ plugins/Multiuser
|
||||||
plugins/NoNewSites
|
plugins/NoNewSites
|
||||||
plugins/StemPort
|
plugins/StemPort
|
||||||
plugins/UiPassword
|
plugins/UiPassword
|
||||||
|
|
||||||
|
# Build files
|
||||||
|
src/Build.py
|
||||||
|
|
53
build.py
Executable file
53
build.py
Executable file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
##
|
||||||
|
|
||||||
|
"""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()
|
|
@ -10,22 +10,24 @@ import logging.handlers
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
VERSION = "0.7.10+"
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
try:
|
try:
|
||||||
from . import Build
|
from . import Build
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print('cannot find build')
|
|
||||||
from .util import Git
|
from .util import Git
|
||||||
self.build_type = 'source'
|
self.build_type = 'source'
|
||||||
self.branch = Git.branch() or 'unknown'
|
self.branch = Git.branch() or 'unknown'
|
||||||
self.commit = Git.commit() or 'unknown'
|
self.commit = Git.commit() or 'unknown'
|
||||||
|
self.version = VERSION
|
||||||
else:
|
else:
|
||||||
self.build_type = Build.build_type
|
self.build_type = Build.build_type
|
||||||
self.branch = Build.branch
|
self.branch = Build.branch
|
||||||
self.commit = Build.commit
|
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.version_full = f'{self.version} ({self.build_type} from {self.branch}-{self.commit})'
|
||||||
self.user_agent = "conservancy"
|
self.user_agent = "conservancy"
|
||||||
# for compatibility
|
# for compatibility
|
||||||
|
|
|
@ -48,7 +48,7 @@ def _gitted(f):
|
||||||
return lambda *args, **kwargs: None
|
return lambda *args, **kwargs: None
|
||||||
|
|
||||||
@_gitted
|
@_gitted
|
||||||
def commit() -> str:
|
def commit() -> Optional[str]:
|
||||||
"""Returns git revision, possibly suffixed with -dirty"""
|
"""Returns git revision, possibly suffixed with -dirty"""
|
||||||
dirty = '-dirty' if _repo.is_dirty() else ''
|
dirty = '-dirty' if _repo.is_dirty() else ''
|
||||||
return f'{_repo.head.commit}{dirty}'
|
return f'{_repo.head.commit}{dirty}'
|
||||||
|
|
Loading…
Reference in a new issue