Root/makfa/patches/00-pickle.patch

1diff --git a/makfa b/makfa
2index af7a8b7..488007e 100755
3--- a/makfa
4+++ b/makfa
5@@ -296,19 +296,16 @@ class Update(object):
6     """Update dictionary."""
7 
8     def __init__(self):
9- self.parser = OptionParser(usage='makfa update [language]',
10+ self.parser = OptionParser(usage='makfa update [language] [filename]',
11                                    description=self.__class__.__doc__)
12 
13     def parse(self, argv):
14         options, args = self.parser.parse_args(argv)
15         print 'Updating dictionary...'
16- if args:
17- try:
18- Updater(args[0])
19- except SyntaxError:
20- print 'Invalid language code.'
21- else:
22- Updater()
23+ try:
24+ Updater(*args)
25+ except SyntaxError:
26+ print 'Invalid language code.'
27 
28 
29 class Find(object):
30@@ -488,7 +485,7 @@ class Type(Command):
31 
32 class Updater(object):
33 
34- def __init__(self, lang='en'):
35+ def __init__(self, lang='en', filename=os.path.expanduser('~/makfa.dump')):
36         self.db = {'order': [], 'entries': {}}
37         url = 'http://jbovlaste.lojban.org/export/xml-export.html?lang=%s'
38         tree = etree.parse(urllib.urlopen(url % lang))
39@@ -506,7 +503,7 @@ class Updater(object):
40                 self.db['entries'][word]['places'][place] = []
41             self.db['entries'][word]['places'][place]. \
42                 append((valsi.get('word'), sense))
43- pickle.dump(self.db, open(os.path.expanduser('~/.makfa.dump'), 'w'), -1)
44+ pickle.dump(self.db, open(filename, 'w'), -1)
45 
46     def _save(self, valsi):
47         word = valsi.get('word')
48@@ -618,12 +615,12 @@ class Filter(object):
49 
50 class Dictionary(object):
51 
52- def __init__(self):
53+ def __init__(self, filename=os.path.expanduser('~/makfa.dump')):
54         try:
55- self._db = pickle.load(open(os.path.expanduser('~/.makfa.dump')))
56+ self._db = pickle.load(open(filename))
57         except:
58             print >>sys.stderr, '(Fetching dictionary, this may take a minute.)'
59- self._db = Updater().db
60+ self._db = Updater(filename=filename).db
61         self._longest = max(map(len, self))
62 
63     def definition(self, entry):
64

Archive Download this file



interactive