Ejemplo n.º 1
0
    def shell(self, *args, **kwargs):
        exceptions = kwargs.pop('exceptions', False)
        join = kwargs.pop('join', False)

        if kwargs:
            raise Exception('Unsupported kwargs provided to function.')

        log.debug(' '.join(args))

        if join:
            process = subprocess.Popen(args, cwd=self.path)
            process.communicate()
        else:
            process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.path)
            stdout, stderr = process.communicate()
            process.stdout = stdout and force_unicode(stdout.strip()) or u''
            process.stderr = stderr and force_unicode(stderr.strip()) or u''
            process.split = filter(lambda x: x, map(lambda x: x.strip(), process.stdout.split(u'\n')))

            if process.returncode != 0:
                message = '%s: %s: %s' % (process.returncode, process.stderr, process.stdout)
                log.debug(message)
                if exceptions:
                    raise Exception(message)

            return process
Ejemplo n.º 2
0
    def shell(self, *args, **kwargs):
        exceptions = kwargs.pop("exceptions", False)
        join = kwargs.pop("join", False)

        if kwargs:
            raise Exception("Unsupported kwargs provided to function.")

        log.debug(" ".join(args))

        if join:
            process = subprocess.Popen(args, cwd=self.path)
            process.communicate()
        else:
            process = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self.path)
            stdout, stderr = process.communicate()
            process.stdout = stdout and force_unicode(stdout.strip()) or u""
            process.stderr = stderr and force_unicode(stderr.strip()) or u""
            process.split = filter(lambda x: x, map(lambda x: x.strip(), process.stdout.split(u"\n")))

            if process.returncode != 0:
                message = "%s: %s: %s" % (process.returncode, process.stderr, process.stdout)
                log.debug(message)
                if exceptions:
                    raise Exception(message)

            return process
Ejemplo n.º 3
0
 def __init__(self, value, color=None, background=None, reverse=False, width=None, align='left', resizable=False):
     self.value = force_unicode(value)
     self.color = color
     self.align = align
     self.resizable = resizable
     self.background = background
     self.attrs = reverse and ['reverse'] or []
     self.width = width and int(width) or len(self.value)
Ejemplo n.º 4
0
    def git(self, *args, **kwargs):
        split = kwargs.pop('split', False)
        join = kwargs.pop('join', False)

        command = ['git'] + list(args)

        log.debug(' '.join(command))

        if join:
            p = subprocess.Popen(command)
            p.communicate()
        else:
            p = subprocess.Popen(command, stdout=subprocess.PIPE)
            (stdout, stderr) = p.communicate(None)
            stdout = force_unicode(stdout)
            stderr = force_unicode(stderr)
            if split:
                stdout = filter(lambda x: x, map(lambda x: x.strip(), stdout.split(u'\n')))
            return stdout
Ejemplo n.º 5
0
 def __init__(self,
              value,
              color=None,
              background=None,
              reverse=False,
              width=None,
              align='left',
              resizable=False):
     self.value = force_unicode(value)
     self.color = color
     self.align = align
     self.resizable = resizable
     self.background = background
     self.attrs = reverse and ['reverse'] or []
     self.width = width and int(width) or len(self.value)
Ejemplo n.º 6
0
 def uncapture_stdout(self):
     sys.__stdout__.write(''.ljust(self.max_length))
     sys.__stdout__.write('\r')
     sys.stdout = self._stdout
     console(force_unicode(self._capture_stdout.getvalue()))
     self._capture_stdout = StringIO.StringIO()
Ejemplo n.º 7
0
 def uncapture_stdout(self):
     sys.__stdout__.write(''.ljust(self.max_length))
     sys.__stdout__.write('\r')
     sys.stdout = self._stdout
     console(force_unicode(self._capture_stdout.getvalue()))
     self._capture_stdout = StringIO.StringIO()
Ejemplo n.º 8
0
 def __init__(self, value, color=None, background=None, reverse=False):
     self.value = force_unicode(value)
     self.color = color
     self.background = background
     self.attrs = reverse and ["reverse"] or []
     self.width = len(self.value)