remove use of very old file() function that is no longer available
[plcapi.git] / db-config.d / 002-system_site
index ced75a7..1564694 100644 (file)
@@ -1,7 +1,5 @@
 # -*-python-*-
-# $Id$
-# $URL$
-#################### 
+####################
 # Create/update and populate the default site (should be site_id 1)
 
 ### plc_www holds the contents of the PLC_WWW configuration category
@@ -36,22 +34,21 @@ site_id = sites[0]['site_id']
 UpdateSite(site_id, site)
 
 # The default administrator account must be associated with a site
-# in order to login.
-AddPersonToSite(admin['person_id'], site['site_id'])
-SetPersonPrimarySite(admin['person_id'], site['site_id'])
+# in order to login - see 001-admin_user
+AddPersonToSite(the_admin_id, site['site_id'])
+SetPersonPrimarySite(the_admin_id, site['site_id'])
 
 # Grant admin and PI roles to the default administrator account
-AddRoleToPerson(10, admin['person_id'])
-AddRoleToPerson(20, admin['person_id'])
+AddRoleToPerson(10, the_admin_id)
+AddRoleToPerson(20, the_admin_id)
 
 # Associate root ssh key with the default administrator
 keyfile=plc['root_ssh_key_pub']
-person = GetPersons(admin['person_id'])[0]
+person = GetPersons(the_admin_id)[0]
 keys = GetKeys(person['key_ids'])
 if os.path.exists(keyfile):
-    sshkeyfp = file(keyfile,"r")
-    sshkey = sshkeyfp.read()
-    sshkeyfp.close()
+    with open(keyfile) as feed:
+        sshkey = feed.read()
 
     found=False
     for key in keys:
@@ -62,7 +59,7 @@ if os.path.exists(keyfile):
                 # should we delete other keys?
                 pass
     if not found:
-        key_id = AddPersonKey(admin['person_id'],{'key_type':'ssh','key':sshkey})
+        key_id = AddPersonKey(the_admin_id,{'key_type':'ssh','key':sshkey})
 else:
     if len(keys)==0:
         print "WARNING: default administrator does not have an ssh key"