#!/usr/bin/env python3 import argparse import os from repo_cloner.lib.repo_dir_structure import RepoDirStructure from git.config import GitConfigParser import logging as l l.basicConfig(level = 0) def config_try_override(config_writer: GitConfigParser, section: str, option: str, value: str): if not section in config_writer.sections(): l.debug(f"CFG Creating section: {section}") config_writer.add_section(section) if not config_writer.has_option(section, option): l.debug(f"CFG Creating option: {option}") config_writer.add_value(section, option, "") l.debug(f"Setting {section}.{option} = {value}") config_writer.set(section, option, value) def main(): # 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() dirs = RepoDirStructure(args.base_dir) os.environ['XDG_CONFIG_HOME'] = dirs.conf_dir from git import Repo r = Repo("/home/vasek/dev/repo-cloner") path: str = r._get_config_path("user") print(path) path = os.path.dirname(path) print(path) if not os.path.isdir(path): os.mkdir(path) cred_store: str = os.path.join(path, "git-credentials") ssh_identity: str = os.path.join(dirs.conf_dir, "ssh", "identity") with r.config_writer("user") as cfgw: config_try_override(cfgw, "credential", "helper", f"store --file={cred_store}") config_try_override(cfgw, "core", "sshcommand", f"ssh -i {ssh_identity} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -q") if __name__ == "__main__": main()