Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shlib: drop shelve in lieu of simpler pickle file

No more silly locking problems. It uses Mercurial's atomictempfile class
to manage overwriting the configuration file (write to temp, close, rename).
Uses cPickle to dump/parse the config data, this is simple and efficient.

Changeset 7db597d06ead

Parent bea2cda18f91

by Steve Borho

Changes to one file · Browse files at 7db597d06ead Showing diff from parent bea2cda18f91 Diff from another changeset...

Change 1 of 2 Show Entire File hggtk/​shlib.py Stacked
 
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
 
21
22
23
 
90
91
92
93
94
95
96
97
98
99
100
101
102
 
 
 
 
 
 
 
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
 
 
 
117
118
119
120
 
 
121
122
123
 
124
125
126
 
7
8
9
 
 
 
10
11
12
 
13
14
15
16
17
18
19
20
21
 
88
89
90
 
 
 
 
 
 
 
 
 
 
91
92
93
94
95
96
97
98
99
100
101
102
 
 
 
 
 
 
 
 
 
103
104
105
106
107
108
109
 
110
111
112
113
 
114
115
116
117
@@ -7,17 +7,15 @@
   """   -import dumbdbm, anydbm -anydbm._defaultmod = dumbdbm -  import os  import sys  import gtk -import shelve +import cPickle  import time  import hgtk  import gobject  from mercurial.i18n import _ +from mercurial import util    class SimpleMRUList(object):   def __init__(self, size=10, reflist=[], compact=True): @@ -90,37 +88,30 @@
    def read(self):   self._data.clear() - if not os.path.exists(self._path+'.dat'): - return - dbase = shelve.open(self._path) - try: - self._dbappname = dbase['APPNAME'] - self.version = dbase['VERSION'] - self._data.update(dbase.get('DATA', {})) - except KeyError: - pass - dbase.close() + if os.path.exists(self._path): + try: + f = file(self._path, 'rb') + self._data = cPickle.loads(f.read()) + f.close() + except Exception: + pass     def write(self):   self._write(self._path, self._data)     def _write(self, appname, data): - dbase = shelve.open(self._get_path(appname)) - dbase['VERSION'] = Settings.version - dbase['APPNAME'] = appname - dbase['DATA'] = data - try: - dbase.close() - except IOError: - pass # Don't care too much about permission errors - + s = cPickle.dumps(data) + f = util.atomictempfile(appname, 'wb', None) + f.write(s) + f.rename()     def _get_path(self, appname):   if os.name == 'nt': - return os.path.join(os.environ.get('APPDATA'), 'TortoiseHg', appname) + return os.path.join(os.environ.get('APPDATA'), 'TortoiseHg', + appname)   else:   return os.path.join(os.path.expanduser('~'), '.tortoisehg', - 'settings', appname) + appname)     def _audit(self):   if os.path.exists(os.path.dirname(self._path)):