]>
git.ipfire.org Git - pakfire.git/blob - python/pakfire/repository/metadata.py
2 ###############################################################################
4 # Pakfire - The IPFire package management system #
5 # Copyright (C) 2011 Pakfire development team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
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. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 from pakfire
.constants
import *
27 class Metadata(object):
28 def __init__(self
, pakfire
, index
, metafile
=None, metadata
=None):
29 self
.pakfire
= pakfire
32 self
.filename
= metafile
34 # Place where we save the data.
37 "revision" : int(time
.time()),
38 "version" : METADATA_FORMAT
,
41 # If a file was passed, we open it.
45 # ... or parse the one that was passed.
49 def __cmp__(self
, other
):
51 Compare two sets of metadata by their revision.
53 return cmp(self
.revision
, other
.revision
)
55 def parse(self
, metadata
):
57 self
._data
= json
.loads(metadata
)
59 raise # XXX catch json exceptions here
61 def open(self
, filename
=None):
63 Open a given file or use the default one and parse the
67 filename
= self
.filename
69 with
open(filename
) as f
:
72 def save(self
, filename
=None):
74 Save all data to a file that could be exported to a
78 filename
= self
.filename
80 f
= open(filename
, "w")
82 # Write all data to the fileobj.
83 json
.dump(self
._data
, f
, indent
=2)
90 Returns the version of the metadata.
92 return self
._data
.get("version")
97 Returns the revision of the metadata.
99 return self
._data
.get("revision")
101 def get_database(self
):
102 return self
._data
.get("database")
104 def set_database(self
, val
):
105 self
._data
["database"] = val
107 database
= property(get_database
, set_database
)
109 def get_database_hash1(self
):
110 return self
._data
.get("database_hash1", None)
112 def set_database_hash1(self
, val
):
113 self
._data
["database_hash1"] = val
115 database_hash1
= property(get_database_hash1
, set_database_hash1
)
117 def get_database_compression(self
):
118 return self
._data
.get("database_compression", None)
120 def set_database_compression(self
, val
):
121 self
._data
["database_compression"] = val
123 database_compression
= property(get_database_compression
,
124 set_database_compression
)