From 8cfb695212dbf5d8d1d1a769fe29e1070fbdb23f Mon Sep 17 00:00:00 2001 From: jiri_otoupal Date: Sat, 30 Apr 2022 14:35:31 +0200 Subject: [PATCH 1/4] Fixing folder path to full icon path --- pycrosskit/shortcut_platforms/linux.py | 43 +++++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/pycrosskit/shortcut_platforms/linux.py b/pycrosskit/shortcut_platforms/linux.py index c04c1c0..6a7184a 100644 --- a/pycrosskit/shortcut_platforms/linux.py +++ b/pycrosskit/shortcut_platforms/linux.py @@ -85,28 +85,41 @@ def create_shortcut(shortcut_instance, :rtype: str, str """ if shortcut_instance.work_path is None: - text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, desc=shortcut_instance.description, - exe=shortcut_instance.exec_path, icon=shortcut_instance.icon_path, + text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, + desc=shortcut_instance.description, + exe=shortcut_instance.exec_path, + icon=shortcut_instance.icon_path, args=shortcut_instance.arguments) else: - text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, desc=shortcut_instance.description, + text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, + desc=shortcut_instance.description, exe="bash -c 'cd " + shortcut_instance.work_path + " && " + shortcut_instance.exec_path + "'", icon=shortcut_instance.icon_path, args=shortcut_instance.arguments) user_folders = get_folders() - for (create, folder) in ((desktop, user_folders.desktop), - (startmenu, user_folders.startmenu)): - if create: - if not os.path.exists(folder): - os.makedirs(folder) - dest = str(Path(folder) / (shortcut_instance.shortcut_name + scut_ext)) - with open(dest, 'w') as f_out: - f_out.write(text) - st = os.stat(dest) - os.chmod(dest, st.st_mode | stat.S_IEXEC) - - return user_folders.desktop, user_folders.startmenu + desktop_path = str( + Path(user_folders.desktop) / (shortcut_instance.shortcut_name + scut_ext)) + startmenu_path = str( + Path(user_folders.startmenu) / (shortcut_instance.shortcut_name + scut_ext)) + + if desktop: + __write_shortcut(desktop_path, shortcut_instance, text) + + if startmenu: + __write_shortcut(startmenu_path, shortcut_instance, text) + + return desktop_path, startmenu_path + + +def __write_shortcut(dest_path, shortcut_instance, icon_content): + if not os.path.exists(dest_path): + os.makedirs(dest_path) + dest = str(Path(dest_path) / (shortcut_instance.shortcut_name + scut_ext)) + with open(dest, 'w') as f_out: + f_out.write(icon_content) + st = os.stat(dest) + os.chmod(dest, st.st_mode | stat.S_IEXEC) def delete_shortcut(shortcut_name, desktop=False, startmenu=False): From e7f9292ab27c9690b81b38f48fde1cf1e452bd98 Mon Sep 17 00:00:00 2001 From: jiri_otoupal Date: Sat, 30 Apr 2022 14:36:46 +0200 Subject: [PATCH 2/4] Class arg renaming --- pycrosskit/envariables.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pycrosskit/envariables.py b/pycrosskit/envariables.py index 4ad1ccc..b1b2184 100644 --- a/pycrosskit/envariables.py +++ b/pycrosskit/envariables.py @@ -29,10 +29,10 @@ def save_shell_specs(cls, shell, shell_file): cls.system_env_handler.shell = shell cls.system_env_handler.shell_file = shell_file - def __new__(mcs, *args, **kwargs): - if mcs.system_env_handler is not None: - mcs.logger.debug(f"Accessed instance of type {os.name}") - return mcs.system_env_handler + def __new__(cls, *args, **kwargs): + if cls.system_env_handler is not None: + cls.logger.debug(f"Accessed instance of type {os.name}") + return cls.system_env_handler if os.name == "nt": from pycrosskit.env_platforms.windows import WinVar @@ -43,7 +43,7 @@ def __new__(mcs, *args, **kwargs): detected_env = LinVar() - mcs.logger.debug(f"Created new instance of type {os.name}") - mcs.system_env_handler = detected_env + cls.logger.debug(f"Created new instance of type {os.name}") + cls.system_env_handler = detected_env return detected_env From fa8a49377ba9d91bfe564754813b254d2cc1c245 Mon Sep 17 00:00:00 2001 From: jiri_otoupal Date: Sat, 30 Apr 2022 14:41:41 +0200 Subject: [PATCH 3/4] added doc --- pycrosskit/shortcut_platforms/linux.py | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/pycrosskit/shortcut_platforms/linux.py b/pycrosskit/shortcut_platforms/linux.py index 6a7184a..f8cd7cb 100644 --- a/pycrosskit/shortcut_platforms/linux.py +++ b/pycrosskit/shortcut_platforms/linux.py @@ -85,18 +85,18 @@ def create_shortcut(shortcut_instance, :rtype: str, str """ if shortcut_instance.work_path is None: - text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, - desc=shortcut_instance.description, - exe=shortcut_instance.exec_path, - icon=shortcut_instance.icon_path, - args=shortcut_instance.arguments) + file_content = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, + desc=shortcut_instance.description, + exe=shortcut_instance.exec_path, + icon=shortcut_instance.icon_path, + args=shortcut_instance.arguments) else: - text = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, - desc=shortcut_instance.description, - exe="bash -c 'cd " + shortcut_instance.work_path + " && " - + shortcut_instance.exec_path + "'", - icon=shortcut_instance.icon_path, - args=shortcut_instance.arguments) + file_content = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, + desc=shortcut_instance.description, + exe="bash -c 'cd " + shortcut_instance.work_path + " && " + + shortcut_instance.exec_path + "'", + icon=shortcut_instance.icon_path, + args=shortcut_instance.arguments) user_folders = get_folders() desktop_path = str( Path(user_folders.desktop) / (shortcut_instance.shortcut_name + scut_ext)) @@ -104,20 +104,26 @@ def create_shortcut(shortcut_instance, Path(user_folders.startmenu) / (shortcut_instance.shortcut_name + scut_ext)) if desktop: - __write_shortcut(desktop_path, shortcut_instance, text) + __write_shortcut(desktop_path, shortcut_instance, file_content) if startmenu: - __write_shortcut(startmenu_path, shortcut_instance, text) + __write_shortcut(startmenu_path, shortcut_instance, file_content) return desktop_path, startmenu_path -def __write_shortcut(dest_path, shortcut_instance, icon_content): +def __write_shortcut(dest_path, shortcut_instance, file_content): + """ + Writes shortcut content to destination + :param dest_path: Path where write file + :param shortcut_instance: Instance of shortcut that will be used + :param file_content: Content of future icon from DESKTOP_FORM.format(...) + """ if not os.path.exists(dest_path): os.makedirs(dest_path) dest = str(Path(dest_path) / (shortcut_instance.shortcut_name + scut_ext)) with open(dest, 'w') as f_out: - f_out.write(icon_content) + f_out.write(file_content) st = os.stat(dest) os.chmod(dest, st.st_mode | stat.S_IEXEC) From b8bc7ad8d17c2f18a6b3ea2ab9af11b6872e4303 Mon Sep 17 00:00:00 2001 From: jiri_otoupal Date: Sat, 30 Apr 2022 14:46:15 +0200 Subject: [PATCH 4/4] str concat rewrite to fstring --- pycrosskit/shortcut_platforms/linux.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pycrosskit/shortcut_platforms/linux.py b/pycrosskit/shortcut_platforms/linux.py index f8cd7cb..ba0063b 100644 --- a/pycrosskit/shortcut_platforms/linux.py +++ b/pycrosskit/shortcut_platforms/linux.py @@ -93,8 +93,9 @@ def create_shortcut(shortcut_instance, else: file_content = DESKTOP_FORM.format(name=shortcut_instance.shortcut_name, desc=shortcut_instance.description, - exe="bash -c 'cd " + shortcut_instance.work_path + " && " - + shortcut_instance.exec_path + "'", + exe=f"bash -c " + f"'cd {shortcut_instance.work_path}" + f" && {shortcut_instance.exec_path}'", icon=shortcut_instance.icon_path, args=shortcut_instance.arguments) user_folders = get_folders()