from PLC.Namespace import email_to_hrn
from PLC.TagTypes import TagTypes
+from PLC.Logger import logger
+
class AddPersonToSite(Method):
"""
Adds the specified person to the specified site. If the person is
# Get account information
persons = Persons(self.api, [person_id_or_email])
if not persons:
- raise PLCInvalidArgument, "No such account"
+ raise PLCInvalidArgument("No such account")
person = persons[0]
if person['peer_id'] is not None:
- raise PLCInvalidArgument, "Not a local account"
+ raise PLCInvalidArgument("Not a local account")
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
if not sites:
- raise PLCInvalidArgument, "No such site"
+ raise PLCInvalidArgument("No such site")
site = sites[0]
if site['peer_id'] is not None:
- raise PLCInvalidArgument, "Not a local site"
+ raise PLCInvalidArgument("Not a local site")
if site['site_id'] not in person['site_ids']:
site.add_person(person)
try:
had_no_site= (len (person['site_ids']) == 0)
if had_no_site:
- login_base=site['login_base']
+ login_base = site['login_base']
root_auth = self.api.config.PLC_HRN_ROOT
- hrn=email_to_hrn("%s.%s"%(root_auth,login_base),person['email'])
- tagname='hrn'
+ hrn = email_to_hrn("%s.%s"%(root_auth,login_base),person['email'])
+ tagname = 'hrn'
tag_type = TagTypes(self.api,{'tagname':tagname})[0]
- person_tags=PersonTags(self.api,{'tagname':tagname,'person_id':person['person_id']})
+ person_tags = PersonTags(self.api,{'tagname':tagname,'person_id':person['person_id']})
if not person_tags:
person_tag = PersonTag(self.api)
person_tag['person_id'] = person['person_id']
person_tag = person_tags[0]
person_tag['value'] = hrn
person_tag.sync()
- except Exception,e:
- print "BEG Warning, cannot maintain person's hrn, %s"%e
- import traceback
- traceback.print_exc()
- print "END Warning, cannot maintain person's hrn, %s"%e
-
+ except Exception as e:
+ logger.exception("ERROR cannot maintain person's hrn, {}"
+ .format(person_id_or_email))
return 1