From 97adb81dab97fb2b993c4331c53f5e248bf4ed65 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Sat, 15 Jan 2022 17:11:30 -0800 Subject: [PATCH 1/6] Add option to use symlinks --- generate.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/generate.py b/generate.py index 5b03e95..b55f3d6 100755 --- a/generate.py +++ b/generate.py @@ -520,6 +520,7 @@ def main(argv: List[str]): 'all-regions-with-lang', 'debug', 'move', + 'link', 'chunk-size=', 'threads=', 'header-file=', @@ -568,6 +569,7 @@ def main(argv: List[str]): group_by_first_letter = False language_weight = 3 move = False + link = False global THREADS global RULES global MAX_FILE_SIZE @@ -647,6 +649,7 @@ def main(argv: List[str]): except OSError: sys.exit(help_msg('invalid output DIR: %s' % output_dir)) move |= opt == '--move' + link |= opt == '--link' if opt == '--chunk-size': CHUNK_SIZE = int(arg) if opt == '--threads': @@ -910,7 +913,8 @@ def include_candidate(x: GameEntry) -> bool: transfer_file( rom_input_path, rom_output_path, - move) + move, + link) copied_files.add(rom_input_path) else: log( @@ -932,7 +936,7 @@ def include_candidate(x: GameEntry) -> bool: if full_path.is_file(): if curr_out_dir: curr_out_dir.mkdir(parents=True, exist_ok=True) - transfer_file(full_path, curr_out_dir, move) + transfer_file(full_path, curr_out_dir, move, link) else: printed_items.append(file_name) break @@ -948,7 +952,8 @@ def include_candidate(x: GameEntry) -> bool: transfer_file( rom_input_path, rom_output_dir, - move) + move, + link) shutil.copystat( str(full_path), str(rom_output_dir)) @@ -1039,11 +1044,15 @@ def set_scores( def transfer_file( input_path: Path, output_path: Path, - move: bool) -> None: + move: bool, + link: bool) -> None: try: if move: print('Moving [%s] to [%s]' % (input_path, output_path)) shutil.move(str(input_path), str(output_path)) + elif link: + print('Linking [%s] to [%s]' % (input_path, output_path)) + output_path.symlink_to(input_path.resolve()) else: print('Copying [%s] to [%s]' % (input_path, output_path)) shutil.copy2(str(input_path), str(output_path)) @@ -1096,6 +1105,13 @@ def help_msg(s: Optional[Union[str, Exception]] = None) -> str: 'If set, ROMs will be moved, instead of copied, ' 'to the output directory', + '\t--link\t\t\t' + 'If set, ROMs will be symlinked (soft linked) ' + 'to the output directory' + '\n\t\t\t\t' + 'Please note newer versions of Windows 10 require ' + 'elevated privileges to create symlinks', + '\t--group-by-first-letter\t' 'If set, groups ROMs on the output directory in subfolders according ' 'to the first letter in their name', From 3e5fc2124ebac33513a94b726a008336df6e8452 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Sat, 15 Jan 2022 17:12:21 -0800 Subject: [PATCH 2/6] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 96e9564..46ab603 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ Options: -o,--output-dir=PATH If provided, ROMs will be copied to an output directory Ex.: -o "C:\Users\John\Downloads\Emulators\SNES\ROMs\1G1R" --move If set, ROMs will be moved, instead of copied, to the output directory + --link If set, ROMs will be symlinked (soft linked) to the output directory + Please note newer versions of Windows 10 require elevated privileges to create symlinks --group-by-first-letter If set, groups ROMs on the output directory in subfolders according to the first letter in their name # File scanning: From 2f3b1b421ac3b7c341f1de33b33a1e4ac33694f7 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Sun, 16 Jan 2022 23:28:42 -0800 Subject: [PATCH 3/6] Fix using symlinks with --no-scan --- generate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generate.py b/generate.py index b55f3d6..5ba7cf2 100755 --- a/generate.py +++ b/generate.py @@ -936,6 +936,8 @@ def include_candidate(x: GameEntry) -> bool: if full_path.is_file(): if curr_out_dir: curr_out_dir.mkdir(parents=True, exist_ok=True) + if link: + curr_out_dir = curr_out_dir / file_name transfer_file(full_path, curr_out_dir, move, link) else: printed_items.append(file_name) From cfaca14d31a33ecf07a6fbf3839314cc96baf2f0 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Tue, 18 Jan 2022 19:49:54 -0800 Subject: [PATCH 4/6] Rename --link to --symlink --- README.md | 2 +- generate.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 46ab603..e4c5484 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Options: -o,--output-dir=PATH If provided, ROMs will be copied to an output directory Ex.: -o "C:\Users\John\Downloads\Emulators\SNES\ROMs\1G1R" --move If set, ROMs will be moved, instead of copied, to the output directory - --link If set, ROMs will be symlinked (soft linked) to the output directory + --symlink If set, ROMs will be symlinked (soft linked) to the output directory Please note newer versions of Windows 10 require elevated privileges to create symlinks --group-by-first-letter If set, groups ROMs on the output directory in subfolders according to the first letter in their name diff --git a/generate.py b/generate.py index 5ba7cf2..c4f7c34 100755 --- a/generate.py +++ b/generate.py @@ -520,7 +520,7 @@ def main(argv: List[str]): 'all-regions-with-lang', 'debug', 'move', - 'link', + 'symlink', 'chunk-size=', 'threads=', 'header-file=', @@ -569,7 +569,7 @@ def main(argv: List[str]): group_by_first_letter = False language_weight = 3 move = False - link = False + symlink = False global THREADS global RULES global MAX_FILE_SIZE @@ -649,7 +649,7 @@ def main(argv: List[str]): except OSError: sys.exit(help_msg('invalid output DIR: %s' % output_dir)) move |= opt == '--move' - link |= opt == '--link' + symlink |= opt == '--symlink' if opt == '--chunk-size': CHUNK_SIZE = int(arg) if opt == '--threads': @@ -914,7 +914,7 @@ def include_candidate(x: GameEntry) -> bool: rom_input_path, rom_output_path, move, - link) + symlink) copied_files.add(rom_input_path) else: log( @@ -936,9 +936,9 @@ def include_candidate(x: GameEntry) -> bool: if full_path.is_file(): if curr_out_dir: curr_out_dir.mkdir(parents=True, exist_ok=True) - if link: + if symlink: curr_out_dir = curr_out_dir / file_name - transfer_file(full_path, curr_out_dir, move, link) + transfer_file(full_path, curr_out_dir, move, symlink) else: printed_items.append(file_name) break @@ -955,7 +955,7 @@ def include_candidate(x: GameEntry) -> bool: rom_input_path, rom_output_dir, move, - link) + symlink) shutil.copystat( str(full_path), str(rom_output_dir)) @@ -1047,12 +1047,12 @@ def transfer_file( input_path: Path, output_path: Path, move: bool, - link: bool) -> None: + symlink: bool) -> None: try: if move: print('Moving [%s] to [%s]' % (input_path, output_path)) shutil.move(str(input_path), str(output_path)) - elif link: + elif symlink: print('Linking [%s] to [%s]' % (input_path, output_path)) output_path.symlink_to(input_path.resolve()) else: @@ -1107,7 +1107,7 @@ def help_msg(s: Optional[Union[str, Exception]] = None) -> str: 'If set, ROMs will be moved, instead of copied, ' 'to the output directory', - '\t--link\t\t\t' + '\t--symlink\t\t' 'If set, ROMs will be symlinked (soft linked) ' 'to the output directory' '\n\t\t\t\t' From a1aaeeaa3f00212f9933dae412cb3497c161c632 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Tue, 18 Jan 2022 20:14:06 -0800 Subject: [PATCH 5/6] Add option to make symlinks relative --- generate.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/generate.py b/generate.py index c4f7c34..80676ad 100755 --- a/generate.py +++ b/generate.py @@ -2,6 +2,7 @@ import getopt import hashlib +import os.path import re import shutil import sys @@ -521,6 +522,7 @@ def main(argv: List[str]): 'debug', 'move', 'symlink', + 'relative', 'chunk-size=', 'threads=', 'header-file=', @@ -570,6 +572,7 @@ def main(argv: List[str]): language_weight = 3 move = False symlink = False + relative = False global THREADS global RULES global MAX_FILE_SIZE @@ -650,6 +653,7 @@ def main(argv: List[str]): sys.exit(help_msg('invalid output DIR: %s' % output_dir)) move |= opt == '--move' symlink |= opt == '--symlink' + relative |= opt == '--relative' if opt == '--chunk-size': CHUNK_SIZE = int(arg) if opt == '--threads': @@ -914,7 +918,8 @@ def include_candidate(x: GameEntry) -> bool: rom_input_path, rom_output_path, move, - symlink) + symlink, + relative) copied_files.add(rom_input_path) else: log( @@ -938,7 +943,7 @@ def include_candidate(x: GameEntry) -> bool: curr_out_dir.mkdir(parents=True, exist_ok=True) if symlink: curr_out_dir = curr_out_dir / file_name - transfer_file(full_path, curr_out_dir, move, symlink) + transfer_file(full_path, curr_out_dir, move, symlink, relative) else: printed_items.append(file_name) break @@ -955,7 +960,8 @@ def include_candidate(x: GameEntry) -> bool: rom_input_path, rom_output_dir, move, - symlink) + symlink, + relative) shutil.copystat( str(full_path), str(rom_output_dir)) @@ -1047,14 +1053,18 @@ def transfer_file( input_path: Path, output_path: Path, move: bool, - symlink: bool) -> None: + symlink: bool, + relative: bool) -> None: try: if move: print('Moving [%s] to [%s]' % (input_path, output_path)) shutil.move(str(input_path), str(output_path)) elif symlink: print('Linking [%s] to [%s]' % (input_path, output_path)) - output_path.symlink_to(input_path.resolve()) + if not relative: + output_path.symlink_to(input_path.resolve()) + else: + output_path.symlink_to(os.path.relpath(input_path, output_path.parent)) else: print('Copying [%s] to [%s]' % (input_path, output_path)) shutil.copy2(str(input_path), str(output_path)) @@ -1114,6 +1124,10 @@ def help_msg(s: Optional[Union[str, Exception]] = None) -> str: 'Please note newer versions of Windows 10 require ' 'elevated privileges to create symlinks', + '\t--relative\t\t' + 'If set along with --symlink, will create ' + 'relative symlinks instead of absolute', + '\t--group-by-first-letter\t' 'If set, groups ROMs on the output directory in subfolders according ' 'to the first letter in their name', From d0c792cb15f11c74d173db405a51f2d6371bece9 Mon Sep 17 00:00:00 2001 From: gvbr <41351562+gvbr@users.noreply.github.com> Date: Tue, 18 Jan 2022 20:15:02 -0800 Subject: [PATCH 6/6] Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e4c5484..abe65b0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Options: --move If set, ROMs will be moved, instead of copied, to the output directory --symlink If set, ROMs will be symlinked (soft linked) to the output directory Please note newer versions of Windows 10 require elevated privileges to create symlinks + --relative If set along with --symlink, will create relative symlinks instead of absolute --group-by-first-letter If set, groups ROMs on the output directory in subfolders according to the first letter in their name # File scanning: