1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2008 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # dumbshelve.py - Temporary implementation of a shelve replacement
21 # 2008-02-27 Thomas Perl <thpinfo.com>
23 from gpodder
.liblogger
import log
29 class DumbShelve(UserDict
.UserDict
):
31 Simply tries to act like a "shelve" object..
33 def __init__(self
, filename
=None):
34 UserDict
.UserDict
.__init
__(self
)
35 self
.__filename
= filename
38 def sync(self
, filename
=None):
42 if filename
is not None:
43 self
.__filename
= filename
46 cPickle
.dump(self
, open(self
.__filename
, 'w'))
49 log('Cannot pickle me to %s', self
.__filename
, sender
=self
, traceback
=True)
52 def __setitem__(self
, key
, item
):
54 UserDict
.UserDict
.__setitem
__(self
, key
, item
)
56 def __delitem__(self
, key
):
58 UserDict
.UserDict
.__delitem
__(self
, key
)
60 def open_shelve(filename
):
61 if not os
.path
.exists(filename
):
62 return DumbShelve(filename
)
65 return cPickle
.load(open(filename
, 'r'))
67 log('Error loading %s. Creating new DumbShelve.', filename
, traceback
=True)
68 return DumbShelve(filename
)