X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxrn.py;h=6198f83c7f57465cd6b22f8ed026372f07926ec7;hb=ecc85e0b923922cf7117d29b380f5284edb88f21;hp=c623cbdd1eea383c5f744f366e32125c25c7a0b4;hpb=ef50cc0f6767a8118a80be2e4f8b0001ba760b0c;p=sfa.git diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index c623cbdd..6198f83c 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -109,6 +109,19 @@ class Xrn: def urn_split (urn): return Xrn.urn_meaningful(urn).split('+') + @staticmethod + def filter_type(urns=None, type=None): + if urns is None: urns=[] + urn_list = [] + if not type: + return urns + + for urn in urns: + xrn = Xrn(xrn=urn) + if (xrn.type == type): + # Xrn is probably a urn so we can just compare types + urn_list.append(urn) + return urn_list #################### # the local fields that are kept consistent # self.urn @@ -116,7 +129,7 @@ class Xrn: # self.type # self.path # provide either urn, or (hrn + type) - def __init__ (self, xrn, type=None, id=None): + def __init__ (self, xrn="", type=None, id=None): if not xrn: xrn = "" # user has specified xrn : guess if urn or hrn self.id = id @@ -124,17 +137,13 @@ class Xrn: self.hrn=None self.urn=xrn if id: - self.urn = "%s-%s" % (self.urn, str(id)) + self.urn = "%s:%s" % (self.urn, str(id)) self.urn_to_hrn() - if type: - self.type=type - self.hrn_to_urn() else: self.urn=None self.hrn=xrn self.type=type self.hrn_to_urn() - self._normalize() # happens all the time .. # if not type: @@ -153,7 +162,7 @@ class Xrn: def get_hrn_type(self): return (self.hrn, self.type) def _normalize(self): - if self.hrn is None: raise SfaAPIError, "Xrn._normalize" + if self.hrn is None: raise SfaAPIError("Xrn._normalize") if not hasattr(self,'leaf'): self.leaf=Xrn.hrn_split(self.hrn)[-1] # self.authority keeps a list @@ -177,12 +186,23 @@ class Xrn: update the authority section of an existing urn """ authority_hrn = self.get_authority_hrn() - old_hrn_parts = Xrn.hrn_split(self.hrn) - old_hrn_parts[0] = authority - hrn = ".".join(old_hrn_list) + if not authority_hrn.startswith(authority): + hrn = ".".join([authority,authority_hrn, self.get_leaf()]) + else: + hrn = ".".join([authority_hrn, self.get_leaf()]) + self.hrn = hrn self.hrn_to_urn() self._normalize() + + # sliver_id_parts is list that contains the sliver's + # slice id and node id + def get_sliver_id_parts(self): + sliver_id_parts = [] + if self.type == 'sliver' or '-' in self.leaf: + sliver_id_parts = self.leaf.split('-') + return sliver_id_parts + def urn_to_hrn(self): """ @@ -191,7 +211,7 @@ class Xrn: # if not self.urn or not self.urn.startswith(Xrn.URN_PREFIX): if not Xrn.is_urn(self.urn): - raise SfaAPIError, "Xrn.urn_to_hrn" + raise SfaAPIError("Xrn.urn_to_hrn") parts = Xrn.urn_split(self.urn) type=parts.pop(2) @@ -229,7 +249,7 @@ class Xrn: # if not self.hrn or self.hrn.startswith(Xrn.URN_PREFIX): if Xrn.is_urn(self.hrn): - raise SfaAPIError, "Xrn.hrn_to_urn, hrn=%s"%self.hrn + raise SfaAPIError("Xrn.hrn_to_urn, hrn=%s"%self.hrn) if self.type and self.type.startswith('authority'): self.authority = Xrn.hrn_auth_list(self.hrn) @@ -246,9 +266,6 @@ class Xrn: else: self.authority = Xrn.hrn_auth_list(self.hrn) name = Xrn.hrn_leaf(self.hrn) - # separate name from id - name_parts = name.split("-") - name = name_parts[0] authority_string = self.get_authority_urn() if self.type == None: @@ -257,7 +274,7 @@ class Xrn: urn = "+".join(['',authority_string,self.type,Xrn.unescape(name)]) if hasattr(self, 'id') and self.id: - urn = "%s-%s" % (urn, self.id) + urn = "%s:%s" % (urn, self.id) self.urn = Xrn.URN_PREFIX + urn