本文整理汇总了Python中feedback.Feedback.success方法的典型用法代码示例。如果您正苦于以下问题:Python Feedback.success方法的具体用法?Python Feedback.success怎么用?Python Feedback.success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedback.Feedback
的用法示例。
在下文中一共展示了Feedback.success方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DevToolsDpkg
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import success [as 别名]
class DevToolsDpkg(DebPackage):
"""
Class for managing packages via 'dpkg'
"""
def __init__(self):
# Get the apt cache
self.cache = Cache()
# Feedback module
self.feedback = Feedback()
def installdeb(self, pkg):
"""
Install the Debian package.
:param pkg: The path to the package to install
:type pkg: str
"""
# Get the DebPackage object and the filename
dpkg = DebPackage(filename=pkg, cache=self.cache)
pkg_name = basename(pkg)
# Look for package conflicts
if not dpkg.check_conflicts():
self.feedback.block(dpkg.conflicts, 'CONFLICT')
self.feedback.error('Cannot install package <{0}>, conflicts with:'.format(pkg_name))
return False
# Get any version in cache
cache_version = dpkg.compare_to_version_in_cache()
action = 'Installed'
# Not installed
if cache_version == dpkg.VERSION_NONE:
self.feedback.info('Package <{0}> not installed'.format(pkg_name))
# Upgrading
if cache_version == dpkg.VERSION_OUTDATED:
self.feedback.info('Package <{0}> outdated, upgrading'.format(pkg_name))
action = 'Updated'
# Same version
if cache_version == dpkg.VERSION_SAME:
return self.feedback.info('Package <{0}> already installed'.format(pkg_name))
# Installed is newer
if cache_version == dpkg.VERSION_NEWER:
return self.feedback.info('Package <{0}> has newer version installed'.format(pkg_name))
# Install the package
dpkg.install()
self.feedback.success('{0}: {1}'.format(action, pkg_name))
示例2: Feedback
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import success [as 别名]
#!/usr/bin/env python3
from sys import path
path.append('{PYTHON_PATH}')
from feedback import Feedback
# Create new instance
feedback = Feedback()
# Test basic messages
i_back = feedback.info('Testing information message')
s_back = feedback.success('Testing success message')
w_back = feedback.warn('Testing warning message')
e_back = feedback.error('Testing error message')
# Test user input
feedback.input('Ask the user for some data: ', key='key_one')
feedback.input('Ask the user a "y" or "n" question? (y/n): ', key='key_two', yes_no=True)
feedback.input('Ask the user for a password and confirm: ', key='key_three', secure=True, confirm=True)
feedback.input('This input has a default value (123): ', key='key_four', default=123)
# Test block display and response retrieval
feedback.block([
'This is a block of indented text, and here is some stuff to look at:',
'Response 1: {0}'.format(feedback.get_response('key_one')),
'Response 2: {0}'.format(feedback.get_response('key_two')),
'Response 3: {0}'.format(feedback.get_response('key_three')),
'Response 4: {0}'.format(feedback.get_response('key_four')),
'Info Returned: {0}'.format(i_back),
'Success Returned: {0}'.format(s_back),
'Warn Returned: {0}'.format(w_back),
'Error Returned: {0}'.format(e_back),
示例3: _NGUtilService
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import success [as 别名]
class _NGUtilService(object):
"""
Simple class wrapper for handling Linux services.
"""
def __init__(self, name):
# Service name
self.name = name
# Feedback handler
self.feedback = Feedback(use_timestamp=True)
def is_running(self):
"""
Check if the service is running.
"""
proc = Popen(['service', self.name, 'status'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
# Return the status
return True if ('running' in out.rstrip()) else False
def _do_service(self, state):
"""
Wrapper for handling the service command argument.
"""
proc = Popen(['service', self.name, state], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
# Set the message prefix
prefix = {
'restart': 'Restarted',
'stop': 'Stopped',
'start': 'Started',
'reload': 'Reloaded',
'save': 'Saved'
}
# If error code returned
if not proc.returncode == 0:
self.feedback.error('Failed to {0} service \'{1}\': {2}'.format(state, self.name, err.rstrip()))
return False
# Service command success
self.feedback.success('{0} \'{1}\' service...'.format(prefix[state], self.name))
return True
def _do_chkconfig(self, state):
"""
Wrapper for running chkconfig.
"""
proc = Popen(['chkconfig', self.name, state], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
# State string
state_str = ('enable', 'Enabled') if (state == 'on') else ('disable', 'Disabled')
# Make sure the command succeeded
if not proc.returncode == 0:
self.feedback.error('Failed to {0} service: {1}, error={2}'.format(state_str[0], self.name, err.rstrip()))
return False
# Chkconfig command success
self.feedback.success('{0} service: {1}'.format(state_str[1], self.name))
return True
def disable(self):
"""
Disable the service.
"""
self._do_chkconfig('off')
def enable(self):
"""
Enable the service.
"""
self._do_chkconfig('on')
def save(self):
"""
Save the service (if the service supports this command).
"""
self._do_service('save')
def reload(self):
"""
Reload the service.
"""
self._do_service('reload')
def stop(self):
"""
Stop the service.
"""
self._do_service('stop')
def start(self):
"""
Start the service.
"""
#.........这里部分代码省略.........
示例4: _NGUtilCommon
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import success [as 别名]
class _NGUtilCommon(object):
"""
Common class for sharing methods and attributes between NGUtil classes.
"""
def __init__(self):
# Feedback handler
self.feedback = Feedback(use_timestamp=True)
# Data directory
self._DATA = '{0}/data'.format(__root__)
# Template ID / file mappings
self._TEMPLATES = {
'FPM': self._data_map('fpm.conf.template'),
'NG_REPO': self._data_map('nginx.repo.template'),
'NG_CONF': self._data_map('nginx.conf.template'),
'NG_HTTP': self._data_map('site.http.conf'),
'NG_HTTPS': self._data_map('site.https.conf')
}
def die(self, msg, code=1):
"""
Print on stderr and die.
"""
self.feedback.error(msg)
exit(code)
def _data_map(self, FILE):
"""
Map a file to the data directory.
"""
return '{0}/{1}'.format(self._DATA, FILE)
def mkpath(self, _path):
"""
Extract the directory from a file name and make sure the path exists.
"""
self.mkdir(path.dirname(_path))
def mkfile(self, _path, contents=None, overwrite=False):
"""
Make a new file and optionally write data to it.
"""
if path.isfile(_path) and not overwrite:
self.die('Cannot make file "{0}". Already exists and overwrite={1}'.format(_path, repr(overwrite)))
# Make sure the directory exists
self.mkpath(_path)
# Make the file
fh = open(_path, 'w')
# If writing contents
if contents:
fh.write(contents)
# Close the file
fh.close()
# Return the path
return _path
def mkdir(self, dir):
"""
Make directory if it doesn't exist.
"""
if not path.isdir(dir):
makedirs(dir)
self.feedback.success('Created directory: {0}'.format(dir))
else:
self.feedback.info('Directory \'{0}\' already exists, skipping...'.format(dir))
def run_command(self, cmd, expects=0, shell=False, stdout=PIPE, stderr=PIPE):
"""
Run a shell command with Popen
"""
# If the command argument is a string
if isinstance(cmd, str):
cmd = cmd.split(' ')
# Open the process
try:
proc = Popen(cmd, stdout=stdout, stderr=stderr, shell=shell)
out, err = proc.communicate()
# Make sure the expected return code is found
if not proc.returncode == expects:
self.die('Failed to run command \'{0}\', ERROR={1}'.format(str(cmd), err))
# Return exit code / stdout / stderr
return proc.returncode, out, err
except Exception as e:
self.die('Failed to run command \'{0}\': ERROR={1}'.format(str(cmd), str(e)))