Debian Codegraph @

bin/grokevt-dumpmsgs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/python3
2
3 # This script dumps the contents of message databases built by grokevt-ripdll.
4 #
5 # Copyright (C) 2006-2007,2011 Timothy D. Morgan
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation version 3 of the
10 # License.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # vi:set tabsize=4:
18 # $Id: grokevt-dumpmsgs 119 2011-06-20 17:14:14Z tim $
19
20
21 import sys
22 import os
23 import dbm
24
25 import grokevt
26
27
28 def usage():
29 sys.stderr.write("USAGE:\n")
30 sys.stderr.write(" %s <MESSAGE_DB1> [<MESSAGE_DB2> ...]\n\n"\
31 % os.path.basename(sys.argv[0]))
32 sys.stderr.write("grokevt-dumpmsgs dumps the contents of message databases\n")
33 sys.stderr.write("built previously by grokevt-ripdll.\n")
34
35
36 if len(sys.argv) < 2:
37 usage()
38 sys.exit(os.EX_USAGE)
39
40 for dbfile in sys.argv[1:]:
41 if not os.access(dbfile, os.R_OK):
42 sys.stderr.write("ERROR: DB file could not be read.")
43 sys.exit(1)
44
45 db = dbm.open(dbfile.split('.db', 1)[0], 'r')
46
47 if grokevt.template_encoding == grokevt.output_encoding:
48 for key in db.keys():
49 print('%s,%s' % (key.decode('ascii'), grokevt.quoteBinary(db[key], b'%,"')))
50 else:
51 for key in db.keys():
52 msg = db[key].decode(grokevt.template_encoding)
53 msg = grokevt.quoteBinary(msg.encode(grokevt.output_encoding,'replace'),
54 b'%,"')
55 print('%s,%s' % (key.decode('ascii'), msg))
56
57 db.close()