fixed loading readline history when the file does not exist

This commit is contained in:
Daniel Pavel 2012-11-02 09:57:08 +02:00
parent 802da6a21a
commit 6e06e39612
4 changed files with 12 additions and 5 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh
LIB=`dirname "$0"`/../lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`uname -m`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`arch`
export PYTHONPATH=$LIB
exec python -OOu -m hidapi.hidconsole "$@"

View File

@ -1,7 +1,7 @@
#!/bin/sh
LIB=`dirname "$0"`/../lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`uname -m`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`arch`
export PYTHONPATH=$LIB
exec python -OOu -m logitech.scanner "$@"

View File

@ -5,7 +5,7 @@ APP=`readlink -f $(dirname "$Z")/../app`
LIB=`readlink -f $(dirname "$Z")/../lib`
SHARE=`readlink -f $(dirname "$Z")/../share`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`uname -m`
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB/native/`arch`
export PYTHONPATH=$APP:$LIB
export XDG_DATA_DIRS=$SHARE:$XDG_DATA_DIRS

View File

@ -45,7 +45,7 @@ def _continuous_read(handle, timeout=1000):
if __name__ == '__main__':
import argparse
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--history', default='.hidconsole-history', help='history file')
arg_parser.add_argument('--history', help='history file')
arg_parser.add_argument('device', default=None, help='linux device to connect to')
args = arg_parser.parse_args()
@ -60,7 +60,14 @@ if __name__ == '__main__':
print (".. Press ^C/^D to exit, or type hex bytes to write to the device.")
import readline
readline.read_history_file(args.history)
if args.history is None:
import os.path
args.history = os.path.join(os.path.expanduser("~"), ".hidconsole-history")
try:
readline.read_history_file(args.history)
except:
# file may not exist yet
pass
start_time = time.time()