本文整理汇总了Python中redhat_support_tool.helpers.confighelper._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: validate_args
def validate_args(self):
msg = _('ERROR: %s requires a package name.') % \
ListKernelDebugs.plugin_name
if not self._line:
if common.is_interactive():
line = raw_input(_('Please provide the text to search (or'
' \'q\' to exit): '))
line = str(line).strip()
if line == 'q':
raise Exception()
if str(line).strip():
self._line = line
else:
print msg
raise Exception(msg)
if len(self._args) == 0 and len(self._line) > 0:
self._args = [self._line]
if self._options['variant']:
self.yumquery = 'kernel-%s-debuginfo-%s' % \
(self._options['variant'], self._args[0])
else:
self.yumquery = 'kernel-debuginfo-%s' % (self._args[0])
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:25,代码来源:find_kerneldebugs.py
示例2: postinit
def postinit(self):
self._submenu_opts = deque()
self._sections = {}
try:
if os.geteuid() != 0:
raise Exception(_('This command requires root user '
'privileges.'))
self.yumhelper = YumDownloadHelper()
self.yumhelper.setup_debug_repos()
self.pkgAry = self.yumhelper.find_package(self.yumquery)
if not self.pkgAry:
raise EmptyValueError(
_('%s was not available from any of the following'
' yum repositories: %s') % (self.yumquery,
', '.join(self.yumhelper.get_repoids())))
for pkg in self.pkgAry:
if hasattr(pkg, 'evr'):
pkgevr = pkg.evr
else:
pkgevr = "%s:%s-%s" % (pkg.epoch, pkg.version, pkg.release)
doc = u''
doc += '%-40s %-20s %-16s' % (pkg.name, pkgevr, pkg.repoid)
disp_opt_doc = u'%s-%s (%s)' % (pkg.name, pkgevr, pkg.repoid)
packed_pkg = {'yumhelper': self.yumhelper,
'package': pkg}
disp_opt = ObjectDisplayOption(disp_opt_doc,
'interactive_action',
packed_pkg)
self._submenu_opts.append(disp_opt)
self._sections[disp_opt] = doc
except NoReposError, nre:
print nre
raise
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:35,代码来源:find_kerneldebugs.py
示例3: postinit
def postinit(self):
kb_object = None
self._submenu_opts = deque()
self._sections = {}
api = None
try:
api = apihelper.get_api()
kb_object = api.solutions.get(self.solutionID)
if not self._parse_solution_sections(kb_object):
raise Exception()
except Exception:
# See if the given ID is an article.
try:
kb_object = api.articles.get(self.solutionID)
if not self._parse_article_sections(kb_object):
raise Exception()
except EmptyValueError, eve:
msg = _("ERROR: %s") % str(eve)
print msg
logger.log(logging.WARNING, msg)
raise
except RequestError, re:
msg = _("Unable to connect to support services API. " "Reason: %s") % re.reason
print msg
logger.log(logging.WARNING, msg)
raise
开发者ID:redhataccess,项目名称:redhat-support-tool,代码行数:26,代码来源:kb.py
示例4: do_shell
def do_shell(self, line):
if len(line) == 0:
print _("ERROR: No command to run was provided")
self.help_shell()
else:
output = os.popen(line).read()
print output
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:7,代码来源:__main__.py
示例5: downloaduuid
def downloaduuid(self, uuid, filename=None, length=None):
api = None
try:
api = apihelper.get_api()
if not length:
logger.debug("Getting attachment length ...")
print _("Downloading ... "),
sys.stdout.flush()
all_attachments = api.attachments.list(self._options['casenumber'])
for attach in all_attachments:
if attach.get_uuid() == uuid:
length = attach.get_length()
logger.debug("... %d bytes" % length)
break
filename = api.attachments.get(
caseNumber=self._options['casenumber'],
attachmentUUID=uuid,
fileName=filename,
attachmentLength=length,
destDir=self._options['destdir'])
print _('File downloaded to %s') % (filename)
except EmptyValueError, eve:
msg = _('ERROR: %s') % str(eve)
print msg
logger.log(logging.WARNING, msg)
raise
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:26,代码来源:get_attachment.py
示例6: _check_destdir
def _check_destdir(self):
beenVerified = False
if not self._options['destdir']:
if common.is_interactive():
while True:
line = raw_input(_('Please provide a download directory '
'or press enter to use the current '
'directory (or \'q\' to exit): '))
if str(line).strip() == 'q':
raise Exception()
line = str(line).strip()
destDir = os.path.expanduser(line)
if not len(destDir):
destDir = os.curdir
if not os.path.isdir(destDir):
print(_('%s is not a valid directory.') % destDir)
else:
self._options['destdir'] = destDir
beenVerified = True
break
else:
self._options['destdir'] = os.curdir
if not beenVerified:
self._options['destdir'] = os.path.\
expanduser(self._options['destdir'])
if not os.path.isdir(self._options['destdir']):
msg = _('ERROR: %s is not a valid directory.') \
% self._options['destdir']
print msg
raise Exception(msg)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:31,代码来源:get_attachment.py
示例7: _get_ver
def _get_ver(self):
versions = None
if self._options['product'] == None:
self._options['product'] = self._case.get_product()
if(not self._productsAry):
self._productsAry = common.get_products()
for product in self._productsAry:
if self._options['product'] == product.get_name():
versions = product.get_versions()
break
common.print_versions(versions)
while True:
line = raw_input(_('Please select a version (or \'q\' '
'to exit): '))
if str(line).strip() == 'q':
return False
try:
line = int(line)
# pylint: disable=W0702
except:
print _("ERROR: Invalid version selection.")
if line in range(1, len(self._productsAry) + 1) and line != '':
self._options['version'] = versions[line - 1]
break
else:
print _("ERROR: Invalid version selection.")
return True
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:29,代码来源:modify_case.py
示例8: get_options
def get_options(cls):
'''
Subclasses that need command line options should override this method
and return an array of optparse.Option(s) to be used by the
OptionParser.
Example:
return [Option("-f", "--file", action="store",
dest="filename", help='Some file'),
Option("-c", "--case",
action="store", dest="casenumber",
help='A case')]
Would produce the following:
Command (? for help): help mycommand
Usage: mycommand [options]
Use the 'mycommand' command to find a knowledge base solution by ID
Options:
-h, --help show this help message and exit
-f, --file Some file
-c, --case A case
Example:
- mycommand -c 12345 -f abc.txt
'''
return [Option("-t", "--variant", dest="variant",
help=_('Select an alternative kernel variant'),
metavar=_('VARIANT'))]
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:30,代码来源:find_kerneldebugs.py
示例9: postinit
def postinit(self):
prompttype = self.metadata['type'].lower()
self.partial_entries = _('%s of %s %s displayed. Type'
' \'m\' to see more.') % ('%s', '%s',
prompttype)
self.end_of_entries = _('No more %s to display') % (prompttype)
self._submenu_opts = self.metadata['options']
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:7,代码来源:genericinteractiveprompt.py
示例10: _check_comment
def _check_comment(self):
msg = _("ERROR: %s requires a some text for the comment.")\
% self.plugin_name
if self._args:
try:
self.comment = u' '.join([unicode(i, 'utf8') for i in
self._args])
except TypeError:
self.comment = u' '.join(self._args)
elif common.is_interactive():
comment = []
try:
print _('Type your comment. Ctrl-d '
'on an empty line to submit:')
while True:
comment.append(raw_input())
except EOFError:
# User pressed Ctrl-d
self.comment = str('\n'.join(comment)).strip()
if self.comment == '':
print msg
raise Exception(msg)
self.comment = self.comment.decode('utf-8')
else:
print msg
raise Exception(msg)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:27,代码来源:add_comment.py
示例11: help_shell
def help_shell(self):
print
print '\n'.join(['shell COMMAND',
_('Execute a shell command. You can also use \'!\''),
_('Example:'),
' shell ls',
' !ls'])
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:7,代码来源:__main__.py
示例12: _parse_solutions
def _parse_solutions(self, solAry):
'''
Use this for non-interactive display of results.
'''
try:
for val in solAry:
# doc is displayed in non-interactive mode
doc = u''
doc += '%-8s %-60s\n' % ('%s:' % Constants.TITLE,
val.get_title())
if self._options['summary']:
summary = val.get_abstract()
if summary:
summary = " ".join(summary.replace('\n', ' ').split())
doc += '%-8s %-60s\n' % (Constants.CASE_SUMMARY, summary)
doc += '%-8s %-60s\n' % (Constants.ID,
val.get_id())
kcsState = val.get_kcsState()[0:3].upper()
kcsStateExplanation = self.state_explanations.get(kcsState, '')
doc += _('State: %s\n' % (kcsStateExplanation))
vuri = val.get_view_uri()
if(vuri):
doc += '%-8s %-60s' % (Constants.URL, vuri)
else:
doc += '%-8s %-60s' % (Constants.URL,
re.sub("api\.|/rs", "",
val.get_uri()))
doc += '\n\n%s%s%s\n\n' % (Constants.BOLD,
str('-' * Constants.MAX_RULE),
Constants.END)
# disp_opt_text is displayed in interactive mode
if confighelper.get_config_helper().get(option='ponies'):
published_state = val.get_ModerationState()[0].upper()
disp_opt_text = '[%7s:%s:%s] %s' % (val.get_id(),
kcsState,
published_state,
val.get_title())
else:
disp_opt_text = '[%7s:%s] %s' % (val.get_id(),
kcsState,
val.get_title())
# TODO: nicely display the summary within disp_opt_text
if self._options['summary']:
disp_opt_text += ' *** %s %s' % (Constants.CASE_SUMMARY,
summary)
disp_opt = ObjectDisplayOption(disp_opt_text,
'interactive_action',
val.get_id())
self._submenu_opts.append(disp_opt)
self._sections[disp_opt] = doc
# pylint: disable=W0702
except:
msg = _('ERROR: problem parsing the solutions.')
print msg
logger.log(logging.WARNING, msg)
return False
if(disp_opt):
return True
return False
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:60,代码来源:search.py
示例13: ssl_check
def ssl_check():
'''Check SSL configuration options
Will print warnings for various potentially unsafe situations as a means
to alert of possible Man-in-the-Middle vectors, or SSL communication is
likely to fail.'''
# Import confighelper - we need to know how various bits are configured.
cfg = confighelper.get_config_helper()
if cfg.get(option='no_verify_ssl'):
# Unsafe/Not Recommended. Warn user, suggest loading the CA cert for
# the proxy/server
msg = _('Warning: no_ssl_verify is enabled in the Red Hat Support Tool'
' configuration, this may allow other servers to intercept'
' communications with Red Hat. If you have a transparent SSL'
' proxy server, you can trust it\'s Certificate Authority'
' using: \'config ssl_ca <filepath>\'')
logging.warn(msg)
print msg
elif (cfg.get(option='ssl_ca')
and not os.access(cfg.get(option='ssl_ca'), os.R_OK)):
# Customer has configured a path to a CA certificate to trust, but we
# can't find or access the Certificate Authority file that we will pass
# to the API. It's not a failure, but we should warn, in case they do
# use Red Hat APIs
msg = _('Warning: Red Hat Support Tool is unable to access the'
' designated Certificate Authority certificate for server'
' verification at %s. Please correct/replace this file,'
' otherwise functionality may be limited.')
logging.warn(msg)
print msg
return
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:31,代码来源:common.py
示例14: _check_case_number
def _check_case_number(self):
errmsg1 = _("ERROR: %s requires a case number." % self.plugin_name)
errmsg2 = _("ERROR: %s is not a valid case number.")
if not self._options['casenumber']:
if common.is_interactive():
while True:
line = raw_input(_("Please provide a case number (or 'q' "
'to exit): '))
line = str(line).strip()
if not line:
print errmsg1
elif line == 'q':
print
self._remove_compressed_attachments()
raise Exception()
else:
try:
int(line)
self._options['casenumber'] = line
break
except ValueError:
print(errmsg2 % line)
else:
print errmsg1
self._remove_compressed_attachments()
raise Exception(errmsg1)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:27,代码来源:add_attachment.py
示例15: _check_description
def _check_description(self):
msg = _("ERROR: %s requires a description.")\
% self.plugin_name
if not self._options['description']:
if common.is_interactive():
while True:
userinput = []
try:
print _('Please enter a description (Ctrl-D on an'
' empty line when complete):')
while True:
userinput.append(raw_input())
except EOFError:
# User pressed Ctrl-d
description = str('\n'.join(userinput)).strip()
if description == '':
print _("ERROR: Invalid description.")
else:
self._options['description'] = description.decode(
'utf_8')
break
else:
print msg
raise Exception(msg)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:25,代码来源:open_case.py
示例16: non_interactive_action
def non_interactive_action(self):
try:
if len(self.pkgAry) >= 1:
print _(
"The vmlinux debug images from the following packages " "will be extracted to: %s"
) % confighelper.get_config_helper().get(option="kern_debug_dir")
for pkg in self.pkgAry:
print pkg
if not self._options["noprompt"]:
line = raw_input(_("Continue (y/n)? "))
if str(line).strip().lower() != "y":
print _("Canceling")
return
# Start installing'
extpaths = self.yumhelper.extractKernelDebugs(self.pkgAry)
for extractedpkg in extpaths:
print _("Kernel vmlinux file for %s was " "extracted to %s") % (
extractedpkg["package"],
extractedpkg["path"],
)
else:
print _("No packages to install.")
# pylint: disable=W0703
except Exception, e:
logger.log(logging.WARNING, e)
开发者ID:redhataccess,项目名称:redhat-support-tool,代码行数:25,代码来源:get_kerneldebug.py
示例17: get_options
def get_options(cls):
'''
Subclasses that need command line options should override this method
and return an array of optparse.Option(s) to be used by the
OptionParser.
Example:
return [Option("-f", "--file", action="store",
dest="filename", help='Some file'),
Option("-c", "--case",
action="store", dest="casenumber",
help='A case')]
Would produce the following:
Command (? for help): help mycommand
Usage: mycommand [options]
Use the 'mycommand' command to find a knowledge base solution by ID
Options:
-h, --help show this help message and exit
-f, --file Some file
-c, --case A case
Example:
- mycommand -c 12345 -f abc.txt
'''
def public_opt_callback(option, opt_str, value, parser):
'''
Callback function for the public option that converts the string
into an equivalent boolean value
'''
ret = common.str_to_bool(value)
if ret is None:
msg = _("ERROR: Unexpected argument to %s: %s\nValid values"
" are true or false (default: %s true)"
% (opt_str, value, opt_str))
print msg
raise Exception(msg)
else:
parser.values.public = ret
public_opt_help = SUPPRESS_HELP
if confighelper.get_config_helper().get(option='ponies'):
public_opt_help = \
_('True or False. Use this to toggle a public or private comment'
' (default=True). Example: -p false')
return [Option("-c", "--casenumber", dest="casenumber",
help=_('The case number from which the comment '
'should be added. (required)'), default=False),
Option("-p", "--public", dest="public", help=public_opt_help,
type='string', action='callback',
callback=public_opt_callback)]
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:55,代码来源:add_comment.py
示例18: do_help
def do_help(self, line):
doclines = [_('Red Hat Support assigns a state with all knowledge'
' solutions, which is displayed in the above output.'),
'',
_('The current states are:')]
for doc in doclines:
print doc
for state in self.state_explanations.keys():
print ' %s - %s' % (state, self.state_explanations[state])
common.do_help(self)
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:13,代码来源:search.py
示例19: _get_aid
def _get_aid(self):
while True:
line = raw_input(_('Please provide a alternative-id (or \'q\' '
'to exit): '))
line = str(line).strip()
if line == 'q':
return False
if line != '':
self._options['aid'] = line
break
else:
print _("ERROR: Invalid alternative-id provided.")
return True
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:13,代码来源:modify_case.py
示例20: help_makeconfig
def help_makeconfig(self):
print _("""Usage: makeconfig
The Red Hat Support Tool saves some configuration options
in $HOME/.rhhelp. Use the 'makeconfig' command to create
the $HOME/.rhhelp configuration file.
This command is only necessary if you prefer to use
the Red Hat Support Tool in the non-interactive mode
(for example: \'redhat-support-tool search rhev\'). The
interactive mode will detect the presence of $HOME/.rhhelp
and create it if necessary.
""")
开发者ID:karmab,项目名称:redhat-support-tool,代码行数:13,代码来源:__main__.py
注:本文中的redhat_support_tool.helpers.confighelper._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论