aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStevan Radaković <stevan.radakovic@linaro.org>2013-03-27 18:04:47 +0100
committerStevan Radaković <stevan.radakovic@linaro.org>2013-03-27 18:04:47 +0100
commit46ce2541c4dee8e40b53ad5c99749f3039c85f8e (patch)
tree9674dbba7259ca0c302429cfb331bdf5388d3819
parente06e946525e259b9aa1a117344438b7f2c92eab5 (diff)
Change SystemCommand class location.
-rw-r--r--rhodecode/lib/helpers.py67
-rw-r--r--rhodecode/lib/system_command.py73
-rw-r--r--rhodecode/model/repo.py1
-rw-r--r--rhodecode/model/repos_group.py2
4 files changed, 75 insertions, 68 deletions
diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py
index 0852f44a..2183ae69 100644
--- a/rhodecode/lib/helpers.py
+++ b/rhodecode/lib/helpers.py
@@ -1170,70 +1170,3 @@ def ip_range(ip_addr):
from rhodecode.model.db import UserIpMap
s, e = UserIpMap._get_ip_range(ip_addr)
return '%s - %s' % (s, e)
-
-
-class SystemCommand():
-
- @classmethod
- def execute(cls, cmd_args, with_sudo=True):
- """Runs the command passed."""
- if not isinstance(cmd_args, list):
- cmd_args = list(cmd_args)
- if with_sudo:
- cmd_args.insert(0, "sudo")
-
- with open(os.devnull, 'w') as tempf:
- process = subprocess.Popen(cmd_args, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- (stdout, stderr) = process.communicate()
-
- if process.returncode != 0:
- log.warn("Error executing command: '%s'. Reason: %s." %
- (" ".join(cmd_args), stderr))
- else:
- log.debug("Sucess executing command %s. Output: %s" % (cmd_args,
- stdout))
-
- return stdout
-
- @classmethod
- def add_group(cls, groupname):
- cmd_args = ["groupadd", groupname]
- cls.execute(cmd_args)
-
- @classmethod
- def rename_group(cls, groupname, newgroupname):
- cmd_args = ["groupmod", "-n", newgroupname, groupname]
- cls.execute(cmd_args)
-
- @classmethod
- def delete_group(cls, groupname):
- cmd_args = ["groupdel", groupname]
- cls.execute(cmd_args)
-
- @classmethod
- def add_user(cls, username):
- cmd_args = ["adduser", "--disabled-password", "--force-badname",
- "--quiet", "--gecos", "''", username]
- cls.execute(cmd_args)
-
- @classmethod
- def add_user_to_group(cls, groupname, username):
- cmd_args = ["gpasswd", "-a", username, groupname]
- cls.execute(cmd_args)
-
- @classmethod
- def remove_user_from_group(cls, groupname, username):
- cmd_args = ["gpasswd", "-d", username, groupname]
- cls.execute(cmd_args)
-
- @classmethod
- def get_group_members(cls, groupname):
- cmd_args = ["members", "--all", groupname]
- try:
- output = cls.execute(cmd_args)
- users = set(output.split())
- return users
- except:
- return {}
-
diff --git a/rhodecode/lib/system_command.py b/rhodecode/lib/system_command.py
new file mode 100644
index 00000000..daa62123
--- /dev/null
+++ b/rhodecode/lib/system_command.py
@@ -0,0 +1,73 @@
+import logging
+import os
+import subprocess
+
+
+log = logging.getLogger(__name__)
+
+
+class SystemCommand():
+
+ @classmethod
+ def execute(cls, cmd_args, with_sudo=True):
+ """Runs the command passed."""
+ if not isinstance(cmd_args, list):
+ cmd_args = list(cmd_args)
+ if with_sudo:
+ cmd_args.insert(0, "sudo")
+
+ with open(os.devnull, 'w') as tempf:
+ process = subprocess.Popen(cmd_args, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ (stdout, stderr) = process.communicate()
+
+ if process.returncode != 0:
+ log.warn("Error executing command: '%s'. Reason: %s." %
+ (" ".join(cmd_args), stderr))
+ else:
+ log.debug("Sucess executing command %s. Output: %s" % (cmd_args,
+ stdout))
+
+ return stdout
+
+ @classmethod
+ def add_group(cls, groupname):
+ cmd_args = ["groupadd", groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def rename_group(cls, groupname, newgroupname):
+ cmd_args = ["groupmod", "-n", newgroupname, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def delete_group(cls, groupname):
+ cmd_args = ["groupdel", groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def add_user(cls, username):
+ cmd_args = ["adduser", "--disabled-password", "--force-badname",
+ "--quiet", "--gecos", "''", username]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def add_user_to_group(cls, groupname, username):
+ cmd_args = ["gpasswd", "-a", username, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def remove_user_from_group(cls, groupname, username):
+ cmd_args = ["gpasswd", "-d", username, groupname]
+ cls.execute(cmd_args)
+
+ @classmethod
+ def get_group_members(cls, groupname):
+ cmd_args = ["members", "--all", groupname]
+ try:
+ output = cls.execute(cmd_args)
+ users = set(output.split())
+ return users
+ except:
+ return {}
+
diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py
index b18110c1..17bd5379 100644
--- a/rhodecode/model/repo.py
+++ b/rhodecode/model/repo.py
@@ -35,6 +35,7 @@ from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode,\
remove_prefix
from rhodecode.lib.caching_query import FromCache
from rhodecode.lib.hooks import log_create_repository, log_delete_repository
+from rhodecode.lib.system_command import SystemCommand
from rhodecode.model import BaseModel
from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \
diff --git a/rhodecode/model/repos_group.py b/rhodecode/model/repos_group.py
index 50617d30..12208273 100644
--- a/rhodecode/model/repos_group.py
+++ b/rhodecode/model/repos_group.py
@@ -30,7 +30,7 @@ import shutil
import datetime
from rhodecode.lib.utils2 import LazyProperty
-from rhodecode.lib.helpers import SystemCommand
+from rhodecode.lib.system_command import SystemCommand
from rhodecode.model import BaseModel
from rhodecode.model.db import RepoGroup, RhodeCodeUi, UserRepoGroupToPerm, \