本文整理汇总了Python中readline.set_history_length函数的典型用法代码示例。如果您正苦于以下问题:Python set_history_length函数的具体用法?Python set_history_length怎么用?Python set_history_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_history_length函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pythonrc_enable_history
def pythonrc_enable_history():
import os
import sys
try:
import readline
except ImportError as e:
sys.stderr.write(str(e) + " - Command-line history is disabled.\n")
else:
# The history file.
PYHISTORY = os.path.expanduser('~/.pyhistory')
# Restore command-line history.
if os.path.isfile(PYHISTORY):
readline.read_history_file(PYHISTORY)
# Save command-line history when Python exits.
try:
import atexit
except ImportError as e:
sys.stderr.write(str(e) + " - Command-line history will not be saved when Python exits.\n")
else:
atexit.register(readline.write_history_file, PYHISTORY)
# Set history size.
readline.set_history_length(10000000)
示例2: __init__
def __init__(self, options):
"""
Constructor
"""
readline.parse_and_bind("tab: complete")
readline.set_completer(self.complete)
readline.set_completion_display_matches_hook(self.completer_print)
try:
readline.read_history_file(CLI_HISTORY)
except IOError:
pass
readline.set_history_length(CLI_MAX_CMD_HISTORY)
if not os.path.isdir(CLI_RESULT_HISTORY_FOLDER):
os.system('rm -rf %s' % os.path.dirname(CLI_RESULT_HISTORY_FOLDER))
os.system('mkdir -p %s' % os.path.dirname(CLI_RESULT_HISTORY_FOLDER))
try:
self.hd = filedb.FileDB(CLI_RESULT_HISTORY_KEY, is_abs_path=True)
except:
os.system('rm -rf %s' % CLI_RESULT_HISTORY_KEY)
self.hd = filedb.FileDB(CLI_RESULT_HISTORY_KEY, is_abs_path=True)
print "\nRead history file: %s error. Has recreate it.\n" % CLI_RESULT_HISTORY_KEY
self.start_key = 'start_key'
self.last_key = 'last_key'
self.cli_cmd_func = {'help': self.show_help,
'history': self.show_help,
'more': self.show_more,
'quit': sys.exit,
'exit': sys.exit,
'save': self.save_json_to_file}
self.cli_cmd = self.cli_cmd_func.keys()
self.raw_words_db = self._parse_api_name(inventory.api_names)
self.words_db = list(self.raw_words_db)
self.words_db.extend(self.cli_cmd)
self.words = list(self.words_db)
self.is_cmd = False
self.curr_pattern = None
self.matching_words = None
self.api_class_params = {}
self.build_api_parameters()
self.api = None
self.account_name = None
self.user_name = None
self.session_uuid = None
if os.path.exists(SESSION_FILE):
try:
with open(SESSION_FILE, 'r') as session_file_reader:
self.session_uuid = session_file_reader.readline().rstrip()
self.account_name = session_file_reader.readline().rstrip()
self.user_name = session_file_reader.readline().rstrip()
except EOFError:
pass
self.hostname = options.host
self.port = options.port
self.no_secure = options.no_secure
self.api = api.Api(host=self.hostname, port=self.port)
示例3: init_history
def init_history(self, histfile):
if hasattr(readline, "read_history_file"):
tryBackup = False
try:
tryBackup = not os.path.exists(histfile)
if not tryBackup:
historyFileDesc = open(histfile)
historyFileDesc.seek(0, 2)
tryBackup = (historyFileDesc.tell() == 0)
historyFileDesc.close()
except:
tryBackup = False
try:
if tryBackup:
try:
if os.path.exists(histfile + '_backup'):
import shutil
shutil.copy(histfile + '_backup', histfile)
except:
pass
readline.read_history_file(histfile)
except IOError:
pass
readline.set_history_length(1000)
atexit.register(self.save_history, histfile)
示例4: setup
def setup():
# Create temporary directory for storing serialized objects.
if not os.path.exists("_temp/"):
os.mkdir("_temp/")
# Configure log file for the application.
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s: %(message)s',
filename='cl_gui.log')
logging.info("Starting application...")
# Code snippet for recalling previous commands with the
# 'up' and 'down' arrow keys.
import rlcompleter
import atexit
import readline
hist_file = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(hist_file)
except IOError:
pass
# Set a limit on the number of commands to remember.
# High values will hog system memory!
readline.set_history_length(25)
atexit.register(readline.write_history_file, hist_file)
# Tab completion for GUI commands
def completer(text, state):
commands = Status.ALL_COMMANDS
file_paths = []
for dirname, dirnames, filenames in os.walk('.'):
if '.git' in dirnames:
# don't go into any .git directories.
dirnames.remove('.git')
# Add path to subdirectories
file_paths.extend([os.path.join(dirname, sub_dir) for sub_dir in dirnames])
# Add path to all filenames in subdirectories.
file_paths.extend([os.path.join(dirname, filename) for filename in filenames])
# Remove './' header in file strings.
file_paths = [file.strip('./') for file in file_paths]
options = [i for i in commands if i.startswith(text)]
options.extend([f for f in file_paths if f.startswith(text)])
try:
return options[state]
except IndexError:
return None
readline.set_completer(completer)
# Bind tab completer to specific platforms
if readline.__doc__ and '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")
del hist_file, readline, rlcompleter
示例5: save_history
def save_history(self):
if hasReadline and self._history_path:
readline.set_history_length(1000)
try:
readline.write_history_file(self._history_path)
except:
pass
示例6: __init__
def __init__(self, base, conf=None, path=None, task=None, wait=None):
cmd.Cmd.__init__(self)
self.base = urlparse.urlparse(base)
self.user = getpass.getuser()
self.hdfs = WebHDFSClient(self.base._replace(path='').geturl(), self.user, conf, wait)
self.do_cd(path or self.base.path)
if task:
self.onecmd(' '.join(task))
sys.exit(0)
try:
self.hist = os.path.join(os.path.expanduser('~'), os.environ.get('WEBHDFS_HISTFILE', '.webhdfs_history'))
readline.read_history_file(self.hist)
except IOError:
pass
try:
readline.set_history_length(int(os.environ.get('WEBHDFS_HISTSIZE', 3)))
except ValueError:
readline.set_history_length(0)
if os.access(self.hist, os.W_OK):
atexit.register(readline.write_history_file, self.hist)
示例7: save_history
def save_history(historyPath=historyPath):
import readline
try:
readline.set_history_length(1000)
readline.write_history_file(historyPath)
except IOError:
print 'skipping the history writing'
示例8: __init__
def __init__(self, *args, **kwargs):
self.restshlib = restshlib.RestSHLib(global_data=self.global_data)
self.prompt = self.cfg_prompt % {"login": self.login, "baseurl": self.baseurl}
readline.read_history_file(self.history_file)
readline.set_history_length(self.history_file_max_lines)
super(RestSH, self).__init__(*args, **kwargs)
示例9: history_init
def history_init(self, filename, size):
self.history_file = filename
self.history_size = size
if filename and os.path.exists(filename):
readline.read_history_file(filename)
readline.set_history_length(size)
self.history_reset()
示例10: __init__
def __init__(self):
super().__init__()
try:
import readline
readline.set_history_length(core.MAX_HISTORY_SIZE)
except ImportError:
pass
示例11: setup
def setup(self):
""" Initialization of third-party libraries
Setting interpreter history.
Setting appropriate completer function.
:return:
"""
if not os.path.exists(self.history_file):
with open(self.history_file, 'a+') as history:
if is_libedit():
history.write("_HiStOrY_V2_\n\n")
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;')
if is_libedit():
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
示例12: Interact
def Interact(session):
import readline
try:
readline.read_history_file(session.config.history_file())
except IOError:
pass
readline.set_history_length(100)
try:
while True:
session.ui.block()
opt = raw_input('mailpile> ').decode('utf-8').strip()
session.ui.unblock()
if opt:
if ' ' in opt:
opt, arg = opt.split(' ', 1)
else:
arg = ''
try:
Action(session, opt, arg)
except UsageError, e:
session.error(str(e))
except EOFError:
print
readline.write_history_file(session.config.history_file())
示例13: __init__
def __init__( self ):
cmd.Cmd.__init__( self )
self.connected = False
self.masterURL = "unset"
self.writeEnabled = False
self.modifiedData = False
self.rpcClient = None
self.do_connect()
if self.connected:
self.modificator = Modificator ( self.rpcClient )
else:
self.modificator = Modificator()
self.identSpace = 20
self.backupFilename = "dataChanges"
self._initSignals()
#User friendly hack
self.do_exit = self.do_quit
# store history
histfilename = os.path.basename(sys.argv[0])
historyFile = os.path.expanduser( "~/.dirac/%s.history" % histfilename[0:-3])
if not os.path.exists( os.path.dirname(historyFile) ):
os.makedirs( os.path.dirname(historyFile) )
if os.path.isfile( historyFile ):
readline.read_history_file( historyFile )
readline.set_history_length(1000)
atexit.register( readline.write_history_file, historyFile )
示例14: _init_history
def _init_history(self):
try:
readline.set_history_length(100)
readline.read_history_file(self._history_file)
except IOError:
pass
atexit.register(self._save_history)
示例15: Interact
def Interact(session):
import readline
try:
readline.read_history_file(session.config.history_file())
except IOError:
pass
# Negative history means no saving state to disk.
history_length = session.config.sys.history_length
if history_length >= 0:
readline.set_history_length(history_length)
else:
readline.set_history_length(-history_length)
try:
prompt = session.ui.palette.color('mailpile> ',
color=session.ui.palette.BLACK,
weight=session.ui.palette.BOLD)
while True:
session.ui.block()
opt = raw_input(prompt).decode('utf-8').strip()
session.ui.unblock()
if opt:
if ' ' in opt:
opt, arg = opt.split(' ', 1)
else:
arg = ''
try:
session.ui.display_result(Action(session, opt, arg))
except UsageError, e:
session.error(unicode(e))
except UrlRedirectException, e:
session.error('Tried to redirect to: %s' % e.url)