Improve reg_extension_icon docstring, add separate --extension.
This commit is contained in:
parent
05d1eb745e
commit
518ca07919
1 changed files with 32 additions and 10 deletions
|
@ -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 <flags>
|
||||
|
||||
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:]))
|
||||
|
|
Loading…
Reference in a new issue