Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize subprocess calls and use f-strings instead of .format(), trim whitespace, adjust DeprecationWarning MinimumVersion #675

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/homebysix/pre-commit-macadmin
rev: v1.16.1
rev: v1.17.0
hooks:
- id: check-autopkg-recipes
args: ["--recipe-prefix=com.github.homebysix.", "--strict", "--"]
Expand All @@ -9,7 +9,7 @@ repos:
exclude: ^Corel\/
- id: forbid-autopkg-trust-info
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=100"]
Expand All @@ -28,23 +28,23 @@ repos:
- id: trailing-whitespace
args: ["--markdown-linebreak-ext=md"]
- repo: https://github.com/ambv/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies: [black==24.1.1]
- repo: https://github.com/PyCQA/pylint
rev: v3.2.3
additional_dependencies: [black==24.10.0]
- repo: https://github.com/pycqa/pylint
rev: v3.3.3
hooks:
- id: pylint
2 changes: 1 addition & 1 deletion 25io/Mou.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Mou</string>
</dict>
<key>MinimumVersion</key>
<string>1.0.0</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion 25io/Smaller.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Smaller</string>
</dict>
<key>MinimumVersion</key>
<string>1.0.0</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
35 changes: 15 additions & 20 deletions BinaryFileVersioner/BinaryFileVersioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

import os
import re
import shlex
from subprocess import PIPE, Popen
import subprocess

from autopkglib import Processor, ProcessorError # noqa: F401

Expand Down Expand Up @@ -47,31 +46,27 @@ def main(self):
if not os.path.isfile("/bin/launchctl"):
raise ProcessorError("/bin/launchctl is not present on this Mac.")

cmd = "/bin/launchctl plist __TEXT,__info_plist '{}'".format(
self.env["input_file_path"]
)
with Popen(
shlex.split(cmd.strip()), stdin=PIPE, stdout=PIPE, stderr=PIPE, text=True
) as proc:
out, err = proc.communicate()
exitcode = proc.returncode

if exitcode != 0:
raise ProcessorError("/bin/launchctl failed with error: {}".format(err))
cmd = [
"/bin/launchctl",
"plist",
"__TEXT,__info_plist",
self.env["input_file_path"],
]
proc = subprocess.run(cmd, check=False, capture_output=True, text=True)
if proc.returncode != 0:
raise ProcessorError(f"/bin/launchctl failed with error: {proc.stderr}")

version_key = self.env.get("plist_version_key", "CFBundleShortVersionString")
pattern = '"{}" = "(.*)";'.format(version_key)
match = re.search(pattern, out)
pattern = f'"{version_key}" = "(.*)";'
match = re.search(pattern, proc.stdout)

if match:
self.env["version"] = match.group(1)
self.output("Found version: {}".format(self.env["version"]))
self.output(f"Found version: {self.env['version']}")
else:
raise ProcessorError(
"Unable to find a {} key in {}.".format(
self.env.get("plist_version_key", "CFBundleShortVersionString"),
self.env["input_file_path"],
)
f"Unable to find a {self.env.get('plist_version_key', 'CFBundleShortVersionString')} "
f"key in {self.env['input_file_path']}."
)


