From c4a7f64c0219123cc81df8ab6267cd5bdc10e4ff Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Thu, 18 May 2017 19:43:35 +0200 Subject: [PATCH] ansible/galaxy: PEP8 compliancy (#24696) - Make PEP8 compliant --- lib/ansible/galaxy/__init__.py | 2 +- lib/ansible/galaxy/api.py | 10 +++++----- lib/ansible/galaxy/login.py | 20 ++++++++++---------- lib/ansible/galaxy/role.py | 11 +++++------ lib/ansible/galaxy/token.py | 9 ++++----- test/sanity/pep8/legacy-files.txt | 5 ----- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/lib/ansible/galaxy/__init__.py b/lib/ansible/galaxy/__init__.py index f221a85cce7..fb18f756198 100644 --- a/lib/ansible/galaxy/__init__.py +++ b/lib/ansible/galaxy/__init__.py @@ -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__) diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py index 08befce0cda..39f4b517037 100644 --- a/lib/ansible/galaxy/api.py +++ b/lib/ansible/galaxy/api.py @@ -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 diff --git a/lib/ansible/galaxy/login.py b/lib/ansible/galaxy/login.py index affe3c82f04..d867d307b4b 100644 --- a/lib/ansible/galaxy/login.py +++ b/lib/ansible/galaxy/login.py @@ -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']) diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py index 369c66d1b41..1a8b9ace54c 100644 --- a/lib/ansible/galaxy/role.py +++ b/lib/ansible/galaxy/role.py @@ -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 diff --git a/lib/ansible/galaxy/token.py b/lib/ansible/galaxy/token.py index a089597ddbf..4b09acc998e 100644 --- a/lib/ansible/galaxy/token.py +++ b/lib/ansible/galaxy/token.py @@ -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) diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 03d0c19acda..e7178154b85 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -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