X-Git-Url: http://git.onelab.eu/?p=sface.git;a=blobdiff_plain;f=sface%2Fsfidata.py;h=1a326c686876a0ec5c48472551ec759d58bbb5be;hp=4f2749ee3cfc7837a788277737f0c768272c85df;hb=c359089db117441b09eba6b6a05313f17bc1ac61;hpb=480ff8b34640f125528b4a008c031eff8d232135 diff --git a/sface/sfidata.py b/sface/sfidata.py index 4f2749e..1a326c6 100644 --- a/sface/sfidata.py +++ b/sface/sfidata.py @@ -1,3 +1,4 @@ +import json import os import pickle from PyQt4.QtCore import * @@ -5,7 +6,6 @@ from PyQt4.QtGui import * from lxml import etree from sfa.util.xrn import hrn_to_urn, urn_to_hrn -from sfa.storage.record import SfaRecord, SliceRecord, AuthorityRecord, UserRecord from sfa.rspecs.rspec import RSpec from sface.config import config @@ -31,19 +31,33 @@ class SfiData: def getSliceRecord(self): rec_file = config.getSliceRecordFile() if os.path.exists(rec_file): - xml = open(rec_file).read() - rec = SliceRecord() - rec.load_from_string(xml) - return rec + try: + from sfa.storage.record import SliceRecord + xml = open(rec_file).read() + rec = SliceRecord() + rec.load_from_string(xml) + return rec + except: + from sfa.storage.model import make_record + obj=make_record (xml=file(rec_file).read()) + # consider as a dict for smooth transition + return obj.__dict__ return None def getUserRecord(self): rec_file = config.getUserRecordFile() if os.path.exists(rec_file): - xml = open(rec_file).read() - rec = UserRecord() - rec.load_from_string(xml) - return rec + try: + from sfa.storage.record import SliceUser + xml = open(rec_file).read() + rec = UserRecord() + rec.load_from_string(xml) + return rec + except: + from sfa.storage.model import make_record + obj=make_record (xml=file(rec_file).read()) + # consider as a dict for smooth transition + return obj.__dict__ return None def getUserSliceHrns(self): @@ -80,9 +94,11 @@ class SfiData: rspec_file = config.getSliceRSpecFile() if os.path.exists(rspec_file): xml = open(rspec_file).read() - rspec = RSpec(rspec=xml) #rspec = parse_rspec(xml) - #self.purgeNonSliceResources(rspec) + if (xml.strip()==""): + return None + + rspec = RSpec(rspec=xml) return rspec return None @@ -91,7 +107,11 @@ class SfiData: rspec_file = config.getResourcesRSpecFile() if os.path.exists(rspec_file): xml = open(rspec_file).read() - rspec = RSpec(rspec=xml) #rspec= parse_rspec(xml) + + if (xml.strip()==""): + return None + + rspec = RSpec(rspec=xml) return rspec return None @@ -99,11 +119,21 @@ class SfiData: if not slice: slice = config.getSlice() + if not slice: + return None + filename = config.fullpath(slice+".sliverstatus") if os.path.exists(filename): data = open(filename).read() - return pickle.loads(data) + try: + if hasattr(json, "loads"): + return json.loads(data) # python 2.6 + else: + return json.read(data) # python 2.5 + except: + print "Exception in getSliverStatus" + return None return None