mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Pep8 fixes for deploy_helper (#24237)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
73c24001d9
commit
465c12ccdb
2 changed files with 45 additions and 46 deletions
|
@ -287,29 +287,30 @@ EXAMPLES = '''
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import *
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
|
|
||||||
|
|
||||||
class DeployHelper(object):
|
class DeployHelper(object):
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
self.module = module
|
self.module = module
|
||||||
self.file_args = module.load_file_common_arguments(module.params)
|
self.file_args = module.load_file_common_arguments(module.params)
|
||||||
|
|
||||||
self.clean = module.params['clean']
|
self.clean = module.params['clean']
|
||||||
self.current_path = module.params['current_path']
|
self.current_path = module.params['current_path']
|
||||||
self.keep_releases = module.params['keep_releases']
|
self.keep_releases = module.params['keep_releases']
|
||||||
self.path = module.params['path']
|
self.path = module.params['path']
|
||||||
self.release = module.params['release']
|
self.release = module.params['release']
|
||||||
self.releases_path = module.params['releases_path']
|
self.releases_path = module.params['releases_path']
|
||||||
self.shared_path = module.params['shared_path']
|
self.shared_path = module.params['shared_path']
|
||||||
self.state = module.params['state']
|
self.state = module.params['state']
|
||||||
self.unfinished_filename = module.params['unfinished_filename']
|
self.unfinished_filename = module.params['unfinished_filename']
|
||||||
|
|
||||||
def gather_facts(self):
|
def gather_facts(self):
|
||||||
current_path = os.path.join(self.path, self.current_path)
|
current_path = os.path.join(self.path, self.current_path)
|
||||||
releases_path = os.path.join(self.path, self.releases_path)
|
releases_path = os.path.join(self.path, self.releases_path)
|
||||||
if self.shared_path:
|
if self.shared_path:
|
||||||
shared_path = os.path.join(self.path, self.shared_path)
|
shared_path = os.path.join(self.path, self.shared_path)
|
||||||
else:
|
else:
|
||||||
shared_path = None
|
shared_path = None
|
||||||
|
|
||||||
previous_release, previous_release_path = self._get_last_release(current_path)
|
previous_release, previous_release_path = self._get_last_release(current_path)
|
||||||
|
|
||||||
|
@ -322,15 +323,15 @@ class DeployHelper(object):
|
||||||
new_release_path = None
|
new_release_path = None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'project_path': self.path,
|
'project_path': self.path,
|
||||||
'current_path': current_path,
|
'current_path': current_path,
|
||||||
'releases_path': releases_path,
|
'releases_path': releases_path,
|
||||||
'shared_path': shared_path,
|
'shared_path': shared_path,
|
||||||
'previous_release': previous_release,
|
'previous_release': previous_release,
|
||||||
'previous_release_path': previous_release_path,
|
'previous_release_path': previous_release_path,
|
||||||
'new_release': self.release,
|
'new_release': self.release,
|
||||||
'new_release_path': new_release_path,
|
'new_release_path': new_release_path,
|
||||||
'unfinished_filename': self.unfinished_filename
|
'unfinished_filename': self.unfinished_filename
|
||||||
}
|
}
|
||||||
|
|
||||||
def delete_path(self, path):
|
def delete_path(self, path):
|
||||||
|
@ -396,7 +397,7 @@ class DeployHelper(object):
|
||||||
|
|
||||||
def remove_unfinished_file(self, new_release_path):
|
def remove_unfinished_file(self, new_release_path):
|
||||||
changed = False
|
changed = False
|
||||||
unfinished_file_path = os.path.join(new_release_path, self.unfinished_filename)
|
unfinished_file_path = os.path.join(new_release_path, self.unfinished_filename)
|
||||||
if os.path.lexists(unfinished_file_path):
|
if os.path.lexists(unfinished_file_path):
|
||||||
changed = True
|
changed = True
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
|
@ -430,14 +431,14 @@ class DeployHelper(object):
|
||||||
changes = 0
|
changes = 0
|
||||||
|
|
||||||
if os.path.lexists(releases_path):
|
if os.path.lexists(releases_path):
|
||||||
releases = [ f for f in os.listdir(releases_path) if os.path.isdir(os.path.join(releases_path,f)) ]
|
releases = [f for f in os.listdir(releases_path) if os.path.isdir(os.path.join(releases_path, f))]
|
||||||
try:
|
try:
|
||||||
releases.remove(reserve_version)
|
releases.remove(reserve_version)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
releases.sort( key=lambda x: os.path.getctime(os.path.join(releases_path,x)), reverse=True)
|
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))
|
changes += self.delete_path(os.path.join(releases_path, release))
|
||||||
elif len(releases) > self.keep_releases:
|
elif len(releases) > self.keep_releases:
|
||||||
|
@ -455,31 +456,32 @@ class DeployHelper(object):
|
||||||
previous_release_path = None
|
previous_release_path = None
|
||||||
|
|
||||||
if os.path.lexists(current_path):
|
if os.path.lexists(current_path):
|
||||||
previous_release_path = os.path.realpath(current_path)
|
previous_release_path = os.path.realpath(current_path)
|
||||||
previous_release = os.path.basename(previous_release_path)
|
previous_release = os.path.basename(previous_release_path)
|
||||||
|
|
||||||
return previous_release, previous_release_path
|
return previous_release, previous_release_path
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
path = dict(aliases=['dest'], required=True, type='path'),
|
path=dict(aliases=['dest'], required=True, type='path'),
|
||||||
release = dict(required=False, type='str', default=None),
|
release=dict(required=False, type='str', default=None),
|
||||||
releases_path = dict(required=False, type='str', default='releases'),
|
releases_path=dict(required=False, type='str', default='releases'),
|
||||||
shared_path = dict(required=False, type='path', default='shared'),
|
shared_path=dict(required=False, type='path', default='shared'),
|
||||||
current_path = dict(required=False, type='path', default='current'),
|
current_path=dict(required=False, type='path', default='current'),
|
||||||
keep_releases = dict(required=False, type='int', default=5),
|
keep_releases=dict(required=False, type='int', default=5),
|
||||||
clean = dict(required=False, type='bool', default=True),
|
clean=dict(required=False, type='bool', default=True),
|
||||||
unfinished_filename = dict(required=False, type='str', default='DEPLOY_UNFINISHED'),
|
unfinished_filename=dict(required=False, type='str', default='DEPLOY_UNFINISHED'),
|
||||||
state = dict(required=False, choices=['present', 'absent', 'clean', 'finalize', 'query'], default='present')
|
state=dict(required=False, choices=['present', 'absent', 'clean', 'finalize', 'query'], default='present')
|
||||||
),
|
),
|
||||||
add_file_common_args = True,
|
add_file_common_args=True,
|
||||||
supports_check_mode = True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
deploy_helper = DeployHelper(module)
|
deploy_helper = DeployHelper(module)
|
||||||
facts = deploy_helper.gather_facts()
|
facts = deploy_helper.gather_facts()
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
'state': deploy_helper.state
|
'state': deploy_helper.state
|
||||||
|
@ -488,7 +490,7 @@ def main():
|
||||||
changes = 0
|
changes = 0
|
||||||
|
|
||||||
if deploy_helper.state == 'query':
|
if deploy_helper.state == 'query':
|
||||||
result['ansible_facts'] = { 'deploy_helper': facts }
|
result['ansible_facts'] = {'deploy_helper': facts}
|
||||||
|
|
||||||
elif deploy_helper.state == 'present':
|
elif deploy_helper.state == 'present':
|
||||||
deploy_helper.check_link(facts['current_path'])
|
deploy_helper.check_link(facts['current_path'])
|
||||||
|
@ -497,7 +499,7 @@ def main():
|
||||||
if deploy_helper.shared_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 not deploy_helper.release:
|
if not deploy_helper.release:
|
||||||
|
@ -519,7 +521,7 @@ def main():
|
||||||
|
|
||||||
elif deploy_helper.state == 'absent':
|
elif deploy_helper.state == 'absent':
|
||||||
# destroy the facts
|
# destroy the facts
|
||||||
result['ansible_facts'] = { 'deploy_helper': [] }
|
result['ansible_facts'] = {'deploy_helper': []}
|
||||||
changes += deploy_helper.delete_path(facts['project_path'])
|
changes += deploy_helper.delete_path(facts['project_path'])
|
||||||
|
|
||||||
if changes > 0:
|
if changes > 0:
|
||||||
|
@ -530,7 +532,5 @@ def main():
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -767,7 +767,6 @@ lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py
|
||||||
lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py
|
lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py
|
||||||
lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py
|
lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py
|
||||||
lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py
|
lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py
|
||||||
lib/ansible/modules/web_infrastructure/deploy_helper.py
|
|
||||||
lib/ansible/modules/web_infrastructure/ejabberd_user.py
|
lib/ansible/modules/web_infrastructure/ejabberd_user.py
|
||||||
lib/ansible/modules/web_infrastructure/jboss.py
|
lib/ansible/modules/web_infrastructure/jboss.py
|
||||||
lib/ansible/modules/windows/win_disk_image.py
|
lib/ansible/modules/windows/win_disk_image.py
|
||||||
|
|
Loading…
Reference in a new issue