当前位置: 首页>>代码示例>>Python>>正文


Python Feedback.set方法代码示例

本文整理汇总了Python中feedback.Feedback.set方法的典型用法代码示例。如果您正苦于以下问题:Python Feedback.set方法的具体用法?Python Feedback.set怎么用?Python Feedback.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在feedback.Feedback的用法示例。


在下文中一共展示了Feedback.set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Bootstrap

# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import set [as 别名]
class Bootstrap(object):
    """
    Main class object for bootstrapping the Lense installation. This
    includes setting up the database and setting the admin user account.
    """
    def __init__(self):
        self.feedback = Feedback()
    
        # Configuration / logger
        self.conf   = config.parse()
        self.log    = logger.create('bootstrap', '{}/bootstrap.log'.format(LOG_DIR))
    
        # Bootstrap parameters
        self.params = BootstrapParams()
    
        # Server configuration file
        self.server_conf = self.params.file['config']['server_conf'][1]
        
        # Database connection
        self._connection = None
    
    def _die(self, msg):
        """
        Quit the program
        """
        self.log.error(msg)
        self.feedback.set(msg).error()
        sys.exit(1)
    
    def _deploy_config(self):
        """
        Deploy configuration files.
        """
        for f,p in self.params.file['config'].iteritems():
            if not os.path.isfile(p[1]):
                
                # Read the default file content
                c_file = open(p[0], 'r')
                c_str  = c_file.read()
                c_file.close()
                
                # Create the new configuration file
                d_file = open(p[1], 'w')
                d_file.write(c_str)
                d_file.close()
                
                # File deployed
                self.feedback.set('File <{}> deployed'.format(p[1])).success()
            else:
                self.feedback.set('File <{}> already deployed, skipping...'.format(p[1])).info()
    
        # Create the log and run directories
        for _dir in ['log', 'run']:
            dir = '{}/{}'.format(PKG_ROOT, _dir)
            if not os.path.isdir(dir):
                os.mkdir(dir)
                self.feedback.set('Created directory "{}"'.format(dir))
            else:
                self.feedback.set('Directory "{}" already exists, skipping...'.format(dir))
    
    def _get_password(self, prompt, min_length=8):
        _pass = getpass(prompt)
        
        # Make sure the password is long enough
        if not len(_pass) >= min_length:
            self.feedback.set('Password cannot be empty and must be at least {} characters long'.format(str(min_length))).error()
            return self._get_password(prompt, min_length)
            
        # Confirm the password
        _pass_confirm = getpass('Please confirm the password: ')
            
        # Make sure the passwords match
        if not _pass == _pass_confirm:
            self.feedback.set('Passwords do not match, try again').error()
            return self._get_password(prompt, min_length)
        return _pass
    
    def _get_input(self, prompt, default=None):
        _input = raw_input(prompt) or default
        
        # If no input found
        if not _input:
            self.feedback.set('Must provide a value').error()
            return self._get_input(prompt, default)
        return _input
    
    def _try_mysql_root(self):
        """
        Attempt to connect to the MySQL server as root user.
        """
        try:
            self._connection = MySQLdb.connect(
                host   = self.params.input.response.get('db_host'), 
                port   = int(self.params.input.response.get('db_port')),
                user   = 'root',
                passwd = self.params.input.response.get('db_root_password')
            )
            self.feedback.set('Connected to MySQL using root user').success()
        except Exception as e:
            self._die('Unable to connect to MySQL with root user: {}'.format(str(e)))
#.........这里部分代码省略.........
开发者ID:djtaylor,项目名称:lense-common,代码行数:103,代码来源:manager.py


注:本文中的feedback.Feedback.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。