From 761bb3b30b5eb8c923f909effdc0c5ea53b16ac5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 26 Nov 2016 02:07:46 +0100 Subject: small improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- README | 6 ++++-- dlu.1 | 8 ++++++-- dlu.py | 12 +++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README b/README index 5046a99..934b424 100644 --- a/README +++ b/README @@ -13,9 +13,11 @@ DESCRIPTION list_dictionaries() Returns a list of all dictionaries. - load_dictionary(dictionary : str) + load_dictionary(dictionary : str) -> bool Sets the fuction get() or a variable that get() reads - to identify which dictionary has been selected. + to identify which dictionary has been selected. The + function shall return True if the dictionary exists, + and False otherwise. open_dictionary(file : str, page : int) Opens the specified page in the specified file. diff --git a/dlu.1 b/dlu.1 index 1cf8c40..7e3468a 100644 --- a/dlu.1 +++ b/dlu.1 @@ -22,14 +22,18 @@ a Python 3 file which defines the functions: .BR list_dictionaries () Returns a list of all dictionaries. .TP -.BR load_dictionary "(\fIdictionary\fP : str)" +.BR load_dictionary "(\fIdictionary\fP : str) -> bool" Sets the fuction .BR get () or a variable that .BR get () reads to identify which .I dictionary -has been selected. +has been selected. The function shall return +.B True +if the dictionary exists, and +.B False +otherwise. .TP .BR open_dictionary "(\fIfile\fP : str, \fIpage\fP : int)" Opens the specified diff --git a/dlu.py b/dlu.py index c12b702..ddbcc32 100755 --- a/dlu.py +++ b/dlu.py @@ -50,9 +50,9 @@ if not f_list: for command_lambda in reads[disps[0]]: command = command_lambda(filename, str(page)); os.execvp(command[0], command) - sys.stderr.print("%s: could find any viewer to use." % sys.argv[0]) - sys.stderr.print("%s: file to open: %s" % (sys.argv[0], filename)) - sys.stderr.print("%s: page to open: %i" % (sys.argv[0], page)) + print("%s: could find any viewer to use." % sys.argv[0], file = sys.stderr) + print("%s: file to open: %s" % (sys.argv[0], filename), file = sys.stderr) + print("%s: page to open: %i" % (sys.argv[0], page), file = sys.stderr) sys.exit(1) ## Load configurations, which holds data needed to perform the lookup. @@ -111,7 +111,7 @@ if config_file is not None: # also redefine it for us. exec(code, g) else: - print('No configuration file found') + print('%s: no configuration file found' % sys.argv[0], file = sys.stderr) sys.exit(1) ## List available dictionaries. @@ -121,7 +121,9 @@ if f_list: sys.exit(0) ## Perform lookup. -load_dictionary(dictionary_name) +if not load_dictionary(dictionary_name): + print('%s: dictionary not found: %s' % (sys.argv[0], dictionary_name), file = sys.stderr) + sys.exit(1) sought_word = wordmod(sought_word) filename, lasts, page_remap = get() -- cgit v1.2.3-70-g09d2