diff --git a/src/passui.desktop b/data/org.smolnet.passui.desktop similarity index 100% rename from src/passui.desktop rename to data/org.smolnet.passui.desktop diff --git a/install.sh b/install.sh index d40fa92..2665b18 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash if [[ "${1}" == "-u" ]]; then echo "Uninstalling passui" - sudo rm /usr/local/bin/passui /usr/share/applications/passui.desktop + sudo rm /usr/local/bin/passui /usr/share/applications/{org.smolnet.,}passui.desktop echo "If you wish you can now manually remove the dependencies: wxpython git gnupg pass" exit 0 elif [[ "${1}" == "-h" ]]; then @@ -20,11 +20,11 @@ elif [[ -f /usr/bin/pacman ]]; then # Arch/Manjaro else echo " This distribution is not supported by this installer. manually install: wxpython python3-gnupg git gnupg pass - and then copy passui to /usr/local/bin and passui.desktop to /usr/share/applications/" + and then copy passui to /usr/local/bin and org.smolnet.passui.desktop to /usr/share/applications/" exit 1 fi -sudo cp src/main.py /usr/local/bin/passui -sudo cp -a src/pass_handler /usr/lib/python3.9/site-packages/ -sudo cp -a src/pass_handler /usr/lib/python3.9/ -sudo cp src/passui.desktop /usr/share/applications/ +sudo cp scripts/passui /usr/local/bin/ +sudo cp -a lib/pass_handler /usr/lib/python3.9/site-packages/ +sudo cp -a lib/pass_handler /usr/lib/python3.9/ +sudo cp data/org.smolnet.passui.desktop /usr/share/applications/ exit 0 diff --git a/src/main.py b/scripts/passui similarity index 100% rename from src/main.py rename to scripts/passui diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7779f66 --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +import setuptools + +with open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +setuptools.setup( + name="passui", + version="0.0.1", + author="Micke Nordin", + author_email="hej@mic.ke", + data_files = [('share/applications', ['data/org.smolnet.passui.desktop']),], + description="A GUI for the standad Unix password manager.", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://code.smolnet.org/micke/passui", + project_urls={ + "Bug Tracker": "https://code.smolnet.org/micke/passui", + }, + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GPL-3.0", + "Operating System :: OS Independent", + ], + package_dir={"": "lib"}, + packages=setuptools.find_packages(where="lib"), + python_requires=">=3.9", + scripts=["scripts/passui"], +) diff --git a/src/pass_handler/__init__.py b/src/pass_handler/__init__.py deleted file mode 100644 index 05980ee..0000000 --- a/src/pass_handler/__init__.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/python3 -import os -import subprocess -from typing import Union - - -class Pass: - - def __init__(self): - self.top_dir: str = os.environ.get('PASSWORD_STORE_DIR') - self.is_init = False - if not self.top_dir: - self.top_dir = os.environ.get('HOME') + '/.password-store' - if os.path.isdir(self.top_dir): - self.set_paths_on_init() - - def delete_password(self, path: str): - """delete_password. - - :param path: str - """ - command1: list[str] = ['/usr/bin/pass', 'rm', '-f', path] - run_command(command1) - self.move_up() - self.cur_paths = self.get_pass_paths() - self.cur_passwords = self.get_pass_passwords() - - def get_pass_path_from_index(self, index: int, path_type: str = "path") -> str: - """get_pass_path_from_index. - - :param index: int - :param path_type: str, default: "path" - """ - if path_type == "password": - result: str = self.cur_passwords[index] - else: - result: str = self.cur_paths[index] - return result.replace(self.top_dir, '').replace('.gpg', '') - - def get_pass_passwords(self) -> list[str]: - """get_pass_passwords.""" - passwords: list[str] = list() - for m_file in os.listdir(self.cur_dir): - if m_file.endswith(".gpg"): - passwords.append(os.path.join(self.cur_dir, m_file)) - passwords = sorted(passwords) - return passwords - - def get_pass_paths(self) -> list[str]: - """get_pass_paths.""" - dirs: list[str] = list() - if self.cur_dir != self.top_dir: - dirs.append(self.cur_dir) - for c_dir in os.listdir(self.cur_dir): - if os.path.isdir(os.path.join(self.cur_dir, - c_dir)) and c_dir != ".git": - dirs.append(os.path.join(self.cur_dir, c_dir)) - dirs = sorted(dirs) - return dirs - - def move_up(self) -> bool: - """move_up.""" - if self.cur_dir == self.top_dir: - return True - if not os.path.isdir(self.cur_dir): - self.cur_dir = os.path.abspath(os.path.join(self.cur_dir, os.pardir)) - self.move_up() - return True - - def pass_init(self, gpg_key: str, git_repo: Union[None, str] = None): - """pass_init. - - """ - if git_repo: - run_command(['/usr/bin/git', 'clone', git_repo, self.top_dir]) - else: - run_command(['/usr/bin/pass', 'init', gpg_key]) - self.set_paths_on_init() - - def save_to_pass(self, password, path, full_path): - command1: list[str] = ['/bin/echo', password.rstrip("\n")] - command2: list[str] = ['/usr/bin/pass', 'insert', '-m', path] - run_command(command1, command2) - self.cur_paths = sorted([full_path] + self.cur_paths) - self.cur_passwords = self.get_pass_passwords() - - def set_paths_on_init(self): - """set_paths_on_init. - - """ - self.cur_dir: str = self.top_dir - self.cur_paths: list[str] = self.get_pass_paths() - self.cur_passwords: list[str] = self.get_pass_passwords() - self.is_init = True - - -def copy_to_clipboard(text) -> tuple[Union[str, bytes], Union[str, bytes]]: - """copy_to_clipboard. - - :param text: - """ - password: str = text.split('\n')[0] - command1: list[str] = ['/bin/echo', password] - command2: list[str] = ['/usr/bin/wl-copy'] - result: tuple[Union[str, bytes], Union[str, bytes]] = run_command(command1, command2) - return result - - -def get_password_from_path(pass_path) -> str: - """get_password_from_path. - - :param pass_path: - """ - result: tuple[Union[str, bytes], Union[str, bytes]] = run_command(['/usr/bin/pass', 'show', pass_path]) - password: str = result[0].decode() - return password - - -def pass_pull(): - """pass_pull. - - """ - run_command(['/usr/bin/pass', 'git', 'pull']) - - -def pass_push(): - """pass_push. - - """ - run_command(['/usr/bin/pass', 'git', 'push']) - - -def run_command(command1, command2=None) -> tuple[Union[str, bytes], Union[str, bytes]]: - """Run a command on system and capture result - - :param command1: - :param command2: - """ - process1: subprocess.Popen = subprocess.Popen(command1, - shell=False, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # If there is a second command it is taken to be a pipeline - if command2: - subprocess.Popen(command2, - shell=False, - stdin=process1.stdout, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - process1.stdout.close() - return process1.communicate()