Add documentation and functionality to progress hook (not used yet)

ticket-769
Vadim vtroshchinskiy 2024-10-09 13:09:47 +02:00
parent 845ed16fad
commit 6646eb5af3
1 changed files with 35 additions and 1 deletions

View File

@ -37,12 +37,46 @@ import posix1e
import blkid
class OgProgressPrinter(git.RemoteProgress):
"""
A class to print progress updates for Git operations.
This class extends `git.RemoteProgress` to provide custom logging and
printing of progress updates to the standard error stream.
Attributes:
logger (Logger): The logger instance used to log debug messages.
prev_len (int): The length of the previous status string printed.
Methods:
__init__(parentLogger):
Initializes the OgProgressPrinter with a logger instance.
update(op_code, cur_count, max_count=None, message=""):
Updates the progress status and prints it to the standard error stream.
__del__():
Ensures a newline is printed when the instance is deleted.
"""
def __init__(self, parentLogger):
super().__init__()
self.logger = parentLogger
self.prev_len = 0
print("\n", file=sys.stderr)
def update(self, op_code, cur_count, max_count=None, message=""):
self.logger.debug(f"Progress: {op_code} {cur_count}/{max_count}: {message}")
status_string = "Progress: %s %d/%d: %s" % (op_code, cur_count, max_count, message)
padded_string = status_string.rjust(self.prev_len, " ")
self.prev_len = len(status_string)
print(f"\r{padded_string}", file=sys.stderr)
def __del__(self):
print("\n", file=sys.stderr)
class OperationTimer:
def __init__(self, parent, operation_name):
self.operation_name = operation_name
@ -1467,7 +1501,7 @@ class OpengnsysGitLibrary:
# repo.heads.master.set_tracking_branch(origin.refs.master)
self.logger.info("Uploading to ogrepository")
repo.git.push("--set-upstream", "origin", repo.head.ref, "--force") # force = True)
repo.git.push("--set-upstream", "origin", repo.head.ref, "--force")
def cloneRepo(self, repo_name, destination, boot_device):
"""