Beispiel #1
0
def command_export(parser, args):
    storage = args.storage

    if args.symlinks:
        # symlink are not supported on Windows because of the
        # 'target_is_directory' parameter which requires extra handling
        if os.name == 'nt' or not hasattr(os, 'symlink'):
            parser.error("symlinks not supported on this platform")

    overwrite = not args.lazy
    symlinks = bool(args.symlinks)

    if not args.patch:
        # multiple patches (update only)
        if args.previous:
            parser.error("patch version required with --previous or --full")
        if args.first:
            parser.error("--from is required when no patch is provided")
        exporters = CdragonRawPatchExporter.from_directory(storage,
                                                           args.output,
                                                           Version(args.first),
                                                           symlinks=symlinks)
        for exporter in exporters:
            exporter.process(overwrite=overwrite)
    else:
        if args.first:
            parser.error("--from cannot be used when providing a patch")
        # single patch
        # retrieve target and previous patch versions
        patch = PatchVersion.version(
            storage, None if args.patch == 'latest' else Version(args.patch))
        if patch is None:
            parser.error(f"patch not found: {args.patch}")
        if args.previous == 'none':
            previous_patch = None
        elif args.previous:
            previous_patch = PatchVersion.version(storage,
                                                  Version(args.previous),
                                                  stored=True)
            if previous_patch is None:
                parser.error(f"previous patch not found: {patch.version}")
        else:
            it = PatchVersion.versions(storage, stored=True)
            for v in it:
                if v.version == patch.version:
                    previous_patch = next(it)
                    break
            else:
                parser.error("cannot guess previous patch")

        exporter = CdragonRawPatchExporter(os.path.join(
            args.output, str(patch.version)),
                                           patch,
                                           previous_patch,
                                           symlinks=symlinks)
        exporter.process(overwrite=overwrite)
Beispiel #2
0
def command_export(parser, args):
    storage = args.storage

    if args.symlinks:
        # symlink are not supported on Windows because of the
        # 'target_is_directory' parameter which requires extra handling
        if os.name == 'nt' or not hasattr(os, 'symlink'):
            parser.error("symlinks not supported on this platform")

    if not args.patch:
        # multiple patch (update only)
        if args.previous:
            parser.error("patch version required with --previous or --full")
        exporter = Exporter(storage, args.output)
        exporter.update()
        if args.symlinks:
            exporter.create_symlinks()
    else:
        # single patch
        # retrieve target and previous patch versions
        patch = PatchVersion.version(
            storage, None if args.patch == 'latest' else Version(args.patch))
        if patch is None:
            parser.error(f"patch not found: {args.patch}")
        if args.previous == 'none':
            previous_patch = None
        elif args.previous:
            previous_patch = PatchVersion.version(storage,
                                                  Version(args.previous),
                                                  stored=True)
            if previous_patch is None:
                parser.error(f"previous patch not found: {patch.version}")
        else:
            it = PatchVersion.versions(storage, stored=True)
            for v in it:
                if v.version == patch.version:
                    previous_patch = next(it)
                    break
            else:
                parser.error("cannot guess previous patch")

        exporter = PatchExporter(os.path.join(args.output, str(patch.version)),
                                 patch, previous_patch)
        exporter.export()
        exporter.write_links()
        if args.symlinks:
            exporter.create_symlinks()
Beispiel #3
0
def test_cli_export_versions(runner, monkeypatch, mocker, args, version,
                             previous_version, overwrite):
    def patch_versions(storage, stored=False):
        for v in ('7.25', '7.24', '7.23', '7.22'):
            yield PatchVersion._create(storage, Version(v), [])

    monkeypatch.setattr(PatchVersion, 'versions', patch_versions)

    with mocker.patch('cdragontoolbox.__main__.PatchExporter'):
        mock = cdragontoolbox.__main__.PatchExporter
        mock.return_value = mock_instance = mocker.Mock()
        runner("export " + args)

        patch = PatchVersion._create(None, version, [])
        previous_patch = None if previous_version is None else PatchVersion._create(
            None, previous_version, [])
        mock.assert_called_once_with(os.path.join('export', '7.24'), patch,
                                     previous_patch)

        mock_instance.export.assert_called_once_with(overwrite=overwrite)
        mock_instance.write_links.assert_called_once_with()
