1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ansible/galaxy: PEP8 compliancy (#24696)

- Make PEP8 compliant
This commit is contained in:
Dag Wieers 2017-05-18 19:43:35 +02:00 committed by John R Barker
parent 6f6bdf7914
commit c4a7f64c02
6 changed files with 25 additions and 32 deletions

View file

@ -43,7 +43,7 @@ class Galaxy(object):
# cli option handling is responsible for making roles_path a list
self.roles_paths = roles_path
self.roles = {}
self.roles = {}
# load data path for resource usage
this_dir, this_filename = os.path.split(__file__)

View file

@ -151,7 +151,7 @@ class GalaxyAPI(object):
if role_name:
args['alternate_role_name'] = role_name
elif github_repo.startswith('ansible-role'):
args['alternate_role_name'] = github_repo[len('ansible-role')+1:]
args['alternate_role_name'] = github_repo[len('ansible-role') + 1:]
data = self.__call_galaxy(url, args=urlencode(args))
if data.get('results', None):
return data['results']
@ -164,9 +164,9 @@ class GalaxyAPI(object):
"""
url = '%s/imports/' % self.baseurl
if task_id is not None:
url = "%s?id=%d" % (url,task_id)
url = "%s?id=%d" % (url, task_id)
elif github_user is not None and github_repo is not None:
url = "%s?github_user=%s&github_repo=%s" % (url,github_user,github_repo)
url = "%s?github_user=%s&github_repo=%s" % (url, github_user, github_repo)
else:
raise AnsibleError("Expected task_id or github_user and github_repo")
@ -248,7 +248,7 @@ class GalaxyAPI(object):
if search:
search_url += '&autocomplete=' + urlquote(search)
tags = kwargs.get('tags',None)
tags = kwargs.get('tags', None)
platforms = kwargs.get('platforms', None)
page_size = kwargs.get('page_size', None)
author = kwargs.get('author', None)
@ -296,6 +296,6 @@ class GalaxyAPI(object):
@g_connect
def delete_role(self, github_user, github_repo):
url = "%s/removerole/?github_user=%s&github_repo=%s" % (self.baseurl,github_user,github_repo)
url = "%s/removerole/?github_user=%s&github_repo=%s" % (self.baseurl, github_user, github_repo)
data = self.__call_galaxy(url, headers=self.__auth_header(), method='DELETE')
return data

View file

@ -52,13 +52,13 @@ class GalaxyLogin(object):
self.get_credentials()
def get_credentials(self):
display.display(u'\n\n' + "We need your " + stringc("Github login",'bright cyan') +
" to identify you.", screen_only=True)
display.display("This information will " + stringc("not be sent to Galaxy",'bright cyan') +
", only to " + stringc("api.github.com.","yellow"), screen_only=True)
display.display(u'\n\n' + "We need your " + stringc("Github login", 'bright cyan') +
" to identify you.", screen_only=True)
display.display("This information will " + stringc("not be sent to Galaxy", 'bright cyan') +
", only to " + stringc("api.github.com.", "yellow"), screen_only=True)
display.display("The password will not be displayed." + u'\n\n', screen_only=True)
display.display("Use " + stringc("--github-token",'yellow') +
" if you do not want to enter your password." + u'\n\n', screen_only=True)
display.display("Use " + stringc("--github-token", 'yellow') +
" if you do not want to enter your password." + u'\n\n', screen_only=True)
try:
self.github_username = raw_input("Github Username: ")
@ -80,7 +80,7 @@ class GalaxyLogin(object):
'''
try:
tokens = json.load(open_url(self.GITHUB_AUTH, url_username=self.github_username,
url_password=self.github_password, force_basic_auth=True,))
url_password=self.github_password, force_basic_auth=True,))
except HTTPError as e:
res = json.load(e)
raise AnsibleError(res['message'])
@ -90,7 +90,7 @@ class GalaxyLogin(object):
display.vvvvv('removing token: %s' % token['token_last_eight'])
try:
open_url('https://api.github.com/authorizations/%d' % token['id'], url_username=self.github_username,
url_password=self.github_password, method='DELETE', force_basic_auth=True,)
url_password=self.github_password, method='DELETE', force_basic_auth=True)
except HTTPError as e:
res = json.load(e)
raise AnsibleError(res['message'])
@ -100,10 +100,10 @@ class GalaxyLogin(object):
Create a personal authorization token with a note of 'ansible-galaxy login'
'''
self.remove_github_token()
args = json.dumps({"scopes":["public_repo"], "note":"ansible-galaxy login"})
args = json.dumps({"scopes": ["public_repo"], "note": "ansible-galaxy login"})
try:
data = json.load(open_url(self.GITHUB_AUTH, url_username=self.github_username,
url_password=self.github_password, force_basic_auth=True, data=args))
url_password=self.github_password, force_basic_auth=True, data=args))
except HTTPError as e:
res = json.load(e)
raise AnsibleError(res['message'])

View file

@ -42,12 +42,13 @@ except ImportError:
from ansible.utils.display import Display
display = Display()
class GalaxyRole(object):
SUPPORTED_SCMS = set(['git', 'hg'])
META_MAIN = os.path.join('meta', 'main.yml')
META_INSTALL = os.path.join('meta', '.galaxy_install_info')
ROLE_DIRS = ('defaults','files','handlers','meta','tasks','templates','vars','tests')
ROLE_DIRS = ('defaults', 'files', 'handlers', 'meta', 'tasks', 'templates', 'vars', 'tests')
def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None):
@ -58,7 +59,7 @@ class GalaxyRole(object):
display.debug('Validate TLS certificates: %s' % self._validate_certs)
self.options = galaxy.options
self.galaxy = galaxy
self.galaxy = galaxy
self.name = name
self.version = version
@ -114,7 +115,6 @@ class GalaxyRole(object):
return self._metadata
@property
def install_info(self):
"""
@ -238,7 +238,7 @@ class GalaxyRole(object):
# are no versions in the list, we'll grab the head
# of the master branch
if len(role_versions) > 0:
loose_versions = [LooseVersion(a.get('name',None)) for a in role_versions]
loose_versions = [LooseVersion(a.get('name', None)) for a in role_versions]
loose_versions.sort()
self.version = str(loose_versions[-1])
elif role_data.get('github_branch', None):
@ -256,7 +256,6 @@ class GalaxyRole(object):
else:
raise AnsibleError("No valid role data found")
if tmp_file:
display.debug("installing from %s" % tmp_file)
@ -346,7 +345,7 @@ class GalaxyRole(object):
if not local_file:
try:
os.unlink(tmp_file)
except (OSError,IOError) as e:
except (OSError, IOError) as e:
display.warning("Unable to remove tmp file (%s): %s" % (tmp_file, str(e)))
return True

View file

@ -46,9 +46,9 @@ class GalaxyToken(object):
display.vvv('Opened %s' % self.file)
return open(self.file, 'r')
# config.yml not found, create and chomd u+rw
f = open(self.file,'w')
f = open(self.file, 'w')
f.close()
os.chmod(self.file,S_IRUSR|S_IWUSR) # owner has +rw
os.chmod(self.file, S_IRUSR | S_IWUSR) # owner has +rw
display.vvv('Created %s' % self.file)
return open(self.file, 'r')
@ -60,6 +60,5 @@ class GalaxyToken(object):
return self.config.get('token', None)
def save(self):
with open(self.file,'w') as f:
yaml.safe_dump(self.config,f,default_flow_style=False)
with open(self.file, 'w') as f:
yaml.safe_dump(self.config, f, default_flow_style=False)

View file

@ -23,11 +23,6 @@ lib/ansible/executor/process/worker.py
lib/ansible/executor/stats.py
lib/ansible/executor/task_executor.py
lib/ansible/executor/task_queue_manager.py
lib/ansible/galaxy/__init__.py
lib/ansible/galaxy/api.py
lib/ansible/galaxy/login.py
lib/ansible/galaxy/role.py
lib/ansible/galaxy/token.py
lib/ansible/inventory/__init__.py
lib/ansible/inventory/dir.py
lib/ansible/inventory/expand_hosts.py