本文整理汇总了Python中feedback.Feedback.info方法的典型用法代码示例。如果您正苦于以下问题:Python Feedback.info方法的具体用法?Python Feedback.info怎么用?Python Feedback.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedback.Feedback
的用法示例。
在下文中一共展示了Feedback.info方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DevToolsDpkg
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import info [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 info [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: _NGUtilCommon
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import info [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)))
示例4: DevToolsCommon
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import info [as 别名]
#.........这里部分代码省略.........
:param message: The error message
:type message: str
"""
self.feedback.error(message)
exit(code)
def targz(self, tarball, source, workdir=None):
"""
Make a new Gzip tar file.
:param tarball: The destination tarball to create
:type tarball: str
:param source: The source folder to compress
:type source: str
:param workdir: Change to a new working directory
:type workdir: str
"""
# Get the current working directory
cwd = getcwd()
# If changing working directories prior to compressing
if workdir:
if not path.isdir(workdir):
self.die('Cannot change to working directory <{0}>, not found'.format(workdir))
# Change working directories
chdir(workdir)
# Create the tarfile
with tarfile.open(tarball, 'w:gz') as tar:
tar.add(source)
self.feedback.info('Created tarball: {0}'.format(tarball))
# Revert directory
chdir(cwd)
def rmfile(self, file):
"""
Remove a file/symlink if it exists.
:param file: The target file
:type file: str
"""
if path.isfile(file) or path.islink(file):
unlink(file)
def mvfile(self, src, dst):
"""
Move a file from one place to another.
:param src: The source file
:type src: str
:param dst: The destination file
:type dst: str
"""
move_file(src, dst)
def mklink(self, target, link):
"""
Make a symbolic link.
:param target: The target file
:type target: str
:param link: The target link