def test_versions_and_sources_last(self):
        cfg = self.given_a_file_in_test_dir('buildout.cfg', '''\
[buildout]
[versions]
[sources]
[www]
[zzz]
[aaa]''')
        output = StringIO()
        sort(open(cfg), output)
        output.seek(0)

        expected = '''\
[buildout]

[aaa]

[www]

[zzz]

[sources]

[versions]
'''

        self.assertEqual(expected, output.read())
Exemple #2
0
def normalize_cmd():
    parser = ArgumentParser()
    parser.add_argument(
        '-C',
        '--check',
        dest='check',
        action='store_true',
        default=False,
        help=('Do not modify buildout file, '
              'only return if file would be modified'))
    parser.add_argument('configfiles',
                        nargs='*',
                        help=('The configfile to normalize in place, '
                              'or "-" to read the config file from stdin '
                              'and return the result to stdout'))
    args = parser.parse_args()

    if not len(args.configfiles):
        logger.exception('You must choose config files to normalize ',
                         'I won\'t guess them for you!')
        sys.exit(3)

    outstreams = {}

    for configfile in args.configfiles:
        if len(args.configfiles) == 1 and configfile == '-':
            instream = StringIO()
            instream.write(sys.stdin.read())
            instream.seek(0)
            pipe = True
        else:
            instream = open(configfile, encoding='utf-8')
            pipe = False
        outstream = StringIO()
        outstreams[configfile] = outstream
        try:
            sort(instream, outstream)
        except Exception:
            logger.exception('Could not parse file %r', configfile)
            return sys.exit(3)
        else:
            instream.seek(0)
            outstream.seek(0)
            changed = instream.read() != outstream.read()
            outstream.seek(0)
            if not changed:
                if pipe:
                    sys.stdout.write(outstream.read())
                    sys.exit(0)
            else:
                if args.check:
                    logger.error('File is not normalized')
                    sys.exit(3)
                else:
                    if pipe:
                        sys.stdout.write(outstream.read())
    if not pipe:
        for outfile, outstream in outstreams.items():
            open(outfile, 'w', encoding='utf-8').write(outstream.read())
    def test_regression1(self):
        cfg = self.given_a_file_in_test_dir('buildout.cfg', '''
[sources]
# xxx
# yyy
a = git http...''')
        output = StringIO()

        sort(open(cfg), output)
        output.seek(0)

        expected = '''[sources]
# xxx
# yyy
a = git http...
'''

        self.assertEqual(expected, output.read())
    def test_regression3(self):
        cfg = self.given_a_file_in_test_dir('buildout.cfg', '''
[filter]
extra-field-types =
 <charFilter class="solr.PatternReplaceCharFilterFactory" pattern="(/)+$" replacement=""/>
''')  # NOQA
        output = StringIO()

        sort(open(cfg), output)
        output.seek(0)

        expected = '''\
[filter]
extra-field-types =
 <charFilter class="solr.PatternReplaceCharFilterFactory" pattern="(/)+$" replacement=""/>
'''  # NOQA

        self.assertEqual(expected, output.read())
    def test_mrdev_options_grouped(self):
        cfg = self.given_a_file_in_test_dir('buildout.cfg', '''\
[buildout]
sources = sources
bla = 1
auto-checkout = *''')
        output = StringIO()

        sort(open(cfg), output)
        output.seek(0)

        expected = '''[buildout]
bla = 1

auto-checkout = *
sources = sources
'''

        self.assertEqual(expected, output.read())
    def test_good_case(self):
        cfg = self.given_a_file_in_test_dir('buildout.cfg', '''\
[buildout]
[bla]
a=1
recipe=xxx
# comment
bla=1
[versions]
a=1
[sources]
xxx = git http:aaa branch=xxx
yyy = git xfdsfdsfsdfsdfdsfdsfsdfdsfsdfdsf branch=yyy
''')
        output = StringIO()

        sort(open(cfg), output)
        output.seek(0)

        expected = '''[buildout]

[bla]
recipe=xxx
a=1
# comment
bla=1

[sources]
xxx = git http:aaa                         branch=xxx
yyy = git xfdsfdsfsdfsdfdsfdsfsdfdsfsdfdsf branch=yyy

[versions]
a=1
'''

        self.assertEqual(expected, output.read())
Exemple #7
0
    if not pipe:
        for outfile, outstream in outstreams.items():
            open(outfile, 'w', encoding='utf-8').write(outstream.read())


def version_info_cmd():
    parser = ArgumentParser(
        description='Print info about pinned versions and its overrides'
    )
    parser.add_argument('configfile',
                        help=('config file to parse'))

    args = parser.parse_args()
    sys.stdout.write(get_version_info(args.configfile).read())


def freeze_cmd():
    parser = ArgumentParser(
        description=('Download external buildout resources.\n'
                     'On second invocation, download them again, if '
                     'necessary.')
    )
    parser.add_argument('configfile',
                        help=('The configfile to start freezing from.\n'
                              'All resources get checked recursively.'))
    args = parser.parse_args()
    sys.stdout.write(freeze(args))

if __name__ == '__main__':
    sys.exit(sort(fileinput.input()))