Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut linux fix #6

Merged
merged 4 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pycrosskit/envariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
60 changes: 40 additions & 20 deletions pycrosskit/shortcut_platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,48 @@ 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=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()
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, file_content)

if startmenu:
__write_shortcut(startmenu_path, shortcut_instance, file_content)

return desktop_path, startmenu_path


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(file_content)
st = os.stat(dest)
os.chmod(dest, st.st_mode | stat.S_IEXEC)


def delete_shortcut(shortcut_name, desktop=False, startmenu=False):
Expand Down