[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fedora-directory-commits
Subject:    =?utf-8?q?=5B389-commits=5D?= [389-ds-base] branch 389-ds-base-1.4.1 updated: Issue 50337 - Replace 
From:       pagure () pagure ! io
Date:       2020-03-27 14:37:24
Message-ID: 20200327143724.30468.42197 () pagure01 ! fedoraproject ! org
[Download RAW message or body]

This is an automated email from the git hooks/post-receive script.

spichugi pushed a commit to branch 389-ds-base-1.4.1
in repository 389-ds-base.

The following commit(s) were added to refs/heads/389-ds-base-1.4.1 by this push:
     new cd65f37  Issue 50337 - Replace exec() with setattr()
cd65f37 is described below

commit cd65f376cb1eb1f3e0c4d60948d3887dd8cb2ef6
Author: Simon Pichugin <spichugi@redhat.com>
AuthorDate: Fri Mar 27 14:00:06 2020 +0100

    Issue 50337 - Replace exec() with setattr()
    
    Description: _constants.py uses exec() a lot to define module
    global variables. That's rather slow and not very elegant.
    
    Get the current module object with sys.modules[__name__] and
    then use setattr() instead.
    
    https://pagure.io/389-ds-base/issue/50337
    
    Reviewed by: mreynolds (Thanks!)
---
 src/lib389/lib389/_constants.py | 42 ++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/src/lib389/lib389/_constants.py b/src/lib389/lib389/_constants.py
index 1ad72b5..27cd88d 100644
--- a/src/lib389/lib389/_constants.py
+++ b/src/lib389/lib389/_constants.py
@@ -6,10 +6,14 @@
 # See LICENSE for details.
 # --- END COPYRIGHT BLOCK ---
 
+import sys
 import os
 from enum import Enum, IntEnum
 from lib389.properties import *
 
+# current module object
+mod = sys.modules[__name__]
+
 (
     MASTER_TYPE,
     HUB_TYPE,
@@ -285,11 +289,11 @@ number_of_instances = 99
 # Standalone topology
 for i in range(port_start, port_start + number_of_instances):
     N+=1
-    exec("HOST_STANDALONE{0} = {1}".format(N, "LOCALHOST"))
-    exec("PORT_STANDALONE{0} = {1}".format(N, i))
-    exec("SECUREPORT_STANDALONE{0} = {1}".format(N, i + 24700))
-    exec("SERVERID_STANDALONE{0} = {1}".format(N, "\"standalone{0}\"".format(N)))
-    exec("REPLICAID_STANDALONE_{0} = {1}".format(N, 65535))
+    setattr(mod, "HOST_STANDALONE{0}".format(N), "LOCALHOST")
+    setattr(mod, "PORT_STANDALONE{0}".format(N), i)
+    setattr(mod, "SECUREPORT_STANDALONE{0}".format(N), i + 24700)
+    setattr(mod, "SERVERID_STANDALONE{0}".format(N), "\"standalone{0}\"".format(N))
+    setattr(mod, "REPLICAID_STANDALONE_{0}".format(N), 65535)
 
 # For compatibility
 HOST_STANDALONE = HOST_STANDALONE1
@@ -302,32 +306,32 @@ N=0
 port_start+=100
 for i in range(port_start, port_start + number_of_instances):
     N+=1
-    exec("HOST_MASTER_{0} = {1}".format(N, "LOCALHOST"))
-    exec("PORT_MASTER_{0} = {1}".format(N, i))
-    exec("SECUREPORT_MASTER_{0} = {1}".format(N, i + 24700))
-    exec("SERVERID_MASTER_{0} = {1}".format(N, "\"master{0}\"".format(N)))
-    exec("REPLICAID_MASTER_{0} = {1}".format(N, N))
+    setattr(mod, "HOST_MASTER_{0}".format(N), "LOCALHOST")
+    setattr(mod, "PORT_MASTER_{0}".format(N), i)
+    setattr(mod, "SECUREPORT_MASTER_{0}".format(N), i + 24700)
+    setattr(mod, "SERVERID_MASTER_{0}".format(N), "\"master{0}\"".format(N))
+    setattr(mod, "REPLICAID_MASTER_{0}".format(N), N)
 
 # Replication topology - hubs
 N=0
 port_start+=100
 for i in range(port_start, port_start + number_of_instances):
     N+=1
-    exec("HOST_HUB_{0} = {1}".format(N, "LOCALHOST"))
-    exec("PORT_HUB_{0} = {1}".format(N, i))
-    exec("SECUREPORT_HUB_{0} = {1}".format(N, i + 24700))
-    exec("SERVERID_HUB_{0} = {1}".format(N, "\"hub{0}\"".format(N)))
-    exec("REPLICAID_HUB_{0} = {1}".format(N, 65535))
+    setattr(mod, "HOST_HUB_{0}".format(N), "LOCALHOST")
+    setattr(mod, "PORT_HUB_{0}".format(N), i)
+    setattr(mod, "SECUREPORT_HUB_{0}".format(N), i + 24700)
+    setattr(mod, "SERVERID_HUB_{0}".format(N), "\"hub{0}\"".format(N))
+    setattr(mod, "REPLICAID_HUB_{0}".format(N), 65535)
 
 # Replication topology - consumers
 N=0
 port_start+=100
 for i in range(port_start, port_start + number_of_instances):
     N+=1
-    exec("HOST_CONSUMER_{0} = {1}".format(N, "LOCALHOST"))
-    exec("PORT_CONSUMER_{0} = {1}".format(N, i))
-    exec("SECUREPORT_CONSUMER_{0} = {1}".format(N, i + 24700))
-    exec("SERVERID_CONSUMER_{0} = {1}".format(N, "\"consumer{0}\"".format(N)))
+    setattr(mod, "HOST_CONSUMER_{0}".format(N), "LOCALHOST")
+    setattr(mod, "PORT_CONSUMER_{0}".format(N), i)
+    setattr(mod, "SECUREPORT_CONSUMER_{0}".format(N), i + 24700)
+    setattr(mod, "SERVERID_CONSUMER_{0}".format(N), "\"consumer{0}\"".format(N))
 
 # Cleanup, we don't need to export that
 del N, port_start, number_of_instances

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
389-commits mailing list -- 389-commits@lists.fedoraproject.org
To unsubscribe send an email to 389-commits-leave@lists.fedoraproject.org
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/389-commits@lists.fedoraproject.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic