Added hashes to the database
This commit is contained in:
parent
1da56e5290
commit
55f68bb2b0
1 changed files with 19 additions and 12 deletions
|
@ -48,11 +48,15 @@ def __init__(self,file_name="specDB.yaml"):
|
||||||
"""
|
"""
|
||||||
Create an empty Database
|
Create an empty Database
|
||||||
Location defaults to root/specDB.yaml
|
Location defaults to root/specDB.yaml
|
||||||
|
The individual data are dicts containing
|
||||||
|
spec: the top level spec of a package
|
||||||
|
path: the path to the install of that package
|
||||||
|
dep_hash: a hash of the dependence DAG for that package
|
||||||
"""
|
"""
|
||||||
self.file_name = file_name
|
self.file_name = file_name
|
||||||
self.data = []
|
self.data = []
|
||||||
|
|
||||||
|
|
||||||
def from_yaml(self,stream):
|
def from_yaml(self,stream):
|
||||||
"""
|
"""
|
||||||
Fill database from YAML
|
Fill database from YAML
|
||||||
|
@ -69,10 +73,11 @@ def from_yaml(self,stream):
|
||||||
for sp in file['database']:
|
for sp in file['database']:
|
||||||
spec = Spec.from_node_dict(sp['spec'])
|
spec = Spec.from_node_dict(sp['spec'])
|
||||||
path = sp['path']
|
path = sp['path']
|
||||||
db_entry = {'spec': spec, 'path': path}
|
dep_hash = sp['hash']
|
||||||
|
db_entry = {'spec': spec, 'path': path, 'hash':dep_hash}
|
||||||
self.data.append(db_entry)
|
self.data.append(db_entry)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_database(root):
|
def read_database(root):
|
||||||
"""Create a Database from the data in the standard location"""
|
"""Create a Database from the data in the standard location"""
|
||||||
|
@ -87,7 +92,7 @@ def read_database(root):
|
||||||
|
|
||||||
return database
|
return database
|
||||||
|
|
||||||
|
|
||||||
def write_database_to_yaml(self,stream):
|
def write_database_to_yaml(self,stream):
|
||||||
"""
|
"""
|
||||||
Replace each spec with its dict-node form
|
Replace each spec with its dict-node form
|
||||||
|
@ -97,7 +102,8 @@ def write_database_to_yaml(self,stream):
|
||||||
for sp in self.data:
|
for sp in self.data:
|
||||||
node = {}
|
node = {}
|
||||||
node['spec']=Spec.to_node_dict(sp['spec'])
|
node['spec']=Spec.to_node_dict(sp['spec'])
|
||||||
node['spec'][sp['spec'].name]['hash']=sp['spec'].dag_hash()
|
# node['spec'][sp['spec'].name]['hash']=sp['spec'].dag_hash()
|
||||||
|
node['hash']=sp['hash']
|
||||||
node['path']=sp['path']
|
node['path']=sp['path']
|
||||||
node_list.append(node)
|
node_list.append(node)
|
||||||
return yaml.dump({ 'database' : node_list},
|
return yaml.dump({ 'database' : node_list},
|
||||||
|
@ -121,13 +127,14 @@ def add(root, spec, path):
|
||||||
TODO: Caching databases
|
TODO: Caching databases
|
||||||
"""
|
"""
|
||||||
database = Database.read_database(root)
|
database = Database.read_database(root)
|
||||||
|
|
||||||
spec_and_path = {}
|
sph = {}
|
||||||
spec_and_path['spec']=spec
|
sph['spec']=spec
|
||||||
spec_and_path['path']=path
|
sph['path']=path
|
||||||
|
sph['hash']=spec.dag_hash()
|
||||||
database.data.append(spec_and_path)
|
|
||||||
|
database.data.append(sph)
|
||||||
|
|
||||||
database.write(root)
|
database.write(root)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue