diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-11-26 02:07:46 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-11-26 02:07:46 +0100 |
| commit | 761bb3b30b5eb8c923f909effdc0c5ea53b16ac5 (patch) | |
| tree | bb3a7291a8c239d4d68b93ddcb48feb095d9e10d | |
| parent | Improve cmdline parsing (diff) | |
| download | dlu-761bb3b30b5eb8c923f909effdc0c5ea53b16ac5.tar.gz dlu-761bb3b30b5eb8c923f909effdc0c5ea53b16ac5.tar.bz2 dlu-761bb3b30b5eb8c923f909effdc0c5ea53b16ac5.tar.xz | |
small improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
| -rw-r--r-- | README | 6 | ||||
| -rw-r--r-- | dlu.1 | 8 | ||||
| -rwxr-xr-x | dlu.py | 12 |
3 files changed, 17 insertions, 9 deletions
@@ -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. @@ -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 @@ -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() |
