aboutsummaryrefslogtreecommitdiff
path: root/dicofr.py
diff options
context:
space:
mode:
Diffstat (limited to 'dicofr.py')
-rwxr-xr-xdicofr.py44
1 files changed, 32 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: