示例#1
0
文件: utils.py 项目: Abioy/fabric
def indent(text, spaces=4, strip=False):
    """
    Return ``text`` indented by the given number of spaces.

    If text is not a string, it is assumed to be a list of lines and will be
    joined by ``\\n`` prior to indenting.

    When ``strip`` is ``True``, a minimum amount of whitespace is removed from
    the left-hand side of the given string (so that relative indents are
    preserved, but otherwise things are left-stripped). This allows you to
    effectively "normalize" any previous indentation for some inputs.
    """
    # Normalize list of strings into a string for dedenting. "list" here means
    # "not a string" meaning "doesn't have splitlines". Meh.
    if not hasattr(text, 'splitlines'):
        text = '\n'.join(text)
    # Dedent if requested
    if strip:
        text = textwrap.dedent(text)
    prefix = ' ' * spaces
    output = '\n'.join(prefix + line for line in text.splitlines())
    # Strip out empty lines before/aft
    output = output.strip()
    # Reintroduce first indent (which just got stripped out)
    output = prefix + output
    return output
示例#2
0
def indent(text, spaces=4, strip=False):
    """
    Return ``text`` indented by the given number of spaces.

    If text is not a string, it is assumed to be a list of lines and will be
    joined by ``\\n`` prior to indenting.

    When ``strip`` is ``True``, a minimum amount of whitespace is removed from
    the left-hand side of the given string (so that relative indents are
    preserved, but otherwise things are left-stripped). This allows you to
    effectively "normalize" any previous indentation for some inputs.
    """
    # Normalize list of strings into a string for dedenting. "list" here means
    # "not a string" meaning "doesn't have splitlines". Meh.
    if not hasattr(text, 'splitlines'):
        text = '\n'.join(text)
    # Dedent if requested
    if strip:
        text = textwrap.dedent(text)
    prefix = ' ' * spaces
    output = '\n'.join(prefix + line for line in text.splitlines())
    # Strip out empty lines before/aft
    output = output.strip()
    # Reintroduce first indent (which just got stripped out)
    output = prefix + output
    return output
示例#3
0
                ))
            #os.spawnl(os.P_WAIT, sys.executable, zc.buildout.easy_install._safe_arg (sys.executable), tsetup,
            #          *[zc.buildout.easy_install._safe_arg(a)
            #            for a in args])
            # We need '-u' to ensure we get unbuffered python so strange things don't happen
            args = [zc.buildout.easy_install._safe_arg (sys.executable), '-u',
                    tsetup]+ \
                    [zc.buildout.easy_install._safe_arg(a) for a in args]
            output = subprocess.check_output(args,stderr=subprocess.STDOUT, close_fds=True)
        except subprocess.CalledProcessError, e:
            raise

        finally:
            os.close(fd)
            os.remove(tsetup)
        return output.strip().split('\n')


def main(cfgfile, args):
    "execute the fabfile we generated"

    parser = OptionParser()
    parser.add_option("-c", "--configuration", dest="cfgfile", default=cfgfile,
                      help="hostout configuration file", metavar="FILE")

    (options, args) = parser.parse_args()
    cfgfile = options.cfgfile.strip()

    config = ConfigParser.ConfigParser()
    config.optionxform = str
    config.read([cfgfile])
示例#4
0
            )
            # os.spawnl(os.P_WAIT, sys.executable, zc.buildout.easy_install._safe_arg (sys.executable), tsetup,
            #          *[zc.buildout.easy_install._safe_arg(a)
            #            for a in args])
            # We need '-u' to ensure we get unbuffered python so strange things don't happen
            args = [zc.buildout.easy_install._safe_arg(sys.executable), "-u", tsetup] + [
                zc.buildout.easy_install._safe_arg(a) for a in args
            ]
            output = subprocess.check_output(args, stderr=subprocess.STDOUT, close_fds=True)
        except subprocess.CalledProcessError, e:
            raise

        finally:
            os.close(fd)
            os.remove(tsetup)
        return output.strip().split("\n")


def main(cfgfile, args):
    "execute the fabfile we generated"

    parser = OptionParser()
    parser.add_option(
        "-c", "--configuration", dest="cfgfile", default=cfgfile, help="hostout configuration file", metavar="FILE"
    )

    (options, args) = parser.parse_args()
    cfgfile = options.cfgfile.strip()

    config = ConfigParser.ConfigParser()
    config.optionxform = str