Setting tag plcapi-5.4-2
[plcapi.git] / PLC / Namespace.py
1 #
2 # Thierry, April 2013
3
4 # This file here is the connection to the SFA code
5 # at some point in time we had duplicated this from sfa
6 # but of course both versions have entirely diverged since then
7 # in addition we really only need 2 hepler functions here, that allow to maintain 
8 # hrn for nodes and persons and that is all
9 #
10 # So in order to avoid such situations in the future, 
11 # we try to import and re-use the SFA code
12 # assumption being that if these hrn's are of importance then it makes sense to
13 # require people to have sfa-plc installed as well
14 # however we do not want this requirement to break myplc in case it is not fulfilled
15
16
17 #################### try to import from sfa
18 try:
19     from sfa.planetlab.plxrn import hostname_to_hrn
20 except:
21     hostname_to_hrn=None
22
23 try:
24     from sfa.planetlab.plxrn import email_to_hrn
25 except:
26     email_to_hrn=None
27
28 try:
29     from sfa.planetlab.plxrn import slicename_to_hrn
30 except:
31     slicename_to_hrn=None
32 #################### if not found, bring our own local version
33 import re
34 def escape(token): return re.sub(r'([^\\])\.', r'\1\.', token)
35
36 if hostname_to_hrn is None:
37     def hostname_to_hrn (auth_hrn, login_base, hostname):
38         return ".".join( [ auth_hrn, login_base, escape(hostname) ] )
39
40 if email_to_hrn is None:
41     def email_to_hrn (auth_hrn, email):
42         return '.'.join([auth_hrn,email.split('@')[0].replace(".", "_").replace("+", "_")])
43
44 if slicename_to_hrn is None:
45     def slicename_to_hrn (auth_hrn, slicename):
46         return ".".join([auth_hrn] + slicename.split("_",1))