Beispiel #4
0
def command_versions(parser, args):
    if args.component == 'patch':
        # special case for listing patch versions
        for patch in PatchVersion.versions(args.storage, stored=args.stored):
            print(patch.version)
        return

    component = parse_component_arg(parser, args.storage, args.component)
    if isinstance(component, (Project, Solution)):
        for pv in component.versions():
            print(pv.version)
    else:
        parser.error(f"command cannot be used on {component}")
Beispiel #5
0
def test_patch_version_versions(storage, monkeypatch, solution_versions,
                                patch_versions):
    def patch_version(self):
        return solution_versions[str(self)]

    monkeypatch.setattr(SolutionVersion, 'patch_version', patch_version)

    for sv in solution_versions:
        sv = parse_component(storage, sv)
        os.makedirs(f"{storage.path}/{sv.path}", exist_ok=True)

    result = list(PatchVersion.versions(storage, stored=True))
    result = [(str(p.version), [str(sv) for sv in p.solutions()])
              for p in result]
    assert result == patch_versions
Beispiel #6
0
def command_export(parser, args):
    storage = args.storage
    overwrite = not args.lazy
    symlinks = bool(args.symlinks)

    if not args.patch:
        # multiple patches (update only)
        if args.previous:
            parser.error("patch version required with --previous or --full")
        if args.first:
            parser.error("--from is required when no patch is provided")
        exporters = CdragonRawPatchExporter.from_directory(storage,
                                                           args.output,
                                                           PatchVersion(
                                                               args.first),
                                                           symlinks=symlinks)
        for exporter in exporters:
            exporter.process(overwrite=overwrite)
    else:
        if args.first:
            parser.error("--from cannot be used when providing a patch")
        # single patch
        # retrieve target and previous patch versions
        patch = storage.patch(None if args.patch == 'latest' else args.patch)
        if patch is None:
            parser.error(f"patch not found: {args.patch}")
        if args.previous == 'none':
            previous_patch = None
        elif args.previous:
            previous_patch = storage.patch(args.previous, stored=True)
            if previous_patch is None:
                parser.error(f"previous patch not found: {patch.version}")
        else:
            it = storage.patches(stored=True)
            for v in it:
                if v.version == patch.version:
                    previous_patch = next(it)
                    break
            else:
                parser.error("cannot guess previous patch")

        exporter = CdragonRawPatchExporter(os.path.join(
            args.output, str(patch.version)),
                                           patch,
                                           previous_patch,
                                           symlinks=symlinks)
        exporter.process(overwrite=overwrite)
Beispiel #7
0
 def patch_versions(storage, stored=False):
     for v in ('7.25', '7.24', '7.23', '7.22'):
         yield PatchVersion._create(storage, Version(v), [])
Beispiel #8
0
 def gen_versions(storage, stored):
     assert stored == False
     for v in ('7.23', '7.21', '7.20', '7.19'):
         yield PatchVersion._create(storage, Version(v), [])
Beispiel #9
0
def test_base_version_init_bad(arg, exc):
    with pytest.raises(exc):
        PatchVersion(arg)
Beispiel #10
0
def test_patch_version_init_ok(arg, t, s):
    v = PatchVersion(arg)
    assert v.t == t
    assert v.s == s
Beispiel #11
0
 def storage_patches(stored=False):
     for v in ('7.25', '7.24', '7.23', '7.22'):
         yield PatchElement('game', PatchVersion(v))
Beispiel #12
0
 def fake_patch(version):
     return Patch._create([PatchElement('game', PatchVersion(version))])