Esempio n. 1
0
    def test_check_for_collisions(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)

        tmpdirObject = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdirObject.cleanup)
        tmpdir = tmpdirObject.name

        part1 = lifecycle.load_plugin("part1", "jdk", {"source": "."})
        part1.code.installdir = tmpdir + "/install1"
        os.makedirs(part1.installdir + "/a")
        open(part1.installdir + "/a/1", mode="w").close()

        part2 = lifecycle.load_plugin("part2", "jdk", {"source": "."})
        part2.code.installdir = tmpdir + "/install2"
        os.makedirs(part2.installdir + "/a")
        with open(part2.installdir + "/1", mode="w") as f:
            f.write("1")
        open(part2.installdir + "/2", mode="w").close()
        with open(part2.installdir + "/a/2", mode="w") as f:
            f.write("a/2")

        part3 = lifecycle.load_plugin("part3", "jdk", {"source": "."})
        part3.code.installdir = tmpdir + "/install3"
        os.makedirs(part3.installdir + "/a")
        os.makedirs(part3.installdir + "/b")
        with open(part3.installdir + "/1", mode="w") as f:
            f.write("2")
        with open(part2.installdir + "/2", mode="w") as f:
            f.write("1")
        open(part3.installdir + "/a/2", mode="w").close()

        self.assertTrue(cmds._check_for_collisions([part1, part2]))
        self.assertEqual("", fake_logger.output)

        self.assertFalse(cmds._check_for_collisions([part1, part2, part3]))
        self.assertEqual(
            "Error: parts part2 and part3 have the following file paths in "
            "common which have different contents:\n"
            "  1\n"
            "  a/2\n",
            fake_logger.output,
        )
Esempio n. 2
0
    def test_check_for_collisions(self):
        fake_logger = fixtures.FakeLogger(level=logging.ERROR)
        self.useFixture(fake_logger)

        tmpdirObject = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdirObject.cleanup)
        tmpdir = tmpdirObject.name

        part1 = lifecycle.load_plugin('part1', 'jdk', {'source': '.'})
        part1.code.installdir = tmpdir + '/install1'
        os.makedirs(part1.installdir + '/a')
        open(part1.installdir + '/a/1', mode='w').close()

        part2 = lifecycle.load_plugin('part2', 'jdk', {'source': '.'})
        part2.code.installdir = tmpdir + '/install2'
        os.makedirs(part2.installdir + '/a')
        with open(part2.installdir + '/1', mode='w') as f:
            f.write('1')
        open(part2.installdir + '/2', mode='w').close()
        with open(part2.installdir + '/a/2', mode='w') as f:
            f.write('a/2')

        part3 = lifecycle.load_plugin('part3', 'jdk', {'source': '.'})
        part3.code.installdir = tmpdir + '/install3'
        os.makedirs(part3.installdir + '/a')
        os.makedirs(part3.installdir + '/b')
        with open(part3.installdir + '/1', mode='w') as f:
            f.write('2')
        with open(part2.installdir + '/2', mode='w') as f:
            f.write('1')
        open(part3.installdir + '/a/2', mode='w').close()

        self.assertTrue(cmds._check_for_collisions([part1, part2]))
        self.assertEqual('', fake_logger.output)

        self.assertFalse(cmds._check_for_collisions([part1, part2, part3]))
        self.assertEqual(
            'Error: parts part2 and part3 have the following file paths in '
            'common which have different contents:\n'
            '  1\n'
            '  a/2\n',
            fake_logger.output)
Esempio n. 3
0
def init(args):
    if os.path.exists('snapcraft.yaml'):
        logger.error('snapcraft.yaml already exists!')
        sys.exit(1)
    yaml = _TEMPLATE_YAML
    if args.part:
        yaml += 'parts:\n'
    for part_name in args.part:
        part = lifecycle.load_plugin(part_name, part_name)
        yaml += '    ' + part.name + ':\n'
        for opt in part.config.get('options', []):
            if part.config['options'][opt].get('required', False):
                yaml += '        ' + opt + ':\n'
    yaml = yaml.strip()
    with open('snapcraft.yaml', mode='w+') as f:
        f.write(yaml)
    logger.info('Wrote the following as snapcraft.yaml.')
    print()
    print(yaml)
    sys.exit(0)
Esempio n. 4
0
def init(args):
    if os.path.exists("snapcraft.yaml"):
        logger.error("snapcraft.yaml already exists!")
        sys.exit(1)
    yaml = _TEMPLATE_YAML
    if args.part:
        yaml += "parts:\n"
    for part_name in args.part:
        part = lifecycle.load_plugin(part_name, part_name)
        yaml += "    " + part.name + ":\n"
        for opt in part.config.get("options", []):
            if part.config["options"][opt].get("required", False):
                yaml += "        " + opt + ":\n"
    yaml = yaml.strip()
    with open("snapcraft.yaml", mode="w+") as f:
        f.write(yaml)
    logger.info("Wrote the following as snapcraft.yaml.")
    print()
    print(yaml)
    sys.exit(0)
Esempio n. 5
0
def init(args):
    if os.path.exists('snapcraft.yaml'):
        logger.error('snapcraft.yaml already exists!')
        sys.exit(1)
    yaml = _TEMPLATE_YAML
    if args.part:
        yaml += 'parts:\n'
    for part_name in args.part:
        part = lifecycle.load_plugin(part_name, part_name)
        yaml += '    ' + part.name + ':\n'
        for opt in part.config.get('options', []):
            if part.config['options'][opt].get('required', False):
                yaml += '        ' + opt + ':\n'
    yaml = yaml.strip()
    with open('snapcraft.yaml', mode='w+') as f:
        f.write(yaml)
    logger.info('Wrote the following as snapcraft.yaml.')
    print()
    print(yaml)
    sys.exit(0)