1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-12 15:05:07 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -272,20 +272,19 @@ from ansible.module_utils.basic import AnsibleModule
class DeployHelper:
def __init__(self, module):
self.module = module
self.file_args = module.load_file_common_arguments(module.params)
self.clean = module.params['clean']
self.current_path = module.params['current_path']
self.keep_releases = module.params['keep_releases']
self.path = module.params['path']
self.release = module.params['release']
self.releases_path = module.params['releases_path']
self.shared_path = module.params['shared_path']
self.state = module.params['state']
self.unfinished_filename = module.params['unfinished_filename']
self.clean = module.params["clean"]
self.current_path = module.params["current_path"]
self.keep_releases = module.params["keep_releases"]
self.path = module.params["path"]
self.release = module.params["release"]
self.releases_path = module.params["releases_path"]
self.shared_path = module.params["shared_path"]
self.state = module.params["state"]
self.unfinished_filename = module.params["unfinished_filename"]
def gather_facts(self):
current_path = os.path.join(self.path, self.current_path)
@ -297,7 +296,7 @@ class DeployHelper:
previous_release, previous_release_path = self._get_last_release(current_path)
if not self.release and (self.state == 'query' or self.state == 'present'):
if not self.release and (self.state == "query" or self.state == "present"):
self.release = time.strftime("%Y%m%d%H%M%S")
if self.release:
@ -306,15 +305,15 @@ class DeployHelper:
new_release_path = None
return {
'project_path': self.path,
'current_path': current_path,
'releases_path': releases_path,
'shared_path': shared_path,
'previous_release': previous_release,
'previous_release_path': previous_release_path,
'new_release': self.release,
'new_release_path': new_release_path,
'unfinished_filename': self.unfinished_filename
"project_path": self.path,
"current_path": current_path,
"releases_path": releases_path,
"shared_path": shared_path,
"previous_release": previous_release,
"previous_release_path": previous_release_path,
"new_release": self.release,
"new_release_path": new_release_path,
"unfinished_filename": self.unfinished_filename,
}
def delete_path(self, path):
@ -422,16 +421,16 @@ class DeployHelper:
if not self.module.check_mode:
releases.sort(key=lambda x: os.path.getctime(os.path.join(releases_path, x)), reverse=True)
for release in releases[self.keep_releases:]:
for release in releases[self.keep_releases :]:
changes += self.delete_path(os.path.join(releases_path, release))
elif len(releases) > self.keep_releases:
changes += (len(releases) - self.keep_releases)
changes += len(releases) - self.keep_releases
return changes
def _get_file_args(self, path):
file_args = self.file_args.copy()
file_args['path'] = path
file_args["path"] = path
return file_args
def _get_last_release(self, current_path):
@ -446,75 +445,72 @@ class DeployHelper:
def main():
module = AnsibleModule(
argument_spec=dict(
path=dict(aliases=['dest'], required=True, type='path'),
release=dict(type='str'),
releases_path=dict(type='str', default='releases'),
shared_path=dict(type='path', default='shared'),
current_path=dict(type='path', default='current'),
keep_releases=dict(type='int', default=5),
clean=dict(type='bool', default=True),
unfinished_filename=dict(type='str', default='DEPLOY_UNFINISHED'),
state=dict(choices=['present', 'absent', 'clean', 'finalize', 'query'], default='present')
path=dict(aliases=["dest"], required=True, type="path"),
release=dict(type="str"),
releases_path=dict(type="str", default="releases"),
shared_path=dict(type="path", default="shared"),
current_path=dict(type="path", default="current"),
keep_releases=dict(type="int", default=5),
clean=dict(type="bool", default=True),
unfinished_filename=dict(type="str", default="DEPLOY_UNFINISHED"),
state=dict(choices=["present", "absent", "clean", "finalize", "query"], default="present"),
),
required_if=[
('state', 'finalize', ['release']),
("state", "finalize", ["release"]),
],
add_file_common_args=True,
supports_check_mode=True
supports_check_mode=True,
)
deploy_helper = DeployHelper(module)
facts = deploy_helper.gather_facts()
result = {
'state': deploy_helper.state
}
result = {"state": deploy_helper.state}
changes = 0
if deploy_helper.state == 'query':
result['ansible_facts'] = {'deploy_helper': facts}
if deploy_helper.state == "query":
result["ansible_facts"] = {"deploy_helper": facts}
elif deploy_helper.state == 'present':
deploy_helper.check_link(facts['current_path'])
changes += deploy_helper.create_path(facts['project_path'])
changes += deploy_helper.create_path(facts['releases_path'])
elif deploy_helper.state == "present":
deploy_helper.check_link(facts["current_path"])
changes += deploy_helper.create_path(facts["project_path"])
changes += deploy_helper.create_path(facts["releases_path"])
if deploy_helper.shared_path:
changes += deploy_helper.create_path(facts['shared_path'])
changes += deploy_helper.create_path(facts["shared_path"])
result['ansible_facts'] = {'deploy_helper': facts}
result["ansible_facts"] = {"deploy_helper": facts}
elif deploy_helper.state == 'finalize':
elif deploy_helper.state == "finalize":
if deploy_helper.keep_releases <= 0:
module.fail_json(msg="'keep_releases' should be at least 1")
changes += deploy_helper.remove_unfinished_file(facts['new_release_path'])
changes += deploy_helper.create_link(facts['new_release_path'], facts['current_path'])
changes += deploy_helper.remove_unfinished_file(facts["new_release_path"])
changes += deploy_helper.create_link(facts["new_release_path"], facts["current_path"])
if deploy_helper.clean:
changes += deploy_helper.remove_unfinished_link(facts['project_path'])
changes += deploy_helper.remove_unfinished_builds(facts['releases_path'])
changes += deploy_helper.cleanup(facts['releases_path'], facts['new_release'])
changes += deploy_helper.remove_unfinished_link(facts["project_path"])
changes += deploy_helper.remove_unfinished_builds(facts["releases_path"])
changes += deploy_helper.cleanup(facts["releases_path"], facts["new_release"])
elif deploy_helper.state == 'clean':
changes += deploy_helper.remove_unfinished_link(facts['project_path'])
changes += deploy_helper.remove_unfinished_builds(facts['releases_path'])
changes += deploy_helper.cleanup(facts['releases_path'], facts['new_release'])
elif deploy_helper.state == "clean":
changes += deploy_helper.remove_unfinished_link(facts["project_path"])
changes += deploy_helper.remove_unfinished_builds(facts["releases_path"])
changes += deploy_helper.cleanup(facts["releases_path"], facts["new_release"])
elif deploy_helper.state == 'absent':
elif deploy_helper.state == "absent":
# destroy the facts
result['ansible_facts'] = {'deploy_helper': []}
changes += deploy_helper.delete_path(facts['project_path'])
result["ansible_facts"] = {"deploy_helper": []}
changes += deploy_helper.delete_path(facts["project_path"])
if changes > 0:
result['changed'] = True
result["changed"] = True
else:
result['changed'] = False
result["changed"] = False
module.exit_json(**result)
if __name__ == '__main__':
if __name__ == "__main__":
main()