mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 03:46:55 +00:00
Address some pylint issues (#1155)
* Address cyclic-import. * Address redefined-builtin. * Address redefined-argument-from-local. * Address many redefined-outer-name. * Address pointless-string-statement. * No longer needed due to separate bugfix. * Address useless-return. * Address possibly-used-before-assignment. * Add TODOs. * Address super-init-not-called. * Address function-redefined. * Address unspecified-encoding. * Clean up more imports.
This commit is contained in:
@@ -499,6 +499,8 @@ class ServicesManager(BaseComposeManager):
|
||||
result = self.cmd_restart()
|
||||
elif self.state == "absent":
|
||||
result = self.cmd_down()
|
||||
else:
|
||||
raise AssertionError("Unexpected state")
|
||||
|
||||
result["containers"] = self.list_containers()
|
||||
result["images"] = self.list_images()
|
||||
|
||||
@@ -570,7 +570,7 @@ class ImageManager(DockerBaseClass):
|
||||
self.results["changed"] = True
|
||||
if not self.check_mode:
|
||||
self.results["image"], dummy = self.client.pull_image(
|
||||
self.name, tag=self.tag, platform=self.pull_platform
|
||||
self.name, tag=self.tag, image_platform=self.pull_platform
|
||||
)
|
||||
elif self.source == "local":
|
||||
if image is None:
|
||||
@@ -891,7 +891,7 @@ class ImageManager(DockerBaseClass):
|
||||
dockerignore = os.path.join(self.build_path, ".dockerignore")
|
||||
exclude = None
|
||||
if os.path.exists(dockerignore):
|
||||
with open(dockerignore) as f:
|
||||
with open(dockerignore, "rt", encoding="utf-8") as f:
|
||||
exclude = list(
|
||||
filter(
|
||||
lambda x: x != "" and x[0] != "#",
|
||||
|
||||
@@ -318,11 +318,11 @@ def dict_to_list(dictionary, concat="="):
|
||||
return [f"{k}{concat}{v}" for k, v in sorted(dictionary.items())]
|
||||
|
||||
|
||||
def _quote_csv(input):
|
||||
if input.strip() == input and all(i not in input for i in '",\r\n'):
|
||||
return input
|
||||
input = input.replace('"', '""')
|
||||
return f'"{input}"'
|
||||
def _quote_csv(text):
|
||||
if text.strip() == text and all(i not in text for i in '",\r\n'):
|
||||
return text
|
||||
text = text.replace('"', '""')
|
||||
return f'"{text}"'
|
||||
|
||||
|
||||
class ImageBuilder(DockerBaseClass):
|
||||
|
||||
@@ -181,7 +181,7 @@ class ImagePuller(DockerBaseClass):
|
||||
results["diff"]["after"] = image_info(dict(Id="unknown"))
|
||||
else:
|
||||
results["image"], not_changed = self.client.pull_image(
|
||||
self.name, tag=self.tag, platform=self.platform
|
||||
self.name, tag=self.tag, image_platform=self.platform
|
||||
)
|
||||
results["changed"] = not not_changed
|
||||
results["diff"]["after"] = image_info(results["image"])
|
||||
|
||||
@@ -161,7 +161,7 @@ class DockerFileStore(object):
|
||||
|
||||
try:
|
||||
# Attempt to read the existing config.
|
||||
with open(self._config_path, "r") as f:
|
||||
with open(self._config_path, "rt", encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
except (ValueError, IOError):
|
||||
# No config found or an invalid config found so we'll ignore it.
|
||||
@@ -197,9 +197,9 @@ class DockerFileStore(object):
|
||||
Write config back out to disk.
|
||||
"""
|
||||
# Make sure directory exists
|
||||
dir = os.path.dirname(self._config_path)
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
directory = os.path.dirname(self._config_path)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
# Write config; make sure it has permissions 0x600
|
||||
content = json.dumps(self._config, indent=4, sort_keys=True).encode("utf-8")
|
||||
f = os.open(self._config_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
@@ -214,13 +214,13 @@ class DockerFileStore(object):
|
||||
"""
|
||||
|
||||
b64auth = base64.b64encode(to_bytes(username) + b":" + to_bytes(password))
|
||||
auth = to_text(b64auth)
|
||||
tauth = to_text(b64auth)
|
||||
|
||||
# build up the auth structure
|
||||
if "auths" not in self._config:
|
||||
self._config["auths"] = dict()
|
||||
|
||||
self._config["auths"][server] = dict(auth=auth)
|
||||
self._config["auths"][server] = dict(auth=tauth)
|
||||
|
||||
self._write()
|
||||
|
||||
@@ -294,7 +294,7 @@ class LoginManager(DockerBaseClass):
|
||||
self.client._auth_configs.add_auth(
|
||||
self.registry_url or auth.INDEX_NAME, req_data
|
||||
)
|
||||
return self.client._result(response, json=True)
|
||||
return self.client._result(response, get_json=True)
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
|
||||
@@ -504,7 +504,7 @@ class SwarmManager(DockerBaseClass):
|
||||
unlock_key = self.get_unlock_key()
|
||||
self.swarm_info.update(unlock_key)
|
||||
except APIError:
|
||||
return
|
||||
pass
|
||||
|
||||
def get_unlock_key(self):
|
||||
default = {"UnlockKey": None}
|
||||
|
||||
Reference in New Issue
Block a user