From f577447cca2874225af0652ff40417d8cbd72a5b Mon Sep 17 00:00:00 2001 From: Istvan Bozso Date: Thu, 13 Feb 2020 13:52:28 +0100 Subject: [PATCH] work on git management automation --- tools/base.py | 70 ------------------------------------- tools/git.py | 38 +++++++++++++++++++++ tools/gpp.py | 93 -------------------------------------------------- tools/tools.py | 28 +++++++++++++++ utils/cmd.py | 4 ++- 5 files changed, 69 insertions(+), 164 deletions(-) delete mode 100644 tools/base.py create mode 100644 tools/git.py delete mode 100644 tools/gpp.py create mode 100644 tools/tools.py diff --git a/tools/base.py b/tools/base.py deleted file mode 100644 index 5086b6c..0000000 --- a/tools/base.py +++ /dev/null @@ -1,70 +0,0 @@ -from subprocess import check_output, CalledProcessError, STDOUT -from shlex import split -from os.path import join - - -__all__ = ( - "repos", - "cmd", - "notify", - "debug", - "home" -) - - -home = join("/home", "istvan") -progs = join(home, "progs") -utils = join(progs, "utils") -icons = join(utils, "icons") - - -repos = { - "insar_meteo": join(progs, "insar_meteo"), - "geodynamics": join(progs, "geodynamics"), - "utils": join(progs, "utils"), - "texfiles": join(home, "Dokumentumok", "texfiles"), - "pygamma": join(progs, "gamma") -} - - -def cmd(*args, **kwargs): - debug = kwargs.pop("debug", False) - - Cmd = " ".join(args) - - if debug: - print(Cmd) - return - - try: - proc = check_output(split(Cmd), stderr=STDOUT) - except CalledProcessError as e: - print("\nNon zero returncode from command: \n'{}'\n" - "\nOUTPUT OF THE COMMAND: \n\n{}\nRETURNCODE was: {}" - .format(Cmd, e.output.decode(), e.returncode)) - exit(1) - - - return proc.decode() - - -def notify(msg, header=None, icon=None, time=None): - - if header is not None: - txt = '"%s" "%s"' % (header, msg) - else: - txt = msg - - if icon is not None: - txt = '%s -i "%s"' % (txt, join(icons, icon)) - - if time is not None: - txt = "%s -t %s" % (txt, time) - - txt = "notify-send %s" % txt - - cmd(txt) - - -def debug(msg): - notify(msg, header="Debug", icon="debug.png") diff --git a/tools/git.py b/tools/git.py new file mode 100644 index 0000000..97b0d99 --- /dev/null +++ b/tools/git.py @@ -0,0 +1,38 @@ +import utils +from tools import github, bitbucket + +commands = ( + "add", "am", "annotate", "apply", "archive", "bisect", "blame", + "branch", "bundle", "checkout", "cherry", "cherry-pick", "clean", + "clone", "commit", "config", "describe", "diff", "difftool", + "fetch", "filter-branch", "format-patch", "fsck", "gc", + "get-tar-commit-id", "grep", "help", "imap-send", "init", + "instaweb", "interpret-trailers", "log", "merge", "mergetool", + "mv", "name-rev", "notes", "pull", "push", "rebase", "reflog", + "remote", "repack", "replace", "request-pull", "reset", + "revert", "rm", "shortlog", "show", "show-branch", "stage", + "stash", "status", "submodule", "subtree", "tag", "verify-commit", + "whatchanged", "worktree", +) + +git = utils.subcommands("git", *commands) + +repos = { + "insar_meteo": github.join("insar_meteo"), + "geodynamics": github.join("geodynamics"), + "utils": github.join("utils"), + "texfiles": home.join("Dokumentumok", "texfiles"), + "pygamma": github.join("pygomma"), +} + + +class Git(object): + def report(self, repo): + pass + + +def main(): + pass + +if __name__ == "__main__": + main() diff --git a/tools/gpp.py b/tools/gpp.py deleted file mode 100644 index df0e8a6..0000000 --- a/tools/gpp.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python - -from sys import path, argv - -path.append("/home/istvan/progs/utils") - -from utils import new_type - -def cast(item, caster): - if caster is str: - return item - else: - return caster(item) - - -class HTMLArgs(object): - __slots__ = ("optional", "positional") - - def __init__(self, args=None): - if args is None: - args = argv[1:] - - self.optional = { - elem.split("=")[0]: elem.split("=")[1] - for elem in args - if "=" in elem - } - - self.positional = tuple(elem for elem in args if "=" not in elem) - - - def pop(self, *args, **kwargs): - type = kwargs.pop("type", str) - - return cast(self.optional.pop(*args, **kwargs), type) - - def __getitem__(self, *args, **kwargs): - return self.optional.__getitem__(*args, **kwargs) - - - def pos(self, idx, type=str): - return cast(self.positional[idx], type) - - -templates = { - "imgit": -} - - -FloatOpts = new_type("FloatOpts", "width, font_size, unit, total_width, " - "title, text_width, img_width, source") - -def imfloat(args): - tpl = """\ - {title} - -
- {title} -
- """ - - opts = FloatOpts( - width = args.pop("width", 500, type=int), - font_size = args.pop("fontsize", 4, type=int), - unit = args.pop("units", "px"), - total_width = args.pop("totalWidth", 1000, type=int), - title = args.pop("title", ""), - text_width = None, - img_width = None, - source = None, - ) - - opts.text_width = "%d%s" % (opts.total_width - opts.width , opts.unit) - opts.img_width = "%d%s" % (opts.width, opts.unit) - opts.source = args.pos(0) - - return tpl.format(**opts.to_dict()) - - -def main(): - try: - args = HTMLArgs() - print(imfloat(args)) - except Exception as e: - raise TypeError("Exception caught: %s\nCalled with arguemnts: %s" % (e, argv)) - - - # GPP().parse().args.fun() - -if __name__ == "__main__": - main() diff --git a/tools/tools.py b/tools/tools.py new file mode 100644 index 0000000..bb50488 --- /dev/null +++ b/tools/tools.py @@ -0,0 +1,28 @@ +import utils + +home = utils.Path.joined("/home", "istvan") +progs = home.join(home, "progs") +github = progs.join("github.com") +bitbucket = progs.join("bitbucket.org") + + +notify_send = utils.Command.with_parser("notify-send") + +def notify(msg, header=None, icon=None, time=None): + + if header is not None: + txt = '"%s" "%s"' % (header, msg) + else: + txt = msg + + if icon is not None: + txt = '%s -i "%s"' % (txt, join(icons, icon)) + + if time is not None: + txt = "%s -t %s" % (txt, time) + + return notify_send(txt) + + +def debug(msg): + notify(msg, header="Debug", icon="debug.png") diff --git a/utils/cmd.py b/utils/cmd.py index 4020526..f6edcb3 100644 --- a/utils/cmd.py +++ b/utils/cmd.py @@ -69,7 +69,9 @@ def subcommands(root, *args, **kwargs): return type(root, (object,), { - cmd: Command.with_parser("%s %s" % (root, cmd), p) + cmd: staticmethod( + Command.with_parser("%s %s" % (root, cmd), p) + ) for cmd in args } )