a little nicer wrt pep8
[sfa.git] / tools / reset_gids.py
index e30ed32..78dece7 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding:utf-8 -*-
 
 from sfa.storage.model import *
@@ -8,8 +8,9 @@ from sfa.trust.hierarchy import Hierarchy
 from sfa.util.xrn import Xrn
 from sfa.trust.certificate import Certificate, Keypair, convert_public_key
 
+
 def fix_users():
-    s=global_dbsession
+    s = global_dbsession
     hierarchy = Hierarchy()
     users = s.query(RegRecord).filter_by(type="user")
     for record in users:
@@ -17,15 +18,16 @@ def fix_users():
         if not record.gid:
             uuid = create_uuid()
             pkey = Keypair(create=True)
-            pub_key=getattr(record,'reg_keys',None)
+            pub_key = getattr(record, 'reg_keys', None)
             if len(pub_key) > 0:
                 # use only first key in record
-                if pub_key and isinstance(pub_key, list): pub_key = pub_key[0]
+                if pub_key and isinstance(pub_key, list):
+                    pub_key = pub_key[0]
                 pub_key = pub_key.key
                 pkey = convert_public_key(pub_key)
-            urn = Xrn (xrn=record.hrn, type='user').get_urn()
-            email=getattr(record,'email',None)
-            gid_object = hierarchy.create_gid(urn, uuid, pkey, email = email)
+            urn = Xrn(xrn=record.hrn, type='user').get_urn()
+            email = getattr(record, 'email', None)
+            gid_object = hierarchy.create_gid(urn, uuid, pkey, email=email)
             gid = gid_object.save_to_string(save_parents=True)
             record.gid = gid
     s.commit()