Misc s/func/certmaster/ replacements
[certmaster.git] / certmaster / minion / modules / command.py
1 # Copyright 2007, Red Hat, Inc
2 # James Bowes <jbowes@redhat.com>
3 # Steve 'Ashcrow' Milner <smilner@redhat.com>
4 #
5 # This software may be freely redistributed under the terms of the GNU
6 # general public license.
7 #
8 # You should have received a copy of the GNU General Public License
9 # along with this program; if not, write to the Free Software
10 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
11
12 """
13 Abitrary command execution module for func.
14 """
15
16 import func_module
17 import sub_process
18
19 class Command(func_module.FuncModule):
20
21 version = "0.0.1"
22 api_version = "0.0.1"
23 description = "Works with shell commands."
24
25 def run(self, command):
26 """
27 Runs a command, returning the return code, stdout, and stderr as a tuple.
28 NOT FOR USE WITH INTERACTIVE COMMANDS.
29 """
30
31 cmdref = sub_process.Popen(command.split(), stdout=sub_process.PIPE,
32 stderr=sub_process.PIPE, shell=False)
33 data = cmdref.communicate()
34 return (cmdref.returncode, data[0], data[1])
35
36 def exists(self, command):
37 """
38 Checks to see if a command exists on the target system(s).
39 """
40 import os
41
42 if os.access(command, os.X_OK):
43 return True
44 return False