本文整理汇总了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