Skip to content

Commit

Permalink
Merge pull request #2 from shugaoye/master
Browse files Browse the repository at this point in the history
Fixed errors when load to PyPi.
  • Loading branch information
passxyz authored Apr 4, 2021
2 parents b767749 + 5540649 commit 2149d70
Show file tree
Hide file tree
Showing 26 changed files with 118 additions and 69 deletions.
39 changes: 0 additions & 39 deletions README.md

This file was deleted.

72 changes: 72 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
KeePass command line application
================================

`KPCLibPy <https://github.com/passxyz/KPCLibPy>`__ is a KeePass command
application written in Python.

The original `KeePass <https://keepass.info/>`__ by Dominik Reichl is a
.NET application written in C#. ``KeePassLib`` is part of KeePass which
can be built as a library to support the major functions of KeePass.
However, at the moment, ``KeePassLib`` is still built for .NET framework
which can run on Windows only. I modified ``KeePassLib`` and extended it
as a .NET Standard library -
`KPCLib <https://github.com/passxyz/KPCLib>`__.
`KPCLib <https://github.com/passxyz/KPCLib>`__ stands for KeePass
Portable Class Library at the time when I started the work. Portable
Class Library (PCL) is replaced by .NET Standard Library nowadays.

`KPCLibPy <https://github.com/passxyz/KPCLibPy>`__ is just a Python
wrapper of `KPCLib <https://github.com/passxyz/KPCLib>`__ using
`Python.NET <http://pythonnet.github.io/>`__. In this perspective,
``KPCLibPy`` is fully compatible to the original KeePass, since the
majority of code is the same as KeePass.

In order to save the development effort and have a nice user interface,
the Python library
`python-nubia <https://github.com/facebookincubator/python-nubia>`__
from Facebook is used as the framework to support command line
interface.

Key Features
------------

- Full compatible with the original KeePass
- .NET Standard 2.0 support with
`KPCLib <https://github.com/passxyz/KPCLib>`__
- Cross platform support with .NET Standard and .NET core
- Nice user interface with
`python-nubia <https://github.com/facebookincubator/python-nubia>`__
- Interactive mode that offers fish-style auto-completion

Installation
------------

As a developer, you can use
`KPCLibPy <https://github.com/passxyz/KPCLibPy>`__ from GitHub directly.

.. code:: bash
git clone https://github.com/shugaoye/KPCLibPy.git
cd KPCLibPy
pip install -r requirements.txt
cd src
python3 ./nubia_main.py
For normal user, `KPCLibPy <https://github.com/passxyz/KPCLibPy>`__ can
be installed using pip.

::

$ pip install kpclibpy
$ keepass

|image01|

Docker image
------------

A Dockr image -
`docker-mono <https://github.com/shugaoye/docker-mono>`__ can be used on
Linux or Windows 10 (WSL).

.. |image01| image:: https://github.com/passxyz/passxyz.github.io/raw/master/images/kpclib/kpclibpy.gif
File renamed without changes.
15 changes: 9 additions & 6 deletions src/nubia_main.py → kpclibpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@

import sys
import os
from typing import Any

import commands
import kpclibpy.commands
from nubia import Nubia, Options
from nubia_plugin import NubiaPassXYZPlugin
from commands.keepass import get_homepath
from kpclibpy.nubia_plugin import NubiaPassXYZPlugin
from kpclibpy.commands.keepass import get_homepath


if __name__ == "__main__":
def main() -> Any:
homepath = get_homepath()
if not os.path.exists(homepath):
os.mkdir(homepath)

plugin = NubiaPassXYZPlugin()
shell = Nubia(
name="nubia_passxyz",
command_pkgs=commands,
command_pkgs=kpclibpy.commands,
plugin=plugin,
options=Options(
persistent_history=False, auto_execute_single_suggestions=False
),
)
sys.exit(shell.run())

if __name__ == "__main__":
sys.exit(main())
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from prettytable import PrettyTable
from termcolor import cprint, colored
from nubia import command, argument, context
from commands.keepass import IStatusLogger, get_homepath, lsdb
from kpclibpy.commands.keepass import IStatusLogger, get_homepath, lsdb
#from KeePassLib import PwGroup, PwEntry, Collections


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commands/keepass.py → kpclibpy/commands/keepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from os.path import isfile, join
from prettytable import PrettyTable
from termcolor import cprint, colored
import kpclibpy
import kpclibpy.kpclib

