Improve runner script: exit codes

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-07-24 22:24:42 +02:00
parent b7e9056b81
commit 21d449a0a9
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
3 changed files with 34 additions and 16 deletions

View File

@ -1,11 +0,0 @@
# library for work with config file
# check directories if they exist
[ -d $CONFIG_DIR ] || die "Config directory does not exist on volune - $CONFIG_DIR"
[ -f $CONFIG_DIR/cloner.cfg ] || die "Config file does not exist - create please cloner.cfg"
# load config files
source $CONFIG_DIR/cloner.cfg
# check if the url is specified
repo=${cloner_repo_url:-}
[ -z "$repo" ] && die "No repository url is specified" || true

View File

@ -5,7 +5,7 @@ IFS=$'\n\t'
# source libs
mydir=$(dirname $(realpath $0))
source $mydir/cloner-lib-cfg
source $mydir/detector-lib-cfg

View File

@ -6,7 +6,7 @@ import os
import logging as l
#l.basicConfig(level = 0)
# l.basicConfig(level = 0)
# create console handler with a higher log level
console_logger = l.StreamHandler()
@ -35,17 +35,46 @@ def config_try_override(config_writer: GitConfigParser, section: str, option: st
config_writer.set(section, option, value)
def main():
def main() -> int:
# parse input arguments
parser = argparse.ArgumentParser(description = "repo-cloner entering script")
parser.add_argument('--base-dir', help = 'path to directory containing whole cloner structure', required = True,
default = None, type = str)
args = parser.parse_args()
log.info(f"Started processing git group in folder: {args.base_dir}")
dirs = RepoDirStructure(args.base_dir)
log.debug(f"Patching XDG_CONFIG_HOME to mock up git config")
os.environ['XDG_CONFIG_HOME'] = dirs.conf_dir
# check dir existence
try:
assert dirs.dirs_exist
except Exception as e:
log.critical(f"Dir structure problem: {e.__str__()}")
return 1
# does config exist?
try:
assert dirs.has_config
except Exception as e:
log.critical(f"Config file not found!?")
log.critical(e.__str__())
return 1
# ignore invalid config lines
# check if there is project name & git url supplied
config = dirs.config
if len(config.cloner_repo_url) == 0:
log.critical("Config directive cloner_repo_url is missing/empty! Cannot continue!")
return 1
if len(config.cloner_project_name) == 0:
log.warning("Config directive cloner_project_name should not be omitted!")
return 0
from git import Repo
r = Repo("/home/vasek/dev/repo-cloner")
path: str = r._get_config_path("user")
@ -68,4 +97,4 @@ def main():
if __name__ == "__main__":
main()
exit(main())