本文整理汇总了Python中readline.read_history_file方法的典型用法代码示例。如果您正苦于以下问题:Python readline.read_history_file方法的具体用法?Python readline.read_history_file怎么用?Python readline.read_history_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类readline
的用法示例。
在下文中一共展示了readline.read_history_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_console
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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 read_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: load_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def load_history(self):
global readline
if readline is None:
try:
import readline
except ImportError:
return
if self.history_file_full_path is None:
folder = os.environ.get('USERPROFILE', '')
if not folder:
folder = os.environ.get('HOME', '')
if not folder:
folder = os.path.split(sys.argv[0])[1]
if not folder:
folder = os.path.curdir
self.history_file_full_path = os.path.join(folder,
self.history_file)
try:
if os.path.exists(self.history_file_full_path):
readline.read_history_file(self.history_file_full_path)
except IOError:
e = sys.exc_info()[1]
warnings.warn("Cannot load history file, reason: %s" % str(e))
示例4: enable_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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 read_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: Input_completer
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def Input_completer(keywords):
completer = MyCompleter(keywords)
readline.set_completer(completer.complete)
if "libedit" in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind('tab: complete')
#readline.parse_and_bind('"\\e[A": complete') # Up arrow
readline.parse_and_bind("set colored-completion-prefix on")
readline.parse_and_bind("set show-all-if-unmodified on")
readline.parse_and_bind("set horizontal-scroll-mode on")
if os.path.exists(history_file):
readline.read_history_file(history_file)
readline.set_history_length(20)
readline.set_completer_delims(' ')
atexit.register(save_history)
示例7: init_readline
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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 :-(')
示例8: preloop
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def preloop(self):
"""
preload a history file
"""
history_file = cfg.get('history_file')
logger.debug("using history file {}".format(history_file))
try:
readline.read_history_file(os.path.expanduser(history_file))
except PermissionError:
logger.warning("failed to read CLI history from {} " +
"(no permission)".format(
history_file))
except FileNotFoundError:
pass
readline.set_history_length(int(cfg.get('history_file_size')))
if not self.registered_atexit:
atexit.register(self.history_write)
示例9: hook_readline_hist
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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)
示例10: load_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def load_history(self):
global readline
if readline is None:
try:
import readline
except ImportError:
return
if self.history_file_full_path is None:
folder = os.environ.get('USERPROFILE', '')
if not folder:
folder = os.environ.get('HOME', '')
if not folder:
folder = os.path.split(sys.argv[0])[1]
if not folder:
folder = os.path.curdir
self.history_file_full_path = os.path.join(folder,
self.history_file)
try:
if os.path.exists(self.history_file_full_path):
readline.read_history_file(self.history_file_full_path)
except IOError, e:
warnings.warn("Cannot load history file, reason: %s" % str(e))
示例11: test_nonascii_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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")
示例12: init_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def init_history(self, histfile):
#readline.parse_and_bind("bind ^I rl_complete")
# Register our completer function
readline.set_completer(SimpleCompleter(G.cmmands.keys()).complete)
#readline.set_completer(TabCompleter().complete)
### Add autocompletion
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind -e")
readline.parse_and_bind("bind '\t' rl_complete")
else:
readline.parse_and_bind("tab: complete")
# Use the tab key for completion
#readline.parse_and_bind('tab: complete')
if hasattr(readline, "read_history_file"):
try:
readline.read_history_file(histfile)
except:
pass
atexit.register(self.save_history, histfile)
示例13: start
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_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)
示例14: enable_autocomplete_and_history
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def enable_autocomplete_and_history(adir,env):
try:
import rlcompleter
import atexit
import readline
except ImportError:
pass
else:
readline.parse_and_bind("bind ^I rl_complete"
if sys.platform == 'darwin'
else "tab: complete")
history_file = os.path.join(adir,'.pythonhistory')
try:
readline.read_history_file(history_file)
except IOError:
open(history_file, 'a').close()
atexit.register(readline.write_history_file, history_file)
readline.set_completer(rlcompleter.Completer(env).complete)
示例15: resume
# 需要导入模块: import readline [as 别名]
# 或者: from readline import read_history_file [as 别名]
def resume(self):
"""Read the history file and restart readline."""
self.active = True
readline.read_history_file(self.historyPath)
readline.set_completer(self.tabCompleter.complete)