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


Python Utils.get_current_time_string方法代码示例

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


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

示例1: login

# 需要导入模块: from utils.utils import Utils [as 别名]
# 或者: from utils.utils.Utils import get_current_time_string [as 别名]
 def login(self, hostname, username, password):        
     cmd = 'ssh ' + username + '@' + hostname
     self._logger.debug(cmd)
     _session = pexpect.spawn(cmd, timeout=Define.TIMEOUT_SSH)
     if define.PEXPECT_OUTPUT_STDOUT:
         _session.logfile_read = sys.stdout
     else:
         #Utils.append_file(Define.PATH_USNIC_LOG_FILE_ALL, Define.PATH_USNIC_LOG_FILE)
         self._log_file = Define.PATH_USNIC_LOG + hostname + "_" + Utils.get_current_time_string()
         self._logger.info(self._log_file)
         _session.logfile_read = file(self._log_file, "w")
     ret = _session.expect([pexpect.TIMEOUT, pexpect.EOF, Define.PATTERN_SSH_NEW_KEY, Define.PATTERN_PROMPT, Define.PATTERN_PASSWORD])
     if ret == 0:
         self._logger.warn('timeout when ssh to ' + hostname)
         os.remove(self._log_file)
         return None
     elif ret == 1:
         self._logger.warn('end of file when ssh to ' + hostname)
         os.remove(self._log_file)
         return None
     elif ret == 2:
         _session.sendline('yes')
         _session.expect(Define.PATTERN_PASSWORD)
         _session.sendline(password)
         ret = _session.expect([pexpect.TIMEOUT, Define.PATTERN_PROMPT])
         if ret == 0:
             self._logger.warn("timeout after sending password")
             os.remove(self._log_file)
             return None
     elif ret == 3:
         pass
     elif ret == 4:
         _session.sendline(password)
         ret = _session.expect([pexpect.TIMEOUT, Define.PATTERN_PROMPT])
         if ret == 0:
             self._logger.warn("timeout after sending password")
             os.remove(self._log_file)
             return None
     return _session
开发者ID:huhe56,项目名称:verbs,代码行数:41,代码来源:ssh.py


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