3
# This module implements DpkgDatalist, an abstract class for storing
4
# a list of objects in a file. Children of this class have to implement
5
# the load and _store methods.
7
# Copyright 2001 Wichert Akkerman <wichert@linux.com>
9
# This file is free software; you can redistribute it and/or modify it
10
# under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2 of the License, or
12
# (at your option) any later version.
14
# This program is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
from UserDict import UserDict
25
from OrderedDict import OrderedDict
27
from types import StringType
29
class DpkgDatalistException(Exception):
33
def __init__(self, message="", reason=UNKNOWN, file=None, line=None):
40
def __init__(self, fn=""):
41
'''Initialize a DpkgDatalist object. An optional argument is a
42
file from which we load values.'''
46
self.load(self.filename)
48
def store(self, fn=None):
49
"Store variable data in a file."
53
# Special case for writing to stdout
55
self._store(sys.stdout)
58
# Write to a temporary file first
59
if type(fn) == StringType:
60
vf=SafeWriteFile(fn+".new", fn, "w")
66
if type(fn) == StringType:
70
class DpkgDatalist(UserDict, _DpkgDatalist):
71
def __init__(self, fn=""):
72
UserDict.__init__(self)
73
_DpkgDatalist.__init__(self, fn)
76
class DpkgOrderedDatalist(OrderedDict, _DpkgDatalist):
77
def __init__(self, fn=""):
78
OrderedDict.__init__(self)
79
_DpkgDatalist.__init__(self, fn)