Expand Down
2 changes: 1 addition & 1 deletion Boom/Boom2.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Boom 2</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion CaseApps/SofaControl.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Sofa Control</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion CaseApps/Tags.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Tags</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions Cocktail/CocktailReleasesInfoProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CocktailReleasesInfoProvider(URLGetter):
"major_version": {
"required": False,
"description": "Major version of macOS for which to download a "
"compatible Cocktail release. Default is %s" % DEFAULT_MAJOR_VERSION,
f"compatible Cocktail release. Default is {DEFAULT_MAJOR_VERSION}.",
}
}
output_variables = {
Expand All @@ -107,7 +107,7 @@ def main(self):

# Determine and set output variables
self.env["url"] = BASE_URL + RELEASES[major_version]["filename"]
self.output("Found URL: %s" % self.env["url"])
self.output(f"Found URL: {self.env['url']}")
self.env["bundle_id"] = RELEASES[major_version]["bundle_id"]

# Determine and set code signature verification cert leaf
Expand Down
9 changes: 3 additions & 6 deletions Corel/CorelSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def license_info(self):
"""Return the product code and DTA file installed path for this Corel
product by parsing the License.plist file in the Registration bundle."""

license_path = (
"%s/plugins/Registration.bundle/Contents/Resources/License.plist"
% self.env["RECIPE_CACHE_DIR"]
)
license_path = f"{self.env['RECIPE_CACHE_DIR']}/plugins/Registration.bundle/Contents/Resources/License.plist"
with open(license_path, "rb") as openfile:
license_info = plistlib.load(openfile)
return license_info["ProductID"], license_info["DTAFileInstalledPath"]
Expand All @@ -65,7 +62,7 @@ def main(self):

if not os.path.isfile(self.env["flat_pkg_path"]):
raise ProcessorError(
"Provided flat_pkg_path does not exist: %s" % self.env["flat_pkg_path"]
f"Provided flat_pkg_path does not exist: {self.env['flat_pkg_path']}"
)

create_dta = os.path.join(self.env["RECIPE_CACHE_DIR"], "plugins", "create_dta")
Expand All @@ -78,7 +75,7 @@ def main(self):
self.env["dta_path"] = dta_path
self.env["dta_installed_path"] = dta_installed_path
self.env["product_code"] = product_code
self.output("Serialized DTA file: %s" % dta_path)
self.output(f"Serialized DTA file: {dta_path}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion DeliciousMonster/DeliciousLibrary.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Delicious Library 3</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion Deltopia/DeltaWalker.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>Description</key>
<string>Downloads the latest version of DeltaWalker.

Valid values for ARCH include:
- x64 (default; Intel)
- aarch64 (Apple Silicon)
Expand Down
2 changes: 1 addition & 1 deletion FindAndReplace/FindAndReplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main(self):
input_string = self.env["input_string"]
find = self.env["find"]
replace = self.env["replace"]
self.output('Replacing "%s" with "%s" in "%s".' % (find, replace, input_string))
self.output(f'Replacing "{find}" with "{replace}" in "{input_string}".')
self.env["output_string"] = self.env["input_string"].replace(find, replace)


Expand Down
2 changes: 1 addition & 1 deletion Folio/Folio.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Folio</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion GeometersSketchpad5/GSP5.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>Description</key>
<string>Downloads the current release version of Geometer's Sketchpad 5.

Not using CodeSignatureVerifier because version 5.06 resource envelope is obsolete (version 1 signature).</string>
<key>Identifier</key>
<string>com.github.homebysix.download.GSP5</string>
Expand Down
2 changes: 1 addition & 1 deletion Gikken/Tokens.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ upgrade from the old app from developer Peer Assembly.</string>
<string>Tokens</string>
</dict>
<key>MinimumVersion</key>
<string>1.0.0</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
6 changes: 3 additions & 3 deletions GoToMeeting/GoToMeetingURLProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GoToMeetingURLProvider(URLGetter):
"base_url": {
"required": False,
"description": "URL for the GoToMeeting "
"releases JSON feed. Default is %s" % BASE_URL,
f"releases JSON feed. Default is {BASE_URL}.",
}
}
output_variables = {
Expand Down Expand Up @@ -108,9 +108,9 @@ def main(self):
base_url = self.env.get("base_url", BASE_URL)
g2m_url, g2m_build = self.get_g2m_info(base_url)
self.env["url"] = g2m_url
self.output("Found URL: %s" % self.env["url"])
self.output(f"Found URL: {self.env['url']}")
self.env["build"] = g2m_build
self.output("Build number: %s" % self.env["build"])
self.output(f"Build number: {self.env['build']}")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions Kite/Kite.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<string>Kite</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand All @@ -22,7 +22,7 @@
<dict>
<key>warning_message</key>
<string>Kite development ceased in 2022. (Details: https://web.archive.org/web/20241210091357/https://www.kite.com/blog/product/kite-is-saying-farewell/)

This recipe is deprecated and will be removed in the future.</string>
</dict>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion LiveSurfaceContext/LiveSurfaceContext.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>LiveSurface Context</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion NDI/PalakisNDIRuntime.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<string>PalakisNDIRuntime</string>
</dict>
<key>MinimumVersion</key>
<string>1.0</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion NothingMagical/Whiskey.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Whiskey</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
8 changes: 4 additions & 4 deletions Perforce/PerforceURLProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def recurse_subdirs(self, path, url):
# Add trailing slash to prevent constant 301 redirects.
if not url.endswith("/"):
url = url + "/"
self.output("Searching %s for %s" % (url, path[0]))
self.output(f"Searching {url} for {path[0]}")

# Get content of directory listing and parse for links matching path regex.
html = self.download(url, text=True)
link_pattern = re.compile('<a href="(%s)">' % path[0])
link_pattern = re.compile(f'<a href="({path[0]})">')
links = re.findall(link_pattern, html)
if len(links) == 0:
# No match, toss back to parent caller and continue recursing.
Expand Down Expand Up @@ -105,10 +105,10 @@ def main(self):
url = self.recurse_subdirs(info["path"], BASE_URL + "/" + info["start"])
if not url:
raise ProcessorError(
"Did not find a matching download URL for %s." % self.env["product"]
f"Did not find a matching download URL for {self.env['product']}."
)
self.env["url"] = url
self.output("Found url: %s" % self.env["url"])
self.output(f"Found url: {self.env['url']}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion ProfitTrain/ProfitTrain.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>ProfitTrain</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
4 changes: 2 additions & 2 deletions R/RProjectURLProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def main(self):

# Set URL and version in environment
self.env["url"] = url_base + m.groupdict()["file"]
self.output("Found url: %s" % self.env["url"])
self.output(f"Found url: {self.env['url']}")
self.env["version"] = m.groupdict()["vers"]
self.output("Found version: %s" % self.env["version"])
self.output(f"Found version: {self.env['version']}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion RecordIt/RecordIt.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>RecordIt</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion Tenor/GIFforMac.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>GIF for Mac</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
2 changes: 1 addition & 1 deletion VersionSplitter/VersionSplitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(self):
split_on = self.env.get("split_on", " ")
index = self.env.get("index", 0)
self.env["version"] = self.env["version"].split(split_on)[index]
self.output("Split version: {}".format(self.env["version"]))
self.output(f"Split version: {self.env['version']}")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion VirtualHost/VirtualHostX.download.recipe
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>VirtualHostX</string>
</dict>
<key>MinimumVersion</key>
<string>0.6.1</string>
<string>1.1</string>
<key>Process</key>
<array>
<dict>
Expand Down
Loading
Loading