Skip to content

Commit

Permalink
I swear I fixed all these
Browse files Browse the repository at this point in the history
  • Loading branch information
nmcspadden committed Aug 22, 2023
1 parent 3cccd32 commit 9b77bd2
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Code/autopkglib/AppDmgVersioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def read_bundle_info(self, path):
with open(plistpath, "rb") as f:
info = plistlib.load(f)
except Exception as error:
raise ProcessorError(f"Can't read {plistpath}: {error}")
raise ProcessorError(f"Can't read {plistpath}: {error}") from error
return info

def main(self):
Expand All @@ -81,7 +81,7 @@ def main(self):
self.output(f"BundleID: {self.env['bundleid']}")
self.output(f"Version: {self.env['version']}")
except BaseException as err:
raise ProcessorError(err)
raise ProcessorError(err) from err
finally:
self.unmount(self.env["dmg_path"])

Expand Down
14 changes: 7 additions & 7 deletions Code/autopkglib/AppPkgCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def read_info_plist(self, app_path):
with open(plistpath, "rb") as f:
plist = plistlib.load(f)
except Exception as err:
raise ProcessorError(f"Can't read {plistpath}: {err}")
raise ProcessorError(f"Can't read {plistpath}: {err}") from err
return plist

def package_app(self, app_path):
Expand All @@ -116,16 +116,16 @@ def package_app(self, app_path):
f"The key '{version_key}' does not exist in the App "
f"Bundle's Info.plist! ({app_path}/Contents/Info.plist) "
f"Please check the recipe and try again."
)
) from None
# Trap all other errors.
except BaseException as err:
raise ProcessorError(err)
raise ProcessorError(err) from err
if not self.env.get("bundleid"):
try:
self.env["bundleid"] = infoplist["CFBundleIdentifier"]
self.output(f"BundleID: {self.env['bundleid']}")
except BaseException as err:
raise ProcessorError(err)
raise ProcessorError(err) from err

# get pkgdir and pkgname
if self.env.get("pkg_path"):
Expand Down Expand Up @@ -160,11 +160,11 @@ def package_app(self, app_path):
else:
os.unlink(pkgroot)
except OSError as err:
raise ProcessorError(f"Can't remove {pkgroot}: {err.strerror}")
raise ProcessorError(f"Can't remove {pkgroot}: {err.strerror}") from err
try:
os.makedirs(os.path.join(pkgroot, "Applications"), 0o775)
except OSError as err:
raise ProcessorError(f"Could not create pkgroot: {err.strerror}")
raise ProcessorError(f"Could not create pkgroot: {err.strerror}") from err

app_name = os.path.basename(app_path)
source_item = app_path
Expand All @@ -180,7 +180,7 @@ def package_app(self, app_path):
except OSError as err:
raise ProcessorError(
f"Can't copy {source_item} to {dest_item}: {err.strerror}"
)
) from err

# build a package request
request = {
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/BrewCaskInfoProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def main(self):
try:
urlobj = urllib.request.urlopen(cask_url)
except urllib.error.HTTPError as err:
raise ProcessorError(f"Error opening URL {cask_url}: {err}")
raise ProcessorError(f"Error opening URL {cask_url}: {err}") from err

formula_data = urlobj.read()
parsed = self.parse_formula(formula_data)
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/ChocolateyPackager.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def main(self):
},
}
except Exception:
raise ProcessorError("Chocolatey packaging failed unexpectedly.")
raise ProcessorError("Chocolatey packaging failed unexpectedly.") from None
finally:
if not keep_build_directory and build_dir is not None:
rmtree(build_dir)
Expand Down
4 changes: 2 additions & 2 deletions Code/autopkglib/Copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def copy(self, source_item, dest_item, overwrite=False):
else:
os.unlink(dest_item)
except OSError as err:
raise ProcessorError(f"Can't remove {dest_item}: {err.strerror}")
raise ProcessorError(f"Can't remove {dest_item}: {err.strerror}") from err

# Copy file or directory.
try:
Expand All @@ -75,7 +75,7 @@ def copy(self, source_item, dest_item, overwrite=False):
shutil.copy(source_item, dest_item)
self.output(f"Copied {source_item} to {dest_item}")
except BaseException as err:
raise ProcessorError(f"Can't copy {source_item} to {dest_item}: {err}")
raise ProcessorError(f"Can't copy {source_item} to {dest_item}: {err}") from err

def main(self):
source_path = self.env["source_path"]
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/DmgCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def main(self):
except OSError as err:
raise ProcessorError(
f"hdiutil execution failed with error code {err.errno}: {err.strerror}"
)
) from err
if proc.returncode != 0:
raise ProcessorError(f"creation of {self.env['dmg_path']} failed: {stderr}")

