Improve shortcut.py.

This commit is contained in:
voussoir 2020-12-07 00:29:44 -08:00
parent 9bde9935eb
commit 4120c3dfcc

View file

@ -22,22 +22,29 @@ def shortcut(lnk_name, target, start_in=None, icon=None):
icon = pathclass.Path(icon) icon = pathclass.Path(icon)
icon.assert_is_file() icon.assert_is_file()
lnk = winshell.Shortcut(lnk.absolute_path) shortcut = winshell.Shortcut(lnk.absolute_path)
lnk.path = target.absolute_path shortcut.path = target.absolute_path
if start_in is not None: if start_in is not None:
lnk.working_directory = start_in.absolute_path shortcut.working_directory = start_in.absolute_path
if icon is not None: if icon is not None:
lnk.icon_location = (icon.absolute_path, 0) shortcut.icon_location = (icon.absolute_path, 0)
lnk.write() shortcut.write()
return lnk
def shortcut_argparse(args): def shortcut_argparse(args):
return shortcut( try:
lnk = shortcut(
lnk_name=args.lnk_name, lnk_name=args.lnk_name,
target=args.target, target=args.target,
start_in=args.start_in, start_in=args.start_in,
icon=args.icon, icon=args.icon,
) )
print(lnk.absolute_path)
return 0
except pathclass.Exists:
print(f'{args.lnk_name} already exists.')
return 1
def main(argv): def main(argv):
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)