Author: adc Date: Sat Jul 19 04:02:06 2014 New Revision: 1611843 URL: http://svn.apache.org/r1611843 Log: execute() takes a sequence instead of a string.
Modified: labs/panopticon/pan-utils/src/asf/utils/execute.py labs/panopticon/pan-utils/src/asf/utils/ezmlm.py labs/panopticon/pan-utils/tests/test_execute.py Modified: labs/panopticon/pan-utils/src/asf/utils/execute.py URL: http://svn.apache.org/viewvc/labs/panopticon/pan-utils/src/asf/utils/execute.py?rev=1611843&r1=1611842&r2=1611843&view=diff ============================================================================== --- labs/panopticon/pan-utils/src/asf/utils/execute.py (original) +++ labs/panopticon/pan-utils/src/asf/utils/execute.py Sat Jul 19 04:02:06 2014 @@ -34,13 +34,13 @@ class ExecutionError(ValueError): return self.__repr__() -def execute(command): +def execute(args): """ Executes a command and returns both stdout and stderr as lists - :param str command: the command to be executed + :param args: a sequence of program arguments. Rhe program to execute is the first item in args. :returns stdout, stderr as lists :raises ExecutionError if the command does not execute correctly. """ - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = [] for line in p.stdout.readlines(): Modified: labs/panopticon/pan-utils/src/asf/utils/ezmlm.py URL: http://svn.apache.org/viewvc/labs/panopticon/pan-utils/src/asf/utils/ezmlm.py?rev=1611843&r1=1611842&r2=1611843&view=diff ============================================================================== --- labs/panopticon/pan-utils/src/asf/utils/ezmlm.py (original) +++ labs/panopticon/pan-utils/src/asf/utils/ezmlm.py Sat Jul 19 04:02:06 2014 @@ -41,7 +41,7 @@ class Ezmlm(object): @property def subscribers(self): - stdout, _ = execute(os.path.join(self.command_location, 'ezmlm-list') + ' ' + self.list_dir) + stdout, _ = execute([os.path.join(self.command_location, 'ezmlm-list'), self.list_dir]) subscribers = set() for line in stdout: @@ -51,7 +51,7 @@ class Ezmlm(object): @property def moderators(self): - stdout, _ = execute(os.path.join(self.command_location, 'ezmlm-list') + ' ' + self.list_dir + ' mod') + stdout, _ = execute([os.path.join(self.command_location, 'ezmlm-list'), self.list_dir, 'mod']) moderators = set() for line in stdout: moderators.add(line.strip()) @@ -62,25 +62,25 @@ class Ezmlm(object): if subscriber in self.subscribers: log.warning('Subscriber %s already in list') else: - execute(os.path.join(self.command_location, 'ezmlm-sub') + ' ' + self.list_dir + ' ' + subscriber) + execute([os.path.join(self.command_location, 'ezmlm-sub'), self.list_dir, subscriber]) def remove_subscriber(self, subscriber): if subscriber not in self.subscribers: log.warning('Subscriber %s not in list') else: - execute(os.path.join(self.command_location, 'ezmlm-unsub') + ' ' + self.list_dir + ' ' + subscriber) + execute([os.path.join(self.command_location, 'ezmlm-unsub'), self.list_dir, subscriber]) def add_moderator(self, moderator): if moderator in self.moderators: log.warning('Subscriber %s already in list') else: - execute(os.path.join(self.command_location, 'ezmlm-sub') + ' ' + self.list_dir + ' mod ' + moderator) + execute([os.path.join(self.command_location, 'ezmlm-sub'), self.list_dir, 'mod', moderator]) def remove_moderator(self, moderator): if moderator not in self.moderators: log.warning('Subscriber %s not in list') else: - execute(os.path.join(self.command_location, 'ezmlm-unsub') + ' ' + self.list_dir + ' mod ' + moderator) + execute([os.path.join(self.command_location, 'ezmlm-unsub'), self.list_dir, 'mod', moderator]) def path_to_archived_message(self, number): m = str(number / 100) Modified: labs/panopticon/pan-utils/tests/test_execute.py URL: http://svn.apache.org/viewvc/labs/panopticon/pan-utils/tests/test_execute.py?rev=1611843&r1=1611842&r2=1611843&view=diff ============================================================================== --- labs/panopticon/pan-utils/tests/test_execute.py (original) +++ labs/panopticon/pan-utils/tests/test_execute.py Sat Jul 19 04:02:06 2014 @@ -23,14 +23,14 @@ from asf.utils.execute import execute, E def test_execute(): data_dir = os.path.join(os.path.dirname(__file__), 'data') - stdout, stderr = execute('ls %s' % data_dir) + stdout, stderr = execute(['ls', '%s' % data_dir]) assert ['podlings.xml', 'test.apache.org'] == stdout assert [] == stderr def test_execute_fail(): try: - execute('ls ZZZ') + execute(['ls', 'ZZZ']) assert False, 'Execution should have thrown an error' except ExecutionError as ee: assert ee.code --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@labs.apache.org For additional commands, e-mail: commits-h...@labs.apache.org