Addon Manager: Pylint and Black cleanup

This commit is contained in:
Chris Hennes
2023-03-26 19:01:33 -05:00
parent fcda1ffc25
commit a5ddf3d255
3 changed files with 85 additions and 76 deletions

View File

@@ -47,8 +47,9 @@ class GitFailed(RuntimeError):
class GitManager:
"""A class to manage access to git: mostly just provides a simple wrapper around the basic
command-line calls. Provides optional asynchronous access to clone and update."""
"""A class to manage access to git: mostly just provides a simple wrapper around
the basic command-line calls. Provides optional asynchronous access to clone and
update."""
def __init__(self):
self.git_exe = None
@@ -110,9 +111,10 @@ class GitManager:
os.path.join(local_path, "ADDON_DISABLED"), "w", encoding="utf-8"
) as f:
f.write(
"This is a backup of an addon that failed to update cleanly so was re-cloned. "
+ "It was disabled by the Addon Manager's git update facility and can be "
+ "safely deleted if the addon is working properly."
"This is a backup of an addon that failed to update cleanly so "
"was re-cloned. It was disabled by the Addon Manager's git update "
"facility and can be safely deleted if the addon is working "
"properly."
)
os.chdir("..")
os.rename(local_path, local_path + ".backup" + str(time.time()))
@@ -193,15 +195,16 @@ class GitManager:
return branch
def repair(self, remote, local_path):
"""Assumes that local_path is supposed to be a local clone of the given remote, and
ensures that it is. Note that any local changes in local_path will be destroyed. This
is achieved by archiving the old path, cloning an entirely new copy, and then deleting
the old directory."""
"""Assumes that local_path is supposed to be a local clone of the given
remote, and ensures that it is. Note that any local changes in local_path
will be destroyed. This is achieved by archiving the old path, cloning an
entirely new copy, and then deleting the old directory."""
original_cwd = os.getcwd()
# Make sure we are not currently in that directory, otherwise on Windows the "rename"
# will fail. To guarantee we aren't in it, change to it, then shift up one.
# Make sure we are not currently in that directory, otherwise on Windows the
# "rename" will fail. To guarantee we aren't in it, change to it, then shift
# up one.
os.chdir(local_path)
os.chdir("..")
backup_path = local_path + ".backup" + str(time.time())
@@ -232,7 +235,6 @@ class GitManager:
result = "(unknown remote)"
for line in lines:
if line.endswith("(fetch)"):
# The line looks like:
# origin https://some/sort/of/path (fetch)
@@ -265,8 +267,10 @@ class GitManager:
return branches
def get_last_committers(self, local_path, n=10):
"""Examine the last n entries of the commit history, and return a list of all the
committers, their email addresses, and how many commits each one is responsible for."""
"""Examine the last n entries of the commit history, and return a list of all
the committers, their email addresses, and how many commits each one is
responsible for.
"""
old_dir = os.getcwd()
os.chdir(local_path)
authors = self._synchronous_call_git(["log", f"-{n}", "--format=%cN"]).split(
@@ -294,8 +298,10 @@ class GitManager:
return result_dict
def get_last_authors(self, local_path, n=10):
"""Examine the last n entries of the commit history, and return a list of all the
authors, their email addresses, and how many commits each one is responsible for."""
"""Examine the last n entries of the commit history, and return a list of all
the authors, their email addresses, and how many commits each one is
responsible for.
"""
old_dir = os.getcwd()
os.chdir(local_path)
authors = self._synchronous_call_git(["log", f"-{n}", "--format=%aN"])
@@ -318,12 +324,12 @@ class GitManager:
def _find_git(self):
# Find git. In preference order
# A) The value of the GitExecutable user preference
# B) The executable located in the same bin directory as FreeCAD and called "git"
# B) The executable located in the same directory as FreeCAD and called "git"
# C) The result of a shutil search for your system's "git" executable
prefs = fci.ParamGet("User parameter:BaseApp/Preferences/Addons")
git_exe = prefs.GetString("GitExecutable", "Not set")
if not git_exe or git_exe == "Not set" or not os.path.exists(git_exe):
fc_dir = fci.DataPaths().home_dir()
fc_dir = fci.DataPaths().home_dir
git_exe = os.path.join(fc_dir, "bin", "git")
if "Windows" in platform.system():
git_exe += ".exe"
@@ -349,7 +355,7 @@ class GitManager:
f"Git returned a non-zero exit status: {e.returncode}\n"
+ f"Called with: {' '.join(final_args)}\n\n"
+ f"Returned stderr:\n{e.stderr}"
)
) from e
return proc.stdout