from KeePassLib import PwGroup, PwEntry, SearchParameters
from KeePassLib.Collections import PwObjectList
Expand Down
File renamed without changes.
21 changes: 7 additions & 14 deletions src/kpclibpy/kpclib.py → kpclibpy/kpclib/kpclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,22 @@
import clr
import sys

from kpclibpy import __path__ as kpclibpy_path

def interop_dll_path(dll_name):
# Unfrozen path
dll_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib', dll_name)
dll_path = os.path.join(os.path.dirname(os.path.realpath(kpclibpy_path[0])), 'kpclibpy', 'kpclib', 'lib', dll_name)
#print("1. ", dll_path)
if os.path.exists(dll_path):
#print("1. ", dll_path)
return dll_path

# Frozen path, dll in the same dir as the executable
dll_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), dll_name)
dll_path = os.path.join(os.path.dirname(os.path.realpath(kpclibpy_path[0])), 'kpclibpy', '..', 'kpclib', 'lib', dll_name)
#print("2. ", dll_path)
if os.path.exists(dll_path):
#print("2. ", dll_path)
return dll_path

try:
# Frozen path packed as onefile
dll_path = os.path.join(sys._MEIPASS, dll_name)
if os.path.exists(dll_path):
#print("3. ", dll_path)
return dll_path
except Exception:
pass

raise Exception('Cannot find %s' % dll_name)
raise Exception('Cannot find %s' % dll_path)

clr.AddReference(interop_dll_path('KPCLib.dll'))
clr.AddReference(interop_dll_path('SkiaSharp.dll'))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/nubia_context.py → kpclibpy/nubia_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
from nubia import context
from nubia import exceptions
from nubia import eventbus
from commands.keepass import KeePass
from kpclibpy.commands.keepass import KeePass

_keepass = KeePass()

class NubiaPassXYZContext(context.Context):
def __init__(self, *args, **kwargs):
self.keepass = _keepass
self.version = "1.0.9"
self.version = "1.1.0"
self._current_group = None
super().__init__()

Expand Down
4 changes: 2 additions & 2 deletions src/nubia_plugin.py → kpclibpy/nubia_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#

import argparse
from nubia_context import NubiaPassXYZContext
from nubia_statusbar import NubiaPassXYZStatusBar
from kpclibpy.nubia_context import NubiaPassXYZContext
from kpclibpy.nubia_statusbar import NubiaPassXYZStatusBar
from nubia import PluginInterface, CompletionDataSource
from nubia.internal.blackcmd import CommandBlacklist

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/tests/db_test.py → kpclibpy/tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@pytest.mark.order(1)
def test_version(pxshell):
version = pxshell.run_interactive_line('version')
assert version == "1.0.9"
assert version == "1.1.0"


@pytest.mark.order(2)
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[options]
packages =
kpclibpy
kpclibpy.commands
kpclibpy.commands.entry
kpclibpy.commands.group
kpclibpy.kpclib
python_requires = >=3.6
install_requires=
pycparser==2.20
pythonnet==2.5.2
python-nubia==0.2b5
setup_requires =
setuptools_scm >= 1.15
include_package_data = True

[options.entry_points]
console_scripts =
keepass = kpclibpy.__main__:main
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

setup(
name="kpclibpy",
version="1.0.9",
version="1.1.0",
description="KeePass command line application",
url="https://github.com/passxyz/KPCLibPy",
license="MIT",
author="Roger Ye",
author_email="[email protected]",
package_dir={"": "src"},
packages=find_packages(where="src"),
#package_dir={"": "src"},
#packages=find_packages(where="src"),
#package_data={'kpclibpy.kpclib': ['lib/*.dll']},
install_requires=["pycparser==2.20",
"pythonnet==2.5.2",
"python-nubia==0.2b5"],
Expand Down

0 comments on commit 2149d70

Please sign in to comment.