Python-Skripte: kleine Korrekturen.
[wortliste.git] / skripte / python / edit_tools / compare_word_files.py
blobbd39660f2da3a7851a7a60142e9fbbe7d3b7c6bb
1 #!/usr/bin/env python3
2 # -*- coding: utf8 -*-
3 # :Copyright: © 2014 Günter Milde.
4 # Released without warranty under the terms of the
5 # GNU General Public License (v. 2 or later)
6 # :Id: $Id: $
8 # compare_word_files.py: Vergleichen von Wort-Dateien
9 # ===================================================
10 # ::
12 """Vergleichen zweier Dateien mit einem Wort/Zeile."""
14 # ::
16 import argparse, sys, os
18 from wortliste import filelines, join_word
20 # Default-Aktion::
22 if __name__ == '__main__':
25 # Optionen::
27 parser = argparse.ArgumentParser(description = __doc__,
28 formatter_class=argparse.RawDescriptionHelpFormatter)
29 parser.add_argument('FILE1', help='erste Datei')
30 parser.add_argument('FILE2', help='zweite Datei')
31 parser.add_argument('-c', '--ignorecase', action="store_true",
32 help='Ignoriere Großschreibung (Vorgabe: Nein).',
33 default=False)
34 args = parser.parse_args()
36 # Listen::
38 words = {}
39 new = []
41 # Einlesen Datei1::
43 for line in filelines([args.FILE1]):
44 words[join_word(line).lower()] = line
46 # Vergleich und Ausgabe:
48 print('# Änderungen')
49 for line in filelines([args.FILE2]):
50 try:
51 word = words.pop(join_word(line).lower())
52 except KeyError:
53 new.append(line)
54 continue
56 if args.ignorecase:
57 if word.lower() != line.lower():
58 print('-', word)
59 print('+', line)
60 elif word != line:
61 print('-', word)
62 print('+', line)
64 print('\n# Neu')
65 for i in new:
66 print(i)
68 print('\n# Gelöscht')
69 words = list(words.values())
70 words.sort()
71 for i in words:
72 print(i)