mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-22 03:24:25 +00:00
chore: mild improvements to debugging
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# /usr/bin/env python3 -m pip install --user gitpython
|
||||
# Easy, quick & dirty solution to act upon multiple git repositories at once.
|
||||
|
||||
# TODO:
|
||||
# - proper commands
|
||||
# - use 'gitpython' instead of calling `git`
|
||||
|
||||
import logging
|
||||
import subprocess
|
||||
@@ -10,10 +14,13 @@ from os import cpu_count, getcwd, walk
|
||||
from os.path import basename, dirname, isdir
|
||||
from sys import argv
|
||||
|
||||
log_level = logging.DEBUG
|
||||
dry_run = False
|
||||
log_level = logging.WARNING
|
||||
root_directory = getcwd()
|
||||
threads_count = cpu_count()
|
||||
|
||||
logging.basicConfig(level=log_level)
|
||||
|
||||
def git_command(directory, *args):
|
||||
logging.debug(f"thread for {directory}")
|
||||
logging.debug(f"using args {args}")
|
||||
@@ -26,13 +33,20 @@ def git_command(directory, *args):
|
||||
command.extend(args)
|
||||
logging.debug(command)
|
||||
|
||||
subprocess.call(command)
|
||||
if dry_run is False:
|
||||
subprocess.call(command)
|
||||
|
||||
if __name__ == "__main__":
|
||||
if argv[1] == "--debug":
|
||||
logging.basicConfig(level=log_level)
|
||||
if "--debug" in argv:
|
||||
logging.basicConfig(level=logging.DEBUG, force=True)
|
||||
logging.warning("debug mode")
|
||||
argv.remove("--debug")
|
||||
|
||||
if "--dry-run" in argv:
|
||||
dry_run = True
|
||||
logging.warning("dry-run mode")
|
||||
argv.remove("--dry-run")
|
||||
|
||||
logging.debug(f"using globals {globals()}")
|
||||
logging.debug(f"using locals {locals()}")
|
||||
|
||||
@@ -41,7 +55,9 @@ if __name__ == "__main__":
|
||||
if isdir(argv[-1]):
|
||||
root_directory = argv[-1]
|
||||
git_args = argv[1:-1]
|
||||
else: git_args = argv[1:]
|
||||
else:
|
||||
git_args = argv[1:]
|
||||
|
||||
logging.debug(f"starting from {root_directory}")
|
||||
logging.debug(f"using git args {git_args}")
|
||||
|
||||
@@ -51,4 +67,5 @@ if __name__ == "__main__":
|
||||
logging.debug(f"creating threads")
|
||||
with ThreadPoolExecutor(max_workers=threads_count) as executor:
|
||||
for repository in repositories:
|
||||
logging.debug(f"submitting thread for {repository}")
|
||||
executor.submit(git_command, repository, *git_args)
|
||||
|
||||
Reference in New Issue
Block a user