Skip to content

Commit

Permalink
ansible/galaxy: PEP8 compliancy (ansible#24696)
Browse files Browse the repository at this point in the history
- Make PEP8 compliant
  • Loading branch information
dagwieers authored and gundalow committed May 18, 2017
1 parent 6f6bdf7 commit c4a7f64
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/ansible/galaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, options):
# 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__)
Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/galaxy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def create_import_task(self, github_user, github_repo, reference=None, role_name
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']
Expand All @@ -164,9 +164,9 @@ def get_import_task(self, task_id=None, github_user=None, github_repo=None):
"""
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")

Expand Down Expand Up @@ -248,7 +248,7 @@ def search_roles(self, search, **kwargs):
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)
Expand Down Expand Up @@ -296,6 +296,6 @@ def remove_secret(self, secret_id):

@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
20 changes: 10 additions & 10 deletions lib/ansible/galaxy/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def __init__(self, galaxy, github_token=None):
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: ")
Expand All @@ -80,7 +80,7 @@ def remove_github_token(self):
'''
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'])
Expand All @@ -90,7 +90,7 @@ def remove_github_token(self):
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'])
Expand All @@ -100,10 +100,10 @@ def create_github_token(self):
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'])
Expand Down
11 changes: 5 additions & 6 deletions lib/ansible/galaxy/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@
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):

Expand All @@ -58,7 +59,7 @@ def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None):
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
Expand Down Expand Up @@ -114,7 +115,6 @@ def metadata(self):

return self._metadata


@property
def install_info(self):
"""
Expand Down Expand Up @@ -238,7 +238,7 @@ def install(self):
# 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):
Expand All @@ -256,7 +256,6 @@ def install(self):
else:
raise AnsibleError("No valid role data found")


if tmp_file:

display.debug("installing from %s" % tmp_file)
Expand Down Expand Up @@ -346,7 +345,7 @@ def install(self):
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

Expand Down
9 changes: 4 additions & 5 deletions lib/ansible/galaxy/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def __open_config_for_read(self):
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')

Expand All @@ -60,6 +60,5 @@ def get(self):
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)
5 changes: 0 additions & 5 deletions test/sanity/pep8/legacy-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4a7f64

Please sign in to comment.