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)
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()
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()
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}")
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
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)
def patch_versions(storage, stored=False): for v in ('7.25', '7.24', '7.23', '7.22'): yield PatchVersion._create(storage, Version(v), [])
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), [])
def test_base_version_init_bad(arg, exc): with pytest.raises(exc): PatchVersion(arg)
def test_patch_version_init_ok(arg, t, s): v = PatchVersion(arg) assert v.t == t assert v.s == s
def storage_patches(stored=False): for v in ('7.25', '7.24', '7.23', '7.22'): yield PatchElement('game', PatchVersion(v))
def fake_patch(version): return Patch._create([PatchElement('game', PatchVersion(version))])