More hacking, it is kinda working a bit more

This commit is contained in:
decentral1se 2021-07-10 14:41:30 +02:00
parent 9983666f77
commit cc547ce7b0
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 16 additions and 17 deletions

33
tyop.py
View File

@ -48,6 +48,7 @@ class Migration:
yaml.preserve_quotes = True
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.allow_duplicate_keys = True
yaml.width = 999999
return yaml
def _exit(self, msg="Bailing out on request...", code=1):
@ -132,17 +133,17 @@ class Migration:
def _message(self):
return input("Commit message? ")
def _commit(self, match):
root_path = Path(match).parent
self._shell("git --no-pager diff", check=False, cwd=root_path)
if self._confirm(bail=False):
def _commit(self):
for path in self.paths[:1]:
self._shell("git --no-pager diff", check=False, cwd=path)
self._confirm()
if not self.commit_msg:
self.commit_msg = self._message()
self._shell("git add .", check=False, cwd=root_path)
self._shell(
f"git commit -vm '{self.commit_msg}'", check=False, cwd=root_path
)
self._shell("git push", check=False, cwd=root_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)
def _validate(self):
if not hasattr(self, "GLOB"):
@ -157,12 +158,12 @@ class Migration:
output = self._shell(command, cwd=root_path)
if not output:
self.log.info("No changes detected, moving on...")
return
return False
self.log.info(f"Diffing {root_path} ({idx+1}/{self.DIFF_LIMIT})")
self._shell(command, check=False, cwd=root_path)
self._confirm()
return self._confirm()
def _clean(self, match=None, branch=False):
if match:
@ -207,7 +208,6 @@ class Migration:
contents = self.yaml.load(contents)
original = contents.copy()
migrated = self.migrate(contents)
self.log.debug(f"Migrated {match}...")
@ -218,17 +218,16 @@ class Migration:
else:
handle.write(migrated)
if idx < self.DIFF_LIMIT:
self._diff(match, idx=idx, check=True)
idx += 1
if idx <= self.DIFF_LIMIT:
if self._diff(match, idx=idx, check=True):
idx += 1
self.log.debug(f"Saved {match} back to the file system...")
self.log.info("Finished migrating files...")
self.log.info("Commencing change commit run...")
for path in self.paths:
self._commit(path)
self._commit()
self.log.info("Finished committing changes...")
self.log.info("Finished! May your tyops be ever glorious!")