diff options
author | Stevan Radaković <stevan.radakovic@linaro.org> | 2013-03-20 17:11:50 +0100 |
---|---|---|
committer | Stevan Radaković <stevan.radakovic@linaro.org> | 2013-03-20 17:11:50 +0100 |
commit | e13f1c04da163de99428d7367b4b4ee86b34e70b (patch) | |
tree | 77b9ad0ffe7fdc5f425a8c431f913d0361c7372b | |
parent | ba7c038a979cda38ed0497b2c7950e8023793e89 (diff) |
Fix command execute method.
-rw-r--r-- | scripts/ldap_sync.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/ldap_sync.py b/scripts/ldap_sync.py index 09a2d6a..4f7d08f 100644 --- a/scripts/ldap_sync.py +++ b/scripts/ldap_sync.py @@ -57,8 +57,7 @@ class SystemCommand(): with open(os.devnull, 'w') as tempf: process = subprocess.Popen(cmd_args, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, shell=True, - env=os.environ) + stderr=subprocess.PIPE) (stdout, stderr) = process.communicate() if process.returncode != 0: @@ -68,7 +67,7 @@ class SystemCommand(): logger.debug("Sucess executing command %s. Output: %s" % (cmd_args, stdout)) - return stdout + return stdout @classmethod def add_group(cls, groupname): @@ -93,10 +92,13 @@ class SystemCommand(): @classmethod def get_group_members(cls, groupname): - cmd_args = ["members --all %s" % groupname] - output = cls.execute(cmd_args, with_sudo=False) - users = output.split() - return users + cmd_args = ["members", "--all", groupname] + try: + output = cls.execute(cmd_args) + users = set(output.split()) + return users + except: + return {} class RhodecodeAPI(): @@ -353,6 +355,8 @@ class LdapSync(): SystemCommand.remove_user_from_group(group, system_member) # Add memberships. + logger.debug("Add memberships.") + for member in group_users: SystemCommand.add_user_to_group(group, member) |