Skip to content

Commit

Permalink
Merge pull request #23 from jiri-otoupal/docs-import-fix
Browse files Browse the repository at this point in the history
Imports fix
  • Loading branch information
jiri-otoupal authored May 11, 2022
2 parents a84a2bb + 0cd1642 commit 3ae1d26
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pycrosskit/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"variables and shortcuts easy "
)

__version__ = "1.6.5"
__version__ = "1.6.6"
__author__ = "Jiri Otoupal"
__author_email__ = "jiri-otoupal@ips-database.eu"
__license__ = "Apache 2.0"
Expand Down
3 changes: 3 additions & 0 deletions pycrosskit/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from collections import namedtuple

UserFolders = namedtuple("UserFolders", ("home", "desktop", "startmenu"))
9 changes: 5 additions & 4 deletions pycrosskit/shortcut_platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from pathlib import Path
from typing import Tuple

from pycrosskit.shortcuts import UserFolders, Shortcut
from pycrosskit.constants import UserFolders
from pycrosskit.shortcuts import Shortcut

scut_ext = ".desktop"
ico_ext = ("ico", "svg", "png")
Expand Down Expand Up @@ -89,7 +90,7 @@ def get_folders() -> UserFolders:


def create_shortcut(
shortcut_instance: Shortcut, desktop: bool = False, startmenu: bool = False
shortcut_instance: Shortcut, desktop: bool = False, startmenu: bool = False
):
"""Creates shortcut on the system.
Expand All @@ -114,8 +115,8 @@ def create_shortcut(
name=shortcut_instance.shortcut_name,
desc=shortcut_instance.description,
exe=f"bash -c "
f"'cd {shortcut_instance.work_path}"
f" && {shortcut_instance.exec_path}'",
f"'cd {shortcut_instance.work_path}"
f" && {shortcut_instance.exec_path}'",
icon=shortcut_instance.icon_path,
args=shortcut_instance.arguments,
)
Expand Down
3 changes: 2 additions & 1 deletion pycrosskit/shortcut_platforms/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import win32com.client
from win32comext.shell import shell, shellcon

from pycrosskit.shortcuts import UserFolders, Shortcut
from pycrosskit.constants import UserFolders
from pycrosskit.shortcuts import Shortcut

scut_ext = ".lnk"
ico_ext = ("ico",)
Expand Down
45 changes: 22 additions & 23 deletions pycrosskit/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
#! python3 # noqa: E265

# -- IMPORTS

# standard
import os
from collections import namedtuple
from typing import Tuple


# conditional
if os.name == "nt":
from pycrosskit.shortcut_platforms.windows import (create_shortcut,
delete_shortcut)
else:
from pycrosskit.shortcut_platforms.linux import (create_shortcut,
delete_shortcut)

# -- GLOBALS
UserFolders = namedtuple("UserFolders", ("home", "desktop", "startmenu"))

# -- CLASSES
class Shortcut:
def __init__(
self,
shortcut_name: str,
exec_path: str,
description: str = "",
icon_path: str = "",
desktop: bool = False,
start_menu: bool = False,
work_dir: str = None,
self,
shortcut_name: str,
exec_path: str,
description: str = "",
icon_path: str = "",
desktop: bool = False,
start_menu: bool = False,
work_dir: str = None,
):
"""Initialize a shortcut object.
Expand All @@ -48,22 +37,32 @@ def __init__(
self.icon_path = str(icon_path)
self.work_path = str(work_dir)

if os.name == "nt":
from pycrosskit.shortcut_platforms.windows import create_shortcut
else:
from pycrosskit.shortcut_platforms.linux import create_shortcut

# create shortcut
self.desktop_path, self.startmenu_path = create_shortcut(
self, start_menu, desktop
)

@staticmethod
def delete(
shortcut_name: str, desktop: bool = False, start_menu: bool = False
shortcut_name: str, desktop: bool = False, start_menu: bool = False
) -> Tuple[str, str]:
"""Remove existing Shortcut from the system.
:param str shortcut_name: Name of shortcut
:param bool desktop: Delete Shortcut on Desktop
:param bool start_menu: Delete Shortcut on Start Menu
:return: desktop and startmenu path
:return Tuple[str, str]: desktop_path, startmenu_path
:return: desktop and start menu path
:return Tuple[str, str]: desktop_path, start menu path
"""
if os.name == "nt":
from pycrosskit.shortcut_platforms.windows import delete_shortcut
else:
from pycrosskit.shortcut_platforms.linux import delete_shortcut

return delete_shortcut(shortcut_name, desktop, start_menu)

0 comments on commit 3ae1d26

Please sign in to comment.