From 518ca079195263521cbb10887ba7df7cdfcb4602 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 17 Jul 2021 10:31:23 -0700 Subject: [PATCH] Improve reg_extension_icon docstring, add separate --extension. --- reg_extension_icon.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/reg_extension_icon.py b/reg_extension_icon.py index d86debb..b9d51fe 100644 --- a/reg_extension_icon.py +++ b/reg_extension_icon.py @@ -1,26 +1,48 @@ ''' -I create my own icon files for some file types. This script edits the windows -registry to assign the file extension icon and optionally a human-friendly name -string. Must run as administrator. +reg_extension_icon +================== + +This script edits the windows registry HKEY_CLASSES_ROOT to assign a file +extension icon and optionally a human-friendly name string. + +Must run as administrator. WARNING, if the extension is already associated with a program, or is otherwise connected to a progid, this will break it. + +> reg_extension_icon ico_file + +ico_file: + Filepath of the icon file. + +--extension: + If you omit this option, your file should be named "png.ico" or "py.ico" to + set the icon for png and py types. If the name of your ico file is not the + name of the extension you want to control, specify the extension here. + +--name: + A human-friendly name string which will show on Explorer under the "Type" + column and in the properties dialog. ''' import argparse import sys import winreg +from voussoirkit import betterhelp from voussoirkit import interactive from voussoirkit import pathclass -def extension_registry(ico_file, human_name=None): +def extension_registry(ico_file, extension=None, human_name=None): if ico_file.extension != 'ico': raise ValueError('Must provide a .ico file.') - name = ico_file.replace_extension('').basename + if extension is None: + extension = ico_file.replace_extension('').basename + else: + extension = extension.strip('.') - dot_ex = f'.{name}' - hash_ex = f'#{name}' + dot_ex = f'.{extension}' + hash_ex = f'#{extension}' prompt = [ f'Set {dot_ex} = {hash_ex}', @@ -47,10 +69,10 @@ def extension_registry(ico_file, human_name=None): print('Finished.') - def extension_registry_argparse(args): return extension_registry( ico_file=pathclass.Path(args.ico_file), + extension=args.extension, human_name=args.name, ) @@ -58,11 +80,11 @@ def main(argv): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('ico_file') + parser.add_argument('--extension', default=None) parser.add_argument('--name', default=None) parser.set_defaults(func=extension_registry_argparse) - args = parser.parse_args(argv) - return args.func(args) + return betterhelp.single_main(argv, parser, __doc__) if __name__ == '__main__': raise SystemExit(main(sys.argv[1:]))