aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2020-12-10 18:52:57 +0100
committerache <ache@ache.one>2020-12-10 18:52:57 +0100
commit39bba7b885726aa390bfd3bfbfe02fb5cf811b73 (patch)
tree04fd943db6f9e850b7d59bbb52d5958ae182f07f
parentUniformisation and rename (diff)
Command line parser
-rwxr-xr-xdicofr.py44
-rwxr-xr-xdownload/download.py6
2 files changed, 38 insertions, 12 deletions
diff --git a/dicofr.py b/dicofr.py
index 7fa018d..399c632 100755
--- a/dicofr.py
+++ b/dicofr.py
@@ -18,7 +18,7 @@ import os
import ui
-DEBUG = False
+DEBUG = True
if DEBUG:
DIR_PATH = os.getcwd()
@@ -98,19 +98,10 @@ def matching(word):
if __name__ == '__main__':
if len(sys.argv) < 2:
- print("Erreur: Rechercher un mot\nUtilisez l'option -h pour avoir de l'aide",
+ print('''Erreur: Rechercher un mot\nUtilisez l'option -h pour avoir de l'aide''',
file=sys.stderr)
exit(-1)
- # Si on n'arrive pas à trouver le dictionnaire
- if not exists(dico):
- if not exists(f'{DIR_PATH}/{dico}'):
- print('Error: No sqlite dictionnary', file=sys.stderr)
- print(f'Default directory is set to "{DIR_PATH}"', file=sys.stderr)
- exit(1)
- else:
- dico = f'{DIR_PATH}/{dico}'
-
parser = argparse.ArgumentParser(description='Get a french word\'s definition')
parser.add_argument('--sql', dest='action', action='store_const',
const=get_def_sql_reg, default=get_def_sql,
@@ -118,11 +109,40 @@ if __name__ == '__main__':
'_ to match a letter, %% to match a group of letters')
parser.add_argument('-m', '--matching', dest='matching', action='store_true',
help='search the french words that match the regex')
- parser.add_argument('word', metavar='PATTERN', type=str,
+ parser.add_argument('word', metavar='PATTERN', type=str, nargs='?',
help='the word or the pattern to match')
+ parser.add_argument('-l', '--word-list', dest='wordList', action='store',
+ help='the filename of the word list',
+ default=None)
+ parser.add_argument('-d', '--dico', dest='dico', action='store',
+ help='the filename of the dictionnary',
+ default='dfr.db')
+ parser.add_argument('-u', '--update', dest='update', type=str, nargs='?', const=dico,
+ help='update the database')
arg = parser.parse_args()
+ if arg.dico:
+ dico = arg.dico
+
+ if arg.update:
+ os.chdir(DIR_PATH)
+ from subprocess import call
+ if arg.wordList:
+ r = call(['/usr/bin/env', 'python', f'{DIR_PATH}/download/download.py', '--download', '--output', dico, '--word-list', arg.wordList])
+ else:
+ r = call(['/usr/bin/env', 'python', f'{DIR_PATH}/download/download.py', '--download', '--output', dico])
+ exit(r)
+
+ # Si on n'arrive pas à trouver le dictionnaire
+ if not exists(dico):
+ if not exists(f'{DIR_PATH}/assets/{dico}'):
+ print('Error: No sqlite dictionnary', file=sys.stderr)
+ print(f'Default directory is set to "{DIR_PATH}"', file=sys.stderr)
+ exit(1)
+ else:
+ dico = f'{DIR_PATH}/assets/{dico}'
+
if arg.matching:
ret = matching(arg.word)
for word in ret:
diff --git a/download/download.py b/download/download.py
index 25fae89..6939c59 100755
--- a/download/download.py
+++ b/download/download.py
@@ -39,6 +39,9 @@ if __name__ == '__main__':
parser.add_argument('-i', '--in', dest='dumpF', action='store',
help='the input dump file\'s filename',
default='')
+ parser.add_argument('-l', '--word-list', dest='wordList', action='store',
+ help='the alternative output, filename of the word list',
+ default=None)
parser.add_argument('-d', '--download', dest='download', action='store_true',
help='to download the lastest dump')
@@ -46,6 +49,9 @@ if __name__ == '__main__':
download = True
+ if not arg.wordList:
+ arg.wordList = arg.outputF + '.wordlist'
+
if download and arg.dumpF:
print('''Incompatible options '-i' and '-d'.''')
exit(1)