Skip to content

Commit

Permalink
Merge pull request #6 from shugaoye/master
Browse files Browse the repository at this point in the history
Build 1.1.7
  • Loading branch information
passxyz authored Apr 17, 2021
2 parents fa94dbd + 61e9007 commit 7b39ed6
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 34 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ A Dockr image -
`docker-mono <https://github.com/shugaoye/docker-mono>`__ can be used on
Linux or Windows 10 (WSL).

Configuration
-------------

The default location for database files is at $HOME/.kpclibdb (or %USERPROFILE%\.kpclibdb on Windows). To change the default location, a configuration file kpclibpy.ini can be created in the folder $HOME/.kpclibdb.
.. code::
[DEFAULT]
homepath = {your data path}
Issues
------
On Windows platform, you may get the below error message:
Expand Down
2 changes: 1 addition & 1 deletion kpclibpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
__email__ = metadata["author-email"]
__license__ = metadata["license"]
except ModuleNotFoundError:
__version__ = "1.1.5.dev0"
__version__ = "1.1.6.dev0"
print("Debug build ", __version__)
7 changes: 4 additions & 3 deletions kpclibpy/commands/database_cmds.py
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 kpclibpy.commands.keepass import IStatusLogger, get_homepath, lsdb
from kpclibpy.commands.keepass import IStatusLogger, get_homepath, lsdb, get_username
#from KeePassLib import PwGroup, PwEntry, Collections


Expand Down Expand Up @@ -164,6 +164,7 @@ def version():
ctx = context.get_context()
en_table.add_row([colored("KPCLibPy", "yellow"), ctx.version])
en_table.add_row([colored("KPCLib", "yellow"), "{}".format(ctx.keepass.version)])
en_table.add_row([colored("PassXYZ", "yellow"), "{}".format(ctx.keepass.version1)])

if ctx.keepass.is_open():
en_table.add_row([colored("CurrentGroup", "yellow"), "{}".format(ctx.keepass.current_group)])
Expand Down Expand Up @@ -226,11 +227,11 @@ def show(items):
version()
elif items == "databases":
print("The current path: ", get_homepath())
db_table = PrettyTable(["No.", "Name"])
db_table = PrettyTable(["No.", "Username", "File Name"])
db_table.align = "l"
num = 1
for file in lsdb():
db_table.add_row([num, file])
db_table.add_row([num, get_username(file), file])
num = num + 1
print(db_table)
elif items == "help":
Expand Down
21 changes: 17 additions & 4 deletions kpclibpy/commands/keepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
from KeePassLib.Security import ProtectedString
from KeePassLib.Serialization import IOConnectionInfo
from PassXYZLib import PxDefs, PxDatabase, PxLibInfo
from PassXYZ.Services import PxKeyProvider


def get_username(filename):
return PxDefs.GetUserNameFromDataFile(filename)

def get_homepath():
config_file = str(Path.home())+'/.kpclibdb/kpclibpy.ini'

Expand Down Expand Up @@ -71,6 +75,14 @@ def __init__(self):
self._user_name = None
self.is_hidden = True

@property
def version1(self):
"""
ReadOnly property to represent the version of PassXYZ
"""
return PxKeyProvider.Version


@property
def version(self):
"""
Expand Down Expand Up @@ -332,12 +344,13 @@ def connect(self, filename, password):
"""
self._db = PxDatabase()
try:
self._db.DefaultFolder = get_homepath()
homepath = get_homepath()
self._db.DefaultFolder = homepath
self._db.Open(filename, password)
except InvalidCompositeKeyException:
except InvalidCompositeKeyException as ex:
cprint("connect: The composite key is invalid!\npath={}, file={}\n{}".format(homepath, filename, ex), "red")
self.close()
self._db = None
cprint("open: The composite key is invalid!", "red")
return

def open(self, db_path, password, logger):
Expand Down Expand Up @@ -383,4 +396,4 @@ def move_entry(self, src_entry, dst_group):
if self._db.MoveEntry(src_entry, dst_group):
print("Moved {} to {}".format(src_entry.get_Name(), dst_group.get_Name()))
else:
print("Cannot move {} to {}".format(src_entry.get_Name(), dst_group.get_Name()))
print("Cannot move {} to {}".format(src_entry.get_Name(), dst_group.get_Name()))
1 change: 1 addition & 0 deletions kpclibpy/kpclib/kpclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def interop_dll_path(dll_name):
clr.AddReference(interop_dll_path('KPCLib.dll'))
clr.AddReference(interop_dll_path('SkiaSharp.dll'))
clr.AddReference(interop_dll_path('PassXYZLib.dll'))
clr.AddReference(interop_dll_path('PassXYZ.dll'))

if __name__ == '__main__':
from KeePassLib import PwDatabase, PwGroup
Expand Down
Binary file modified kpclibpy/kpclib/lib/KPCLib.dll
Binary file not shown.
Binary file modified kpclibpy/kpclib/lib/PassXYZ.dll
100644 → 100755
Binary file not shown.
Binary file modified kpclibpy/kpclib/lib/PassXYZLib.dll
Binary file not shown.
54 changes: 28 additions & 26 deletions kpclibpy/unit_test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,47 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 1,
"id": "metallic-survey",
"metadata": {},
"outputs": [
{
"ename": "KeyError",
"evalue": "1",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-11-4d26b62fdc10>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mentries\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"README\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mentries\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mKeyError\u001b[0m: 1"
"name": "stdout",
"output_type": "stream",
"text": [
"['/home/roger_ye/KPCLibPy/kpclibpy', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '', '/home/roger_ye/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages', '/usr/local/lib/python3.7/dist-packages/IPython/extensions', '/home/roger_ye/.ipython', '/home/roger_ye/KPCLibPy/kpclibpy/..']\n"
]
}
],
"source": [
"entries = kp.find(\"README\")\n",
"entries[1]\n"
"import sys\n",
"import os\n",
"path = os.getcwd()\n",
"sys.path.append(path+\"/..\")\n",
"import kpclibpy\n",
"print(sys.path)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"id": "thermal-british",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Index\n",
"README\n"
]
}
],
"outputs": [],
"source": [
"import kpclibpy.kpclib\n",
"import PassXYZ"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "local-constant",
"metadata": {},
"outputs": [],
"source": [
"for entry in entries:\n",
" print(entries[entry].Name)"
"from PassXYZ.Services import PxKeyProvider\n",
"#print(PassXYZ.Services.PxKeyProvider.Version)"
]
},
{
Expand Down Expand Up @@ -538,9 +540,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "kpclib",
"display_name": "Python 3",
"language": "python",
"name": "kpclib"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 7b39ed6

Please sign in to comment.