예제 #1
0
 def load_credential_file(self, path):
     """Load a credential file as is setup like the Java utilities"""
     c_data = StringIO()
     c_data.write("[Credentials]\n")
     for line in open(path, "r").readlines():
         c_data.write(
             line.replace("AWSAccessKeyId", "aws_access_key_id").replace(
                 "AWSSecretKey", "aws_secret_access_key"))
     c_data.seek(0)
     self.readfp(c_data)
예제 #2
0
class ShellCommand(object):

    def __init__(self, command, wait=True, fail_fast=False, cwd=None):
        self.exit_code = 0
        self.command = command
        self.log_fp = StringIO()
        self.wait = wait
        self.fail_fast = fail_fast
        self.run(cwd=cwd)

    def run(self, cwd=None):
        mssapi.log.info('running:%s' % self.command)
        self.process = subprocess.Popen(self.command, shell=True,
                                        stdin=subprocess.PIPE,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        cwd=cwd)
        if(self.wait):
            while self.process.poll() is None:
                time.sleep(1)
                t = self.process.communicate()
                self.log_fp.write(t[0])
                self.log_fp.write(t[1])
            mssapi.log.info(self.log_fp.getvalue())
            self.exit_code = self.process.returncode

            if self.fail_fast and self.exit_code != 0:
                raise Exception("Command " + self.command +
                                " failed with status " + self.exit_code)

            return self.exit_code

    def setReadOnly(self, value):
        raise AttributeError

    def getStatus(self):
        return self.exit_code

    status = property(getStatus, setReadOnly, None,
                      'The exit code for the command')

    def getOutput(self):
        return self.log_fp.getvalue()

    output = property(getOutput, setReadOnly, None,
                      'The STDIN and STDERR output of the command')
예제 #3
0
class ShellCommand(object):
    def __init__(self, command, wait=True, fail_fast=False, cwd=None):
        self.exit_code = 0
        self.command = command
        self.log_fp = StringIO()
        self.wait = wait
        self.fail_fast = fail_fast
        self.run(cwd=cwd)

    def run(self, cwd=None):
        mssapi.log.info('running:%s' % self.command)
        self.process = subprocess.Popen(self.command,
                                        shell=True,
                                        stdin=subprocess.PIPE,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        cwd=cwd)
        if (self.wait):
            while self.process.poll() is None:
                time.sleep(1)
                t = self.process.communicate()
                self.log_fp.write(t[0])
                self.log_fp.write(t[1])
            mssapi.log.info(self.log_fp.getvalue())
            self.exit_code = self.process.returncode

            if self.fail_fast and self.exit_code != 0:
                raise Exception("Command " + self.command +
                                " failed with status " + self.exit_code)

            return self.exit_code

    def setReadOnly(self, value):
        raise AttributeError

    def getStatus(self):
        return self.exit_code

    status = property(getStatus, setReadOnly, None,
                      'The exit code for the command')

    def getOutput(self):
        return self.log_fp.getvalue()

    output = property(getOutput, setReadOnly, None,
                      'The STDIN and STDERR output of the command')
예제 #4
0
 def dump_safe(self, fp=None):
     if not fp:
         fp = StringIO()
     for section in self.sections():
         fp.write('[%s]\n' % section)
         for option in self.options(section):
             if option == 'aws_secret_access_key':
                 fp.write('%s = xxxxxxxxxxxxxxxxxx\n' % option)
             else:
                 fp.write('%s = %s\n' % (option, self.get(section, option)))