X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxrn.py;h=b0db4c1de5ef10df0e1d130c0e6ba4b437d389d5;hb=4d697c967d8f3e0f398cfe3c209f6bcaadc79b11;hp=38656a7006651736debe096b6bc3a9a5a1140fb9;hpb=5ef8d766d0dea92ee77463b91a4a82b08131ce6c;p=sfa.git diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index 38656a70..b0db4c1d 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -109,6 +109,18 @@ class Xrn: def urn_split (urn): return Xrn.urn_meaningful(urn).split('+') + @staticmethod + def filter_type(urns=[], type=None): + 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,17 +128,15 @@ 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 if Xrn.is_urn(xrn): self.hrn=None self.urn=xrn - if type: - self.type=type if id: - self.urn = "%s-%s" % (self.urn, str(id)) + self.urn = "%s:%s" % (self.urn, str(id)) self.urn_to_hrn() else: self.urn=None @@ -175,10 +185,23 @@ class Xrn: update the authority section of an existing urn """ authority_hrn = self.get_authority_hrn() - hrn = ".".join([authority, self.get_leaf()]) + 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): """