Expand Down
4 changes: 2 additions & 2 deletions Code/autopkglib/FileCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def main(self):
fileref.write(self.env["file_content"])
self.output(f"Created file at {self.env['file_path']}")
except BaseException as err:
raise ProcessorError(f"Can't create file at {self.env['file_path']}: {err}")
raise ProcessorError(f"Can't create file at {self.env['file_path']}: {err}") from err
if "file_mode" in self.env:
try:
os.chmod(self.env["file_path"], int(self.env["file_mode"], 8))
except BaseException as err:
raise ProcessorError(
f"Can't set mode of {self.env['file_path']} to "
f"{self.env['file_mode']}: {err}"
)
) from err


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/FlatPkgPacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def flatten(self, source_dir, dest_pkg):
["/usr/sbin/pkgutil", "--flatten", source_dir, dest_pkg]
)
except subprocess.CalledProcessError as err:
raise ProcessorError(f"{err} flattening {source_dir}")
raise ProcessorError(f"{err} flattening {source_dir}") from err

def main(self):
source_dir = self.env.get("source_flatpkg_dir")
Expand Down
10 changes: 5 additions & 5 deletions Code/autopkglib/FlatPkgUnpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def unpack_flat_pkg(self):
except OSError as err:
raise ProcessorError(
f"Can't create {self.env['destination_path']}: {err.strerror}"
)
) from err
elif self.env.get("purge_destination"):
for entry in os.listdir(self.env["destination_path"]):
path = os.path.join(self.env["destination_path"], entry)
Expand All @@ -91,7 +91,7 @@ def unpack_flat_pkg(self):
else:
os.unlink(path)
except OSError as err:
raise ProcessorError(f"Can't remove {path}: {err.strerror}")
raise ProcessorError(f"Can't remove {path}: {err.strerror}") from err

if self.env.get("skip_payload"):
self.xar_expand()
Expand All @@ -118,7 +118,7 @@ def xar_expand(self):
except OSError as err:
raise ProcessorError(
f"xar execution failed with error code {err.errno}: {err.strerror}"
)
) from err
if proc.returncode != 0:
raise ProcessorError(
f"extraction of {self.env['flat_pkg_path']} with xar failed: {stderr}"
Expand All @@ -133,7 +133,7 @@ def pkgutil_expand(self):
except OSError as err:
raise ProcessorError(
f"Can't remove {self.env['destination_path']}: {err.strerror}"
)
) from err

try:
pkgutilcmd = [
Expand All @@ -149,7 +149,7 @@ def pkgutil_expand(self):
except OSError as err:
raise ProcessorError(
f"pkgutil execution failed with error code {err.errno}: {err.strerror}"
)
) from err
if proc.returncode != 0:
raise ProcessorError(
f"extraction of {self.env['flat_pkg_path']} with pkgutil failed: "
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/InstallFromDMG.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def connect(self):
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.connect(AUTOPKGINSTALLD_SOCKET)
except OSError as err:
raise ProcessorError(f"Couldn't connect to autopkginstalld: {err.strerror}")
raise ProcessorError(f"Couldn't connect to autopkginstalld: {err.strerror}") from err

def send_request(self, request):
"""Send an install request to autopkginstalld"""
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/MunkiCatalogBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def main(self):
raise ProcessorError(
f"makecatalog execution failed with error code {err.errno}: "
f"{err.strerror}"
)
) from err
if proc.returncode != 0:
raise ProcessorError(f"makecatalogs failed: {err_out}")
self.output("Munki catalogs rebuilt!")
Expand Down
2 changes: 1 addition & 1 deletion Code/autopkglib/PathDeleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main(self):
)
self.output(f"Deleted {path}")
except OSError as err:
raise ProcessorError(f"Could not remove {path}: {err}")
raise ProcessorError(f"Could not remove {path}: {err}") from err


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions Code/autopkglib/Symlinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main(self):
except OSError as err:
raise ProcessorError(
f"Can't remove {destination_path}: {err.strerror}"
)
) from err

# Make symlink.
try:
Expand All @@ -60,7 +60,7 @@ def main(self):
except BaseException as err:
raise ProcessorError(
f"Can't symlink {source_path} to {destination_path}: {err}"
)
) from err


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions Code/autopkglib/Unarchiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _extract_native(
except Exception as ex:
raise ProcessorError(
f"Unarchiving {archive_path} with <native extractor> failed: {ex}"
)
) from ex

def _extract_utility(
self, format: str, archive_path: str, destination_path: str
Expand Down Expand Up @@ -158,7 +158,7 @@ def _extract_utility(
raise ProcessorError(
f"{os.path.basename(cmd[0])} execution failed with error code "
f"{err.errno}: {err.strerror}"
)
) from err
if proc.returncode != 0:
raise ProcessorError(
f"Unarchiving {archive_path} with {os.path.basename(cmd[0])} failed: "
Expand All @@ -183,7 +183,7 @@ def main(self):
try:
os.makedirs(destination_path)
except OSError as err:
raise ProcessorError(f"Can't create {destination_path}: {err.strerror}")
raise ProcessorError(f"Can't create {destination_path}: {err.strerror}") from err
elif self.env.get("purge_destination"):
for entry in os.listdir(destination_path):
path = os.path.join(destination_path, entry)
Expand All @@ -193,7 +193,7 @@ def main(self):
else:
os.unlink(path)
except OSError as err:
raise ProcessorError(f"Can't remove {path}: {err.strerror}")
raise ProcessorError(f"Can't remove {path}: {err.strerror}") from err

fmt = self.env.get("archive_format")
if fmt is None:
Expand Down

0 comments on commit 9b77bd2

Please sign in to comment.