Addon Manager: Update to Python 3.8

This commit is contained in:
Chris Hennes
2022-12-17 18:33:40 -06:00
parent 89c191e160
commit 95f474a86a
8 changed files with 14 additions and 15 deletions

View File

@@ -518,7 +518,7 @@ class CommandAddonManager:
use_cache = not self.update_cache
if use_cache:
if os.path.isfile(utils.get_cache_file_name("package_cache.json")):
with open(utils.get_cache_file_name("package_cache.json"), "r") as f:
with open(utils.get_cache_file_name("package_cache.json")) as f:
data = f.read()
try:
from_json = json.loads(data)
@@ -1072,7 +1072,7 @@ class CommandAddonManager:
uninstall_script = os.path.join(clonedir, "uninstall.py")
if os.path.exists(uninstall_script):
try:
with open(uninstall_script, "r") as f:
with open(uninstall_script) as f:
exec(f.read())
except Exception:
FreeCAD.Console.PrintError(

View File

@@ -546,7 +546,7 @@ if HAVE_QTNETWORK:
f = self.file_buffers[index]
try:
f.write(buffer.data())
except IOError as e:
except OSError as e:
if HAVE_FREECAD:
FreeCAD.Console.PrintError(
f"Network Manager internal error: {str(e)}"

View File

@@ -607,7 +607,7 @@ class DeveloperMode:
if filename.endswith(".py"):
with open(
os.path.join(dirpath, filename), "r", encoding="utf-8"
os.path.join(dirpath, filename), encoding="utf-8"
) as f:
contents = f.read()
version_strings = vermin.version_strings(
@@ -677,8 +677,7 @@ class DeveloperMode:
vendor_path,
"vermin",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
check=True,
)
FreeCAD.Console.PrintMessage(proc.stdout.decode())

View File

@@ -262,7 +262,7 @@ class Predictor:
for name in valid_names:
full_path = os.path.join(self.path, name)
if os.path.exists(full_path):
with open(full_path, "r", encoding="utf-8") as f:
with open(full_path, encoding="utf-8") as f:
self.readme_data = f.read()
return
@@ -279,7 +279,7 @@ class Predictor:
for name in valid_names:
full_path = os.path.join(self.path.replace("/", os.path.sep), name)
if os.path.isfile(full_path):
with open(full_path, "r", encoding="utf-8") as f:
with open(full_path, encoding="utf-8") as f:
self.license_data = f.read()
self.license_file = name
return

View File

@@ -168,7 +168,7 @@ class AddonInstaller(QtCore.QObject):
os.path.dirname(__file__), "ALLOWED_PYTHON_PACKAGES.txt"
)
if os.path.exists(allow_file):
with open(allow_file, "r", encoding="utf8") as f:
with open(allow_file, encoding="utf8") as f:
lines = f.readlines()
for line in lines:
if line and len(line) > 0 and line[0] != "#":

View File

@@ -417,7 +417,7 @@ class Macro:
try:
with codecs.open(macro_path, "w", "utf-8") as macrofile:
macrofile.write(self.code)
except IOError:
except OSError:
return False, [f"Failed to write {macro_path}"]
# Copy related files, which are supposed to be given relative to
# self.src_filename.
@@ -446,7 +446,7 @@ class Macro:
)
try:
shutil.copy(self.icon, dst_file)
except IOError:
except OSError:
warnings.append(f"Failed to copy icon to {dst_file}")
elif self.icon not in self.other_files:
self.other_files.append(self.icon)
@@ -478,7 +478,7 @@ class Macro:
self._fetch_single_file(other_file, src_file, dst_file, warnings)
try:
shutil.copy(src_file, dst_file)
except IOError:
except OSError:
warnings.append(f"Failed to copy {src_file} to {dst_file}")
return True # No fatal errors, but some files may have failed to copy

View File

@@ -280,7 +280,7 @@ def get_macro_version_from_file(filename: str) -> str:
as well as a reference to __date__"""
date = ""
with open(filename, "r", errors="ignore", encoding="utf-8") as f:
with open(filename, errors="ignore", encoding="utf-8") as f:
line_counter = 0
max_lines_to_scan = 200
while line_counter < max_lines_to_scan:

View File

@@ -441,7 +441,7 @@ class LoadPackagesFromCacheWorker(QtCore.QThread):
def run(self):
"""Rarely called directly: create an instance and call start() on it instead to
launch in a new thread"""
with open(self.cache_file, "r", encoding="utf-8") as f:
with open(self.cache_file, encoding="utf-8") as f:
data = f.read()
if data:
dict_data = json.loads(data)
@@ -480,7 +480,7 @@ class LoadMacrosFromCacheWorker(QtCore.QThread):
"""Rarely called directly: create an instance and call start() on it instead to
launch in a new thread"""
with open(self.cache_file, "r", encoding="utf-8") as f:
with open(self.cache_file, encoding="utf-8") as f:
data = f.read()
dict_data = json.loads(data)
for item in dict_data: