本文整理汇总了Python中readline.write_history_file方法的典型用法代码示例。如果您正苦于以下问题:Python readline.write_history_file方法的具体用法?Python readline.write_history_file怎么用?Python readline.write_history_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.write_history_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_console
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def run_console(glob):
import readline
import rlcompleter
import atexit
import code
history_path = os.path.expanduser("~/.python_history")
def save_history(history_path=history_path):
readline.write_history_file(history_path)
if os.path.exists(history_path):
readline.read_history_file(history_path)
atexit.register(save_history)
readline.set_completer(rlcompleter.Completer(glob).complete)
readline.parse_and_bind("tab: complete")
code.InteractiveConsole(locals=glob).interact()
示例2: __init__
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def __init__(self):
"""Create the main mode.
If titus.inspector.defs.CONFIG_DIRECTORY_EXISTS is ``True``, get the readline history file from the user's titus.inspector.defs.CONFIG_DIRECTORY.
"""
if CONFIG_DIRECTORY_EXISTS:
self.historyPath = os.path.join(os.path.expanduser(CONFIG_DIRECTORY), self.historyFileName)
if not os.path.exists(self.historyPath):
open(self.historyPath, "w").close()
self.active = True
self.tabCompleter = TabCompleter(self)
readline.read_history_file(self.historyPath)
readline.set_completer(self.tabCompleter.complete)
def writehistory():
if self.active:
readline.write_history_file(self.historyPath)
atexit.register(writehistory)
示例3: save_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def save_history(self):
if self.history_file_full_path is not None:
global readline
if readline is None:
try:
import readline
except ImportError:
return
try:
readline.write_history_file(self.history_file_full_path)
except IOError:
e = sys.exc_info()[1]
warnings.warn("Cannot save history file, reason: %s" % str(e))
#------------------------------------------------------------------------------
# Main loop
# Debugging loop.
示例4: enable_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def enable_history(self, history_file: str) -> None:
self.histfile = os.path.expanduser(history_file)
try:
readline.read_history_file(self.histfile)
except FileNotFoundError:
pass
except PermissionError:
self.histfile = ""
print(
f"Warning: You don't have permissions to read {history_file} and\n"
" the command history of this session won't be saved.\n"
" Either change this file's permissions, recreate it,\n"
" or use an alternate path with the SDB_HISTORY_FILE\n"
" environment variable.")
return
readline.set_history_length(1000)
atexit.register(readline.write_history_file, self.histfile)
示例5: setup
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def setup(self):
""" Initialization of third-party libraries
Setting interpreter history.
Setting appropriate completer function.
:return:
"""
if not os.path.exists(self.history_file):
open(self.history_file, 'a+').close()
readline.read_history_file(self.history_file)
readline.set_history_length(self.history_length)
atexit.register(readline.write_history_file, self.history_file)
readline.parse_and_bind('set enable-keypad on')
readline.set_completer(self.complete)
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
示例6: init_readline
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def init_readline(complete_method, histfile=None):
"""init the readline library if available"""
try:
import readline
readline.parse_and_bind("tab: complete")
readline.set_completer(complete_method)
string = readline.get_completer_delims().replace(':', '')
readline.set_completer_delims(string)
if histfile is not None:
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
except:
print('readline si not available :-(')
示例7: hook_readline_hist
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def hook_readline_hist():
try:
import readline
except ImportError:
return
histfile = os.environ['HOME'] + '/.web_develop_history' # 定义一个存储历史记录的文件地址
readline.parse_and_bind('tab: complete')
try:
readline.read_history_file(histfile)
except IOError:
pass # It doesn't exist yet.
def savehist():
try:
readline.write_history_file(histfile)
except:
print 'Unable to save Python command history'
atexit.register(savehist)
示例8: postloop
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def postloop(self):
"""Take care of any unfinished business.
Despite the claims in the Cmd documentaion, Cmd.postloop() is not a stub.
"""
try:
if readline:
readline.write_history_file(sys.argv[0] + ".history")
except Exception as err:
if not isinstance(err, IOError):
self.stdout.write("history error: %s\n" % err)
# clean up command completion
cmd.Cmd.postloop(self)
if self.interactive:
self.stdout.write("Exiting...\n")
# tell the core we have stopped
core.deferred(core.stop)
示例9: save_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def save_history(self):
if self.history_file_full_path is not None:
global readline
if readline is None:
try:
import readline
except ImportError:
return
try:
readline.write_history_file(self.history_file_full_path)
except IOError, e:
warnings.warn("Cannot save history file, reason: %s" % str(e))
#------------------------------------------------------------------------------
# Main loop
# Debugging loop.
示例10: test_nonascii_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def test_nonascii_history(self):
readline.clear_history()
try:
readline.add_history("entrée 1")
except UnicodeEncodeError as err:
self.skipTest("Locale cannot encode test data: " + format(err))
readline.add_history("entrée 2")
readline.replace_history_item(1, "entrée 22")
readline.write_history_file(TESTFN)
self.addCleanup(os.remove, TESTFN)
readline.clear_history()
readline.read_history_file(TESTFN)
if is_editline:
# An add_history() call seems to be required for get_history_
# item() to register items from the file
readline.add_history("dummy")
self.assertEqual(readline.get_history_item(1), "entrée 1")
self.assertEqual(readline.get_history_item(2), "entrée 22")
示例11: start
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def start(self):
self.cmd_manager.init()
log('%s started - GL HF!' % Color.colorify('frick', 'green highligh'))
readline.parse_and_bind('tab: complete')
hist = os.path.join(os.environ['HOME'], '.frick_history')
try:
readline.read_history_file(hist)
except IOError:
pass
atexit.register(readline.write_history_file, hist)
while True:
inp = six.moves.input().strip()
if len(inp) > 0:
self.cmd_manager.handle_command(inp)
示例12: pause
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def pause(self):
"""Write the current history to the history file and stop readline."""
readline.write_history_file(self.historyPath)
readline.clear_history()
readline.set_completer()
self.active = False
示例13: remote_api_shell
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def remote_api_shell(servername, appid, path, secure, rpc_server_factory):
"""Actually run the remote_api_shell."""
remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
servername=servername,
save_cookies=True, secure=secure,
rpc_server_factory=rpc_server_factory)
remote_api_stub.MaybeInvokeAuthentication()
os.environ['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'
if not appid:
appid = os.environ['APPLICATION_ID']
sys.ps1 = '%s> ' % appid
if readline is not None:
readline.parse_and_bind('tab: complete')
atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
if os.path.exists(HISTORY_PATH):
readline.read_history_file(HISTORY_PATH)
if '' not in sys.path:
sys.path.insert(0, '')
preimported_locals = {
'memcache': memcache,
'urlfetch': urlfetch,
'users': users,
'db': db,
'ndb': ndb,
}
code.interact(banner=BANNER, local=preimported_locals)
示例14: setup
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def setup():
history_file = "./.history"
if not os.path.exists(history_file):
open(history_file, 'a+').close()
readline.read_history_file(history_file)
readline.set_history_length(history_length)
atexit.register(readline.write_history_file, history_file)
readline.parse_and_bind('set enable-keypad on')
readline.set_completer(complete)
readline.set_completer_delims(' \t\n;')
readline.parse_and_bind("tab: complete")
示例15: do_exit
# 需要导入模块: import readline [as 别名]
# 或者: from readline import write_history_file [as 别名]
def do_exit(self, line):
self.close()
if not self.execute_only_mode and readline.get_current_history_length() > 0:
readline.write_history_file(self.admin_history)
return True