From 78e26747110b7930231c6019f8db08a9c43cf2a0 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sat, 10 Jul 2021 15:18:43 +0200 Subject: [PATCH] Further fumbling around in the dark --- tyop.py | 66 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/tyop.py b/tyop.py index f999eae..8aa35ec 100644 --- a/tyop.py +++ b/tyop.py @@ -24,19 +24,17 @@ class Migration: self._validate() if self.args.validate: - self._exit(code=0) + self._exit(code=0, output=False) self.matches = glob(expanduser(self.GLOB)) self.paths = list(set([Path(p).parent for p in self.matches])) - self.log.info(f"Discovered '{self.GLOB}' as user defined glob") - self.log.info(f"Matched paths are: {[m for m in self.matches]}") - self._confirm() + self.log.debug(f"Discovered '{self.GLOB}' as user defined glob") + self.log.debug(f"Matched paths are: {[m for m in self.matches]}") if self.args.reset: - self.log.info("Resetting all changes as requested...") self._clean() - self._exit(code=0) + self._exit(code=0, output=False) try: self._run() @@ -51,8 +49,9 @@ class Migration: yaml.width = 999999 return yaml - def _exit(self, msg="Bailing out on request...", code=1): - self.log.info(msg) + def _exit(self, msg="Bailing out on request...", code=1, output=True): + if output: + self.log.info(msg) exit(code) def _parse(self): @@ -117,38 +116,47 @@ class Migration: except Exception as exception: self._exit(msg=f"Failed to run {cmd}, saw {str(exception)}") - def _confirm(self, bail=True): + def _confirm(self, bail=True, match=None): answer = "" - while answer not in ["y", "Y", "n", "N"]: - answer = input("Does this look good? [y/N]? ").lower() + while answer not in ["y", "n", "s"]: + answer = input("Does this look good? [y/n/s]? ").lower() - result = answer == "y" or answer == "Y" + if answer == "s": + if match: + self._clean(match=match) + self.log.debug(f"Skipping changes to {match}...") + return answer - if not result and bail: + if not answer == "y" and bail: self._exit() - return result + return answer def _message(self): return input("Commit message? ") def _commit(self): - for path in self.paths[:1]: + for path in self.paths: + self.log.debug(f"Running commit logic inside {path}") self._shell("git --no-pager diff", check=False, cwd=path) - self._confirm() + + if self._confirm() == "s": + self.log.debug(f"Skipping {path} as requested...") + continue if not self.commit_msg: self.commit_msg = self._message() + self._shell("git pull", check=False, cwd=path) self._shell("git add .", check=False, cwd=path) self._shell(f"git commit -m '{self.commit_msg}'", check=False, cwd=path) - # self._shell("git push", check=False, cwd=path) + self._shell("git push", check=False, cwd=path) def _validate(self): if not hasattr(self, "GLOB"): self._exit(msg="Missing GLOB attribute!") - self.log.info("Validation succeeded!") + self.log.debug("Validation succeeded!") def _diff(self, match, idx, check=True): command = "git --no-pager diff" @@ -157,13 +165,17 @@ class Migration: if check: output = self._shell(command, cwd=root_path) if not output: - self.log.info("No changes detected, moving on...") + self.log.debug("No changes detected, moving on...") return False - self.log.info(f"Diffing {root_path} ({idx+1}/{self.DIFF_LIMIT})") + self.log.info("=" * 79) + self.log.info(f"{match.upper()}") + self.log.info("=" * 79) + + self.log.debug(f"Diffing {root_path} ({idx+1}/{self.DIFF_LIMIT})") self._shell(command, check=False, cwd=root_path) - return self._confirm() + return self._confirm(match=match) def _clean(self, match=None, branch=False): if match: @@ -172,12 +184,12 @@ class Migration: _paths = self.paths for _path in _paths: - self.log.info(f"Cleaning {_path} of local changes...") + self.log.debug(f"Cleaning {_path} of local changes...") self._shell("git checkout .", check=False, cwd=_path) if branch: - self.log.info("Checking out the default branch...") + self.log.debug("Checking out the default branch...") self._shell( ( "git checkout main > /dev/null 2>&1 " @@ -195,7 +207,7 @@ class Migration: self._clean(match=match, branch=True) with open(match, "r") as handle: - self.log.info(f"Processing {match}...") + self.log.debug(f"Processing {match}...") contents = handle.read() if self.args.yaml: @@ -224,10 +236,10 @@ class Migration: self.log.debug(f"Saved {match} back to the file system...") - self.log.info("Finished migrating files...") - self.log.info("Commencing change commit run...") + self.log.debug("Finished migrating files...") + self.log.debug("Commencing change commit run...") self._commit() - self.log.info("Finished committing changes...") + self.log.debug("Finished committing changes...") self.log.info("Finished! May your tyops be ever glorious!")