mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
removed unused imports in galaxy/cli
This commit is contained in:
parent
d7b516f75d
commit
8e445c551a
1 changed files with 16 additions and 19 deletions
|
@ -25,7 +25,6 @@ __metaclass__ = type
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import json
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -40,7 +39,6 @@ from ansible.galaxy.role import GalaxyRole
|
||||||
from ansible.galaxy.login import GalaxyLogin
|
from ansible.galaxy.login import GalaxyLogin
|
||||||
from ansible.galaxy.token import GalaxyToken
|
from ansible.galaxy.token import GalaxyToken
|
||||||
from ansible.playbook.role.requirement import RoleRequirement
|
from ansible.playbook.role.requirement import RoleRequirement
|
||||||
from ansible.module_utils.urls import open_url
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -61,10 +59,10 @@ class GalaxyCLI(CLI):
|
||||||
"remove": "delete a role from your roles path",
|
"remove": "delete a role from your roles path",
|
||||||
"search": "query the Galaxy API",
|
"search": "query the Galaxy API",
|
||||||
"setup": "add a TravisCI integration to Galaxy",
|
"setup": "add a TravisCI integration to Galaxy",
|
||||||
}
|
}
|
||||||
|
|
||||||
SKIP_INFO_KEYS = ("name", "description", "readme_html", "related", "summary_fields", "average_aw_composite", "average_aw_score", "url" )
|
SKIP_INFO_KEYS = ("name", "description", "readme_html", "related", "summary_fields", "average_aw_composite", "average_aw_score", "url" )
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
self.VALID_ACTIONS = self.available_commands.keys()
|
self.VALID_ACTIONS = self.available_commands.keys()
|
||||||
self.VALID_ACTIONS.sort()
|
self.VALID_ACTIONS.sort()
|
||||||
|
@ -101,7 +99,7 @@ class GalaxyCLI(CLI):
|
||||||
usage = "usage: %%prog [%s] [--help] [options] ..." % "|".join(self.VALID_ACTIONS),
|
usage = "usage: %%prog [%s] [--help] [options] ..." % "|".join(self.VALID_ACTIONS),
|
||||||
epilog = "\nSee '%s <command> --help' for more information on a specific command.\n\n" % os.path.basename(sys.argv[0])
|
epilog = "\nSee '%s <command> --help' for more information on a specific command.\n\n" % os.path.basename(sys.argv[0])
|
||||||
)
|
)
|
||||||
|
|
||||||
self.set_action()
|
self.set_action()
|
||||||
|
|
||||||
# options specific to actions
|
# options specific to actions
|
||||||
|
@ -131,7 +129,7 @@ class GalaxyCLI(CLI):
|
||||||
self.parser.add_option('-n', '--no-deps', dest='no_deps', action='store_true', default=False,
|
self.parser.add_option('-n', '--no-deps', dest='no_deps', action='store_true', default=False,
|
||||||
help='Don\'t download roles listed as dependencies')
|
help='Don\'t download roles listed as dependencies')
|
||||||
self.parser.add_option('-r', '--role-file', dest='role_file',
|
self.parser.add_option('-r', '--role-file', dest='role_file',
|
||||||
help='A file containing a list of roles to be imported')
|
help='A file containing a list of roles to be imported')
|
||||||
elif self.action == "remove":
|
elif self.action == "remove":
|
||||||
self.parser.set_usage("usage: %prog remove role1 role2 ...")
|
self.parser.set_usage("usage: %prog remove role1 role2 ...")
|
||||||
elif self.action == "list":
|
elif self.action == "list":
|
||||||
|
@ -190,7 +188,7 @@ class GalaxyCLI(CLI):
|
||||||
|
|
||||||
# if not offline, get connect to galaxy api
|
# if not offline, get connect to galaxy api
|
||||||
if self.action in ("import","info","install","search","login","setup","delete") or \
|
if self.action in ("import","info","install","search","login","setup","delete") or \
|
||||||
(self.action == 'init' and not self.options.offline):
|
(self.action == 'init' and not self.options.offline):
|
||||||
self.api = GalaxyAPI(self.galaxy)
|
self.api = GalaxyAPI(self.galaxy)
|
||||||
|
|
||||||
self.execute()
|
self.execute()
|
||||||
|
@ -544,7 +542,7 @@ class GalaxyCLI(CLI):
|
||||||
def execute_search(self):
|
def execute_search(self):
|
||||||
page_size = 1000
|
page_size = 1000
|
||||||
search = None
|
search = None
|
||||||
|
|
||||||
if len(self.args):
|
if len(self.args):
|
||||||
terms = []
|
terms = []
|
||||||
for i in range(len(self.args)):
|
for i in range(len(self.args)):
|
||||||
|
@ -556,7 +554,7 @@ class GalaxyCLI(CLI):
|
||||||
|
|
||||||
response = self.api.search_roles(search, platforms=self.options.platforms,
|
response = self.api.search_roles(search, platforms=self.options.platforms,
|
||||||
tags=self.options.tags, author=self.options.author, page_size=page_size)
|
tags=self.options.tags, author=self.options.author, page_size=page_size)
|
||||||
|
|
||||||
if response['count'] == 0:
|
if response['count'] == 0:
|
||||||
display.display("No roles match your search.", color="yellow")
|
display.display("No roles match your search.", color="yellow")
|
||||||
return True
|
return True
|
||||||
|
@ -578,7 +576,7 @@ class GalaxyCLI(CLI):
|
||||||
data += (format_str % ("----", "-----------"))
|
data += (format_str % ("----", "-----------"))
|
||||||
for role in response['results']:
|
for role in response['results']:
|
||||||
data += (format_str % (role['username'] + '.' + role['name'],role['description']))
|
data += (format_str % (role['username'] + '.' + role['name'],role['description']))
|
||||||
|
|
||||||
self.pager(data)
|
self.pager(data)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -595,12 +593,12 @@ class GalaxyCLI(CLI):
|
||||||
github_token = self.options.token
|
github_token = self.options.token
|
||||||
|
|
||||||
galaxy_response = self.api.authenticate(github_token)
|
galaxy_response = self.api.authenticate(github_token)
|
||||||
|
|
||||||
if self.options.token is None:
|
if self.options.token is None:
|
||||||
# Remove the token we created
|
# Remove the token we created
|
||||||
login.remove_github_token()
|
login.remove_github_token()
|
||||||
|
|
||||||
# Store the Galaxy token
|
# Store the Galaxy token
|
||||||
token = GalaxyToken()
|
token = GalaxyToken()
|
||||||
token.set(galaxy_response['token'])
|
token.set(galaxy_response['token'])
|
||||||
|
|
||||||
|
@ -611,7 +609,7 @@ class GalaxyCLI(CLI):
|
||||||
"""
|
"""
|
||||||
Import a role into Galaxy
|
Import a role into Galaxy
|
||||||
"""
|
"""
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
'INFO': 'normal',
|
'INFO': 'normal',
|
||||||
'WARNING': 'yellow',
|
'WARNING': 'yellow',
|
||||||
|
@ -631,7 +629,7 @@ class GalaxyCLI(CLI):
|
||||||
else:
|
else:
|
||||||
# Submit an import request
|
# Submit an import request
|
||||||
task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference)
|
task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference)
|
||||||
|
|
||||||
if len(task) > 1:
|
if len(task) > 1:
|
||||||
# found multiple roles associated with github_user/github_repo
|
# found multiple roles associated with github_user/github_repo
|
||||||
display.display("WARNING: More than one Galaxy role associated with Github repo %s/%s." % (github_user,github_repo),
|
display.display("WARNING: More than one Galaxy role associated with Github repo %s/%s." % (github_user,github_repo),
|
||||||
|
@ -693,7 +691,7 @@ class GalaxyCLI(CLI):
|
||||||
if len(self.args) < 4:
|
if len(self.args) < 4:
|
||||||
raise AnsibleError("Missing one or more arguments. Expecting: source github_user github_repo secret")
|
raise AnsibleError("Missing one or more arguments. Expecting: source github_user github_repo secret")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
secret = self.args.pop()
|
secret = self.args.pop()
|
||||||
github_repo = self.args.pop()
|
github_repo = self.args.pop()
|
||||||
github_user = self.args.pop()
|
github_user = self.args.pop()
|
||||||
|
@ -711,7 +709,7 @@ class GalaxyCLI(CLI):
|
||||||
|
|
||||||
if len(self.args) < 2:
|
if len(self.args) < 2:
|
||||||
raise AnsibleError("Missing one or more arguments. Expected: github_user github_repo")
|
raise AnsibleError("Missing one or more arguments. Expected: github_user github_repo")
|
||||||
|
|
||||||
github_repo = self.args.pop()
|
github_repo = self.args.pop()
|
||||||
github_user = self.args.pop()
|
github_user = self.args.pop()
|
||||||
resp = self.api.delete_role(github_user, github_repo)
|
resp = self.api.delete_role(github_user, github_repo)
|
||||||
|
@ -722,9 +720,8 @@ class GalaxyCLI(CLI):
|
||||||
display.display("------ --------------- ----------")
|
display.display("------ --------------- ----------")
|
||||||
for role in resp['deleted_roles']:
|
for role in resp['deleted_roles']:
|
||||||
display.display("%-8s %-15s %s" % (role.id,role.namespace,role.name))
|
display.display("%-8s %-15s %s" % (role.id,role.namespace,role.name))
|
||||||
|
|
||||||
display.display(resp['status'])
|
display.display(resp['status'])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue