Coder Social home page Coder Social logo

gnebbia / kb Goto Github PK

View Code? Open in Web Editor NEW
3.1K 59.0 103.0 17.88 MB

A minimalist command line knowledge base manager

License: GNU General Public License v3.0

Makefile 0.29% Python 94.69% Shell 3.74% Ruby 1.29%
knowledge cheatsheets procedures methodology pentest-tool knowledge-base rtfm notes notes-management-system cli

kb's Introduction

kb. A minimalist knowledge base manager

Build Status

Author: gnc [email protected]

Copyright: © 2020, gnc

Date: 2022-09-21

Version: 0.1.7

Table of Contents

Purpose

kb is a text-oriented minimalist command line knowledge base manager. kb can be considered a quick note collection and access tool oriented toward software developers, penetration testers, hackers, students or whoever has to collect and organize notes in a clean way. Although kb is mainly targeted on text-based note collection, it supports non-text files as well (e.g., images, pdf, videos and others).

The project was born from the frustration of trying to find a good way to quickly access my notes, procedures, cheatsheets and lists (e.g., payloads) but at the same time, keeping them organized. This is particularly useful for any kind of student. I use it in the context of penetration testing to organize pentesting procedures, cheatsheets, payloads, guides and notes.

I found myself too frequently spending time trying to search for that particular payload list quickly, or spending too much time trying to find a specific guide/cheatsheet for a needed tool. kb tries to solve this problem by providing you a quick and intuitive way to access knowledge.

In few words kb allows a user to quickly and efficiently:

  • collect items containing notes,guides,procedures,cheatsheets into an organized knowledge base;
  • filter the knowledge base on different metadata: title, category, tags and others;
  • visualize items within the knowledge base with (or without) syntax highlighting;
  • grep through the knowledge base using regexes;
  • import/export an entire knowledge base;

Basically, kb provides a clean text-based way to organize your knowledge.

Installation

You should have Python 3.6 or above installed.

To install the most recent stable version of kb just type:

pip install -U kb-manager

If you want to install the bleeding-edge version of kb (that may have some bugs) you should do:

git clone https://github.com/gnebbia/kb
cd kb
pip install -r requirements.txt
python setup.py install

# or with pip
pip install -U git+https://github.com/gnebbia/kb

Tip for GNU/Linux and MacOS users: For a better user experience, also set the following kb bash aliases:

cat <<EOF > ~/.kb_alias
alias kbl="kb list"
alias kbe="kb edit"
alias kba="kb add"
alias kbv="kb view"
alias kbd="kb delete --id"
alias kbg="kb grep"
alias kbt="kb list --tags"
EOF
echo "source ~/.kb_alias" >> ~/.bashrc
source ~/.kb_alias

Please remember to upgrade kb frequently by doing:

pip install -U kb-manager

Installation from AUR

Arch Linux users can install kb or kb-git with their favorite AUR Helper.

Stable:

yay -S kb

Dev:

yay -S kb-git

Installation from pkgsrc

Of course it runs on NetBSD (and on pkgsrc). We can install it from pkgsrc source tree (databases/py-kb) or as a binary package using pkgin:

pkgin in py38-kb

Note that at the moment the package is only available from -current repositories.

Installation with homebrew

To install using homebrew, use:

brew tap gnebbia/kb https://github.com/gnebbia/kb.git
brew install gnebbia/kb/kb

To upgrade with homebrew:

brew update
brew upgrade gnebbia/kb/kb

Notes for Windows users

Windows users should keep in mind these things:

  • DO NOT USE notepad as %EDITOR%, kb is not compatible with notepad, a reasonable alternative is notepad++;
  • %EDITOR% variable should ALWAYS be enclosed within double quotes;
EDITOR=C:\Program Files\Editor\my cool editor.exe      -> WRONG!
EDITOR="C:\Program Files\Editor\my cool editor.exe"    -> OK!

To set the "EDITOR" Environment variable by using cmd.exe, just issue the following commands, after having inserted the path to your desired text editor:

set EDITOR="C:\path\to\editor\here.exe"
setx EDITOR "\"C:\path\to\editor\here.exe\""

To set the "EDITOR" Environment variable by using Powershell, just issue the following commands, after having inserted the path to your desired text editor:

$env:EDITOR='"C:\path\to\editor\here.exe"'
[System.Environment]::SetEnvironmentVariable('EDITOR','"C:\path\to\editor\here.exe"', [System.EnvironmentVariableTarget]::User)

Setting Aliases for cmd

Open a cmd.exe terminal with administrative rights and paste the following commands:

reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor" /v "AutoRun" /t REG_EXPAND_SZ /d "%USERPROFILE%\autorun.cmd"
(
echo @echo off
echo doskey kbl=kb list $*
echo doskey kbe=kb edit $*
echo doskey kba=kb add $*
echo doskey kbv=kb view $*
echo doskey kbd=kb delete --id $*
echo doskey kbg=kb grep $*
echo doskey kbt=kb list --tags $*
)> %USERPROFILE%\autorun.cmd

Setting Aliases for Powershell

Open a Powershell terminal and paste the following commands:

@'
function kbl { kb list $args }
function kbe { kb edit $args }
function kba { kb add  $args }
function kbv { kb view $args }
function kbd { kb delete --id $args }
function kbg { kb grep $args }
function kbt { kb list --tags $args }
'@ >  $env:USERPROFILE\Documents\WindowsPowerShell\profile.ps1

Docker

A docker setup has been included to help with development.

To install and start the project with docker:

docker-compose up -d
docker-compose exec kb bash

The container has the aliases included in its .bashrc so you can use kb in the running container as you would if you installed it on the host directly. The ./docker/data directory on the host is bound to /data in the container, which is the image's working directly also. To interact with the container, place (or symlink) the files on your host into the ./docker/data directory, which can then be seen and used in the /data directory in the container.

Usage

A quick demo of a typical scenario using kb:

A quick demo with kb aliases enabled:

A quick demo for non-text documents:

List artifacts

List all artifacts contained in the kb knowledge base

kb list

# or if aliases are used:
kbl

List all artifacts containing the string "zip"

kb list zip

# or if aliases are used:
kbl zip

List all artifacts belonging to the category "cheatsheet"

kb list --category cheatsheet
# or
kb list -c cheatsheet

# or if aliases are used:
kbl -c cheatsheet

List all the artifacts having the tags "web" or "pentest"

kb list --tags "web;pentest"

# or if aliases are used:
kbl --tags "web;pentest"

List using "verbose mode"

kb list -v

# or if aliases are used:
kbl -v

Add artifacts

Add a file to the collection of artifacts

kb add ~/Notes/cheatsheets/pytest

# or if aliases are used:
kba ~/Notes/cheatsheets/pytest

Add a file to the artifacts

kb add ~/ssh_tunnels --title pentest_ssh --category "procedure" \
    --tags "pentest;network" --author "gnc" --status "draft"

Add all files contained in a directory to kb

kb add ~/Notes/cheatsheets/general/* --category "cheatsheet"

Create a new artifact from scratch

kb add --title "ftp" --category "notes" --tags "protocol;network"
# a text editor ($EDITOR) will be launched for editing

Create a new artifact from the output of another program

kb add --title "my_network_scan" --category "scans" --body "$(nmap -T5 -p80 192.168.1.0/24)"

Delete artifacts

Delete an artifact by ID

kb delete --id 2

# or if aliases are used:
kbd 2

Delete multiple artifacts by ID

kb delete --id 2 3 4

# or if aliases are used:
kbd 2 3 4

Delete an artifact by name

kb delete --title zap --category cheatsheet

View artifacts

View an artifact by id

kb view --id 3
# or
kb view -i 3
# or 
kb view 3

# or if aliases are used:
kbv 3

View an artifact by name

kb view --title "gobuster"
# or
kb view -t "gobuster"
# or
kb view gobuster

View an artifact without colors

kb view -t dirb -n

View an artifact within a text-editor

kb view -i 2 -e

# or if aliases are used:
kbv 2 -e

Edit artifacts

Editing artifacts involves opening a text editor. Hence, binary files cannot be edited by kb.

The editor can be set by the "EDITOR" environment variable.

Edit an artifact by id

kb edit --id 13
# or
kbe 13
# or if aliases are used:
kbe 13 

Edit an artifact by name

kb edit --title "git" --category "cheatsheet"
# or
kb edit -t "git" -c "cheatsheet"
# or if git is unique as artifact
kb edit git

Grep through artifacts

Grep through the knowledge base

kb grep "[bg]zip"

# or if aliases are used:
kbg "[bg]zip"

Grep (case-insensitive) through the knowledge base

kb grep -i "[BG]ZIP"

Grep in "verbose mode" through the knowledge base

kb grep -v "[bg]zip"

Grep through the knowledge base and show matching lines

kb grep -m "[bg]zip"

Import/Export/Erase a knowledge base

Export the current knowledge base

To export the entire knowledge base, do:

kb export

This will generate a .kb.tar.gz archive that can be later be imported by kb.

If you want to export only data (so that it can be used in other software):

 kb export --only-data

This will export a directory containing a subdirectory for each category and within these subdirectories we will have all the artifacts belonging to that specific category.

Import a knowledge base

kb import archive.kb.tar.gz

NOTE: Importing a knowledge base erases all the previous data. Basically it erases everything and imports the new knowledge base.

Erase the entire knowledge base

kb erase

Manage Templates

kb supports custom templates for the artifacts. A template is basically a file using the "toml" format, structured in this way:

TITLES   = [ "^#.*", "blue",  ]
WARNINGS = [ "!.*" , "yellow",]
COMMENTS = [ ";;.*", "green", ]

Where the first element of each list is a regex and the second element is a color.

Note that by default an artifact is assigned with the 'default' template, and this template can be changed too (look at "Edit a template" subsection).

List available templates

To list all available templates:

kb template list

To list all the templates containing the string "theory":

kb template list "theory"

Create a new template

Create a new template called "lisp-cheatsheets", note that an example template will be put as example in the editor.

kb template new lisp-cheatsheets

Delete a template

To delete the template called "lisp-cheatsheets" just do:

kb template delete lisp-cheatsheets

Edit a template

To edit the template called "listp-cheatsheets" just do:

kb template edit lisp-cheatsheets

Add a template

We can also add a template from an already existing toml configuration file by just doing:

kb template add ~/path/to/myconfig.toml --title myconfig

Change template for an artifact

We can change the template for an existing artifact by ID by using the update command:

kb update --id 2 --template "lisp-cheatsheets"

Apply a template to all artifacts of a category

We can apply the template "lisp-cheatsheets" to all artifacts belonging to the category "lispcode" by doing:

kb template apply "lisp-cheatsheets" --category "lispcode"

Apply a template to all artifacts having zip in their title

We can apply the template "dark" to all artifacts having in their title the string "zip" (e.g., bzip, 7zip, zipper) by doing:

kb template apply "dark" --title "zip" --extended-match
# or 
kb template apply "dark" --title "zip" -m

We can always have our queries to "contain" the string by using the --extended-match option when using kb template apply.

Apply a template to all artifacts having specific properties

We can apply the template "light" to all artifacts of the category "cheatsheet" who have as author "gnc" and as status "OK" by doing:

kb template apply "light" --category "cheatsheet" --author "gnc" --status "OK"

Integrating kb with other tools

kb can be integrated with other tools.

kb and rofi

We can integrate kb with rofi, a custom mode has been developed accessible in the "misc" directory within this repository.

We can launch rofi with this mode by doing:

rofi -show kb -modi kb:/path/to/rofi-kb-mode.sh

Experimental

Synchronize kb with a remote git repository

Synchronization with a remote git repository is experimental at the moment. Anyway we can initialize our knowledge base to a created empty github/gitlab (other git service) repository by doing:

kb sync init

We can then push our knowledge base to the remote git repository with:

kb sync push

We can pull (e.g., from another machine) our knowledge base from the remote git repository with:

kb sync pull

We can at any time view to what remote endpoint our knowledge is synchronizing to with:

kb sync info

UPGRADE

If you want to upgrade kb to the most recent stable release do:

pip install -U kb-manager

If instead you want to update kb to the most recent release (that may be bugged), do:

git clone https://github.com/gnebbia/kb 
cd kb
pip install --upgrade .

FAQ

Q) How do I solve the AttributeError: module 'attr' has no attribute 's' error?

A) Uninstall attr and use attrs:

pip uninstall attr
pip uninstall attrs
pip install attrs
pip install -U kb-manager

DONATIONS

I am an independent developer working on kb in my free time, if you like kb and would like to say thank you, buy me a beer!

paypal

COPYRIGHT

Copyright 2020 Giuseppe Nebbione.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Similar projects

kb's People

Contributors

0xrin1 avatar alshapton avatar asadmoosvi avatar flipee avatar gaspar-h-v avatar gnebbia avatar pawelkuk avatar yihong0618 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kb's Issues

Question: Can we set background color in templates?

Hi,

great program, thanks for sharing!

Question

Can we use background from?

For example:

TemplateFileXY:
ERRORS = [ "^!.*", "light_red", "light_yellow"]

Expected Behavior

Display light red text on light yellow background for lines beginning with "!".

Actual Behavior

Displays red text on terminal's current background.

Specifications

  • Version: kb v.0.1.6
  • Platform: Windows 10.0.19042

Thanks!

BR
Tomo

SyntaxError: invalid syntax

Expected Behavior

work

Actual Behavior

not work

Steps to Reproduce the Problem

1.install kb
2.kb --version

Specifications

  • Version: 0.1.4
  • Platform: LInux
  • Subsystem: ubuntu16.04

File "/home/xx/env_python3/lib/python3.5/site-packages/kb_manager-0.1.4-py3.5.egg/kb/entities/artifact.py", line 20
id: Optional[int]
^
SyntaxError: invalid syntax

Code Page issue on Windows

Expected Behavior

Using: pip install -U kb-manager
or pip install -U git+https://github.com/gnebbia/kb

I expected to have kb installed

Actual Behavior

There is an error related to the code page:

Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\python27\lib\site-packages\pip\__init__.py", line 28, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "c:\python27\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
    from pip.download import path_to_url
  File "c:\python27\lib\site-packages\pip\download.py", line 37, in <module>
    from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
  File "c:\python27\lib\site-packages\pip\utils\ui.py", line 57, in <module>
    _BaseBar = _select_progress_class(IncrementalBar, Bar)
  File "c:\python27\lib\site-packages\pip\utils\ui.py", line 50, in _select_progress_class
    six.text_type().join(characters).encode(encoding)
LookupError: unknown encoding: cp65001

Steps to Reproduce the Problem

  1. At the Windows command prompt.
  2. Use either:

Specifications

  • Version: Unknown - current
  • Platform: Windows 10
  • Subsystem:

Some points about the experimental git integration

I recently discovered this tool and thought it could be an idea to get rid of my various text files :D Well, I'll see how it will work out.
While tinkering with the tool I tried the experimental sync feature via git. And noticed some points (didn't look at the source yet, so maybe my observations are wrong)

  1. branch name main seems to be hardcoded? Causes issues with pushing, if git still creates master or whatever as the main branch as default
  2. every kb sync push creates a commit

regarding 1.:
Remote (and local, but that I discovered later) repo had a different branchname, which caused the following error:

Create a remote empty repository on github/gitlab or other git provider...
Insert the URL of the created empty remote repo (e.g., https://github/user/mykb): Clio:Backup/Repository/kb.git
Initialization with remote may take time...
Please provide remote credentials and wait...
Traceback (most recent call last):
  File "/usr/bin/kb", line 33, in <module>
    sys.exit(load_entry_point('kb-manager==0.1.6', 'console_scripts', 'kb')())
  File "/usr/lib/python3.9/site-packages/kb/main.py", line 66, in main
    dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
  File "/usr/lib/python3.9/site-packages/kb/main.py", line 56, in dispatch
    return COMMANDS[function](*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/kb/commands/sync.py", line 46, in sync
    git_init(config["PATH_KB"])
  File "/usr/lib/python3.9/site-packages/kb/commands/sync.py", line 126, in git_init
    remote.push(refspec='{}:{}'.format("main", "main"))
  File "/usr/lib/python3.9/site-packages/git/remote.py", line 848, in push
    return self._get_push_info(proc, progress)
  File "/usr/lib/python3.9/site-packages/git/remote.py", line 735, in _get_push_info
    proc.wait(stderr=stderr_text)
  File "/usr/lib/python3.9/site-packages/git/cmd.py", line 408, in wait
    raise GitCommandError(self.args, status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push --porcelain origin main:main
  stderr: 'error: src refspec main does not match any
error: failed to push some refs to 'Clio:Backup/Repository/kb.git''

After changing it on the remote if failed again. Because the local repo also had a different branchname from what the program assumed/expected:

~ $ kb sync push
zsh: correct 'sync' to 'Sync' [nyae]? n
Some error occured while pushing the code
Check your internet connection or the existence of the remote repository 

regarding 2.: It shouldn't create a commit which then gets pushed, if there is no change in the local repo.
Additional thought about this: When should the commit be created? Either after every add, edit or whatever operation changes the local state in the repo. Or stay with the current implementation. Personally I like the first. Which I luckily can do even if you don't want to change the behaviour, which would be perfectly fine.

Missing Package: Metadata

Expected Behavior

expected 'kb list' to list execute.

Actual Behavior

The following error was raised:

Traceback (most recent call last):
  File "/usr/bin/kb", line 33, in <module>
    sys.exit(load_entry_point('kb==0.1.1', 'console_scripts', 'kb')())
  File "/usr/bin/kb", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.8/importlib/metadata.py", line 504, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.8/importlib/metadata.py", line 177, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: kb

I expect that there is an additional requirement that needs to be specified? This running on Ubuntu 20.04.

Add homebrew support

Loosely related to #15.

I've created Homebrew tap with kb formula. I'd be happy to transfer this file (or even repo since there's only kb.rb there now) to you if you want. For now, with no pip package, it takes package from a repo.

Repo url: https://github.com/kgadek/homebrew-tools

Installation procedure using repo (tested on macOS):

brew tap kgadek/tools
brew install kgadek/tools/kb

Note: I'm definitely not an expert in Homebrew. It seems to work but definitely could get improvements. E.g. it doesn't pass brew audit ("1: col 1: Missing frozen string literal comment").

EDITOR on windows not being set

Expected Behavior

kb add opens the editor set in the EDITOR env var

Actual Behavior

Call to open editor fails, looking at code Im not seeing where it looks for env var it appears to use default config always which would point to vim?

Steps to Reproduce the Problem

  1. kb add --title "test" --category "note" --tags "test;firstnote"

Specifications

  • Version: 0.1.6
  • Platform: windows
  • Subsystem:

Error when deleting by title from command line

Expected Behavior

The artefact should have been deleted

Actual Behavior

Traceback (most recent call last):
File "/usr/local/bin/kb", line 33, in
sys.exit(load_entry_point('kb-manager', 'console_scripts', 'kb')())
File "/Users/shaptona/MyProjects/kb/kb/main.py", line 62, in main
dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
File "/Users/shaptona/MyProjects/kb/kb/main.py", line 54, in dispatch
return COMMANDS[function](*args, **kwargs)
File "/Users/shaptona/MyProjects/kb/kb/commands/delete.py", line 50, in delete
print("Artifact {id} removed!".format(args["id"]))
KeyError: 'id'

Steps to Reproduce the Problem

  1. kb delete -t <title>

Specifications

  • Version: 0.1.5
  • Platform:MacOS
  • Subsystem:

XDG Compliance

Expected Behavior

Puts kb data in "${XDG_DATA_HOME:-$HOME/.local/share}/kb"

It would be great to follow the XDG Base Directory Specification and place application
data files in $XDG_DATA_HOME/kb, if it exists, and fall back to $HOME/.local/share/kb if that environment variable does not exist. It was mentioned offhand in this thread, but I would like to make an issue to address this :)

Actual Behavior

kb data put in ~/.kb.

Steps to Reproduce the Problem

Execute a kb command

Specifications

  • Version: 0.1.5
  • Platform: Linux
  • Subsystem: Arch

Create a new knowledge base

Expected Behavior

I believe that a function like kb --init would be advantageous to create a new knowledgeable, when someone who wishes to erase a knowledgeable and create a new one from scratch

Updating status updates author instead

Expected Behavior

I tried to update the status of a document

Actual Behavior

The Author was updated instead

Steps to Reproduce the Problem

  1. Added a file with a status of 'open'
  2. Ran >kb update --id 2 -s closed
  3. Did a verbose list and saw the author was 'closed' and the status was still 'open'

Specifications

  • Version: 0.12
  • Platform: Windows 10
  • Subsystem:

AttributeError: 'str' object has no attribute 'mkdir'

Hi,

I am getting the following error

$ kb add test Traceback (most recent call last): File "/usr/local/bin/kb", line 11, in <module> load_entry_point('kb==0.1.1', 'console_scripts', 'kb')() File "/usr/local/lib/python3.6/site-packages/kb-0.1.1-py3.6.egg/kb/main.py", line 62, in main dispatch(cmd, cmd_params, config=DEFAULT_CONFIG) File "/usr/local/lib/python3.6/site-packages/kb-0.1.1-py3.6.egg/kb/main.py", line 52, in dispatch return COMMANDS[function](*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/kb-0.1.1-py3.6.egg/kb/commands/add.py", line 50, in add initializer.init(config) File "/usr/local/lib/python3.6/site-packages/kb-0.1.1-py3.6.egg/kb/initializer.py", line 37, in init create_kb_files(config) File "/usr/local/lib/python3.6/site-packages/kb-0.1.1-py3.6.egg/kb/initializer.py", line 63, in create_kb_files kb_path.mkdir(parents=True, exist_ok=True) AttributeError: 'str' object has no attribute 'mkdir'

From what I can see in config.py these are indeed strings not "Path" objects

Running on RedHat 7.8

Linux xxx 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 11 19:12:04 EDT 2020 x86_64 x86_64 x86_64 GNU/Linux

Please clarify the license this software is released under

Great job releasing this! It'll help a lot of people.

A quest question, there appear to be two licenses. One in the README and one in the LICENSE file. It's not clear whether this is released under BSD, GPLv3, or dual license. Can this be clarified? Thanks!

Expected Behavior

Single license

Actual Behavior

Two licenses

Steps to Reproduce the Problem

  1. Read the bottom of the README, see something that is or looks like 3-clause BSD
  2. Read LICENSE file, see GPLv3

Can we update category/tags after it's created?

I think it's nice if we can update it.
Also, I think it will be more convenient if the title/category/tags are included inside the note as well, so we don't need to specify title/category/tags in the command line when we add a new note, and we can update it easily when we want later.

So I imagine a flow like this:

  1. Adding new note: type kba, this will open a new file in the $EDITOR will the following structure:
# title: 
# category:
# tags:

Then we can add it there, it's nice to be able to add it in the editor, instead of from the command line

  1. Edit old note: type kbe 0, this will open the note, and allow us to update everything, from the content to title/category/tags

`add` and `edit` commands error if $EDITOR set to "vim -u ~/my-vimrc"

Expected Behavior

add and edit commands work.

Actual Behavior

add and edit commands don't work if $EDITOR is set to "vim -u ~/my-vimrc", but work if set to just "vim".

$ echo "${EDITOR}"
vim -u ~/my-vimrc

$ kb add -t 'test title test'
Traceback (most recent call last):
  File "/usr/local/bin/kb", line 33, in <module>
    sys.exit(load_entry_point('kb==0.1.1', 'console_scripts', 'kb')())
  File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/main.py", line 62, in main
    dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
  File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/main.py", line 52, in dispatch
    return COMMANDS[function](*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/commands/add.py", line 71, in add
    call([config["EDITOR"], Path(category_path, title)])
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'vim -u ~/my-vimrc'

Problems seem to be at the line call([config["EDITOR"], Path(category_path, title)]) in kb/commands/add.py and kb/commands/view.py.

Steps to Reproduce the Problem

touch ~/my-vimrc
EDITOR="vim -u ~/my-vimrc" kb add -t 'new title'
EDITOR="vim -u ~/my-vimrc" kb view -t 'new title'

Specifications

  • Version: Python 3.8.5
  • Platform: macOS Catalina 10.15.6
  • Subsystem: N/A

Android app

This is just an idea.

I'm self hosting most of my stuff. It would be great to be able to use kb from an Android phone.

We could sync the sqlite database using something like Syncthing, but I wonder if that could generate some problems if the database is modified by two devices at the same time...

Exception thrown for `kb view --id 90` when 90 does not exist

Expected Behavior

I'd probably expect nothing to return.

Actual Behavior

Traceback (most recent call last):
  File "/usr/local/bin/kb", line 33, in <module>
    sys.exit(load_entry_point('kb', 'console_scripts', 'kb')())
  File "/Users/jake.robers/Code/kb/kb/main.py", line 62, in main
    dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
  File "/Users/jake.robers/Code/kb/kb/main.py", line 52, in dispatch
    return COMMANDS[function](*args, **kwargs)
  File "/Users/jake.robers/Code/kb/kb/commands/view.py", line 60, in view
    artifact = db.get_artifact_by_id(conn, artifact_id)
  File "/Users/jake.robers/Code/kb/kb/db.py", line 210, in get_artifact_by_id
    return Artifact(*cur.fetchall().pop())
IndexError: pop from empty list

Steps to Reproduce the Problem

View an archive that does not exist on your system.

  1. kb view --id 90 # 90 does not exist on my machine.

[request] Interactive mode with FZF integration would be sweet

Hi there. I've been using kb for a while now and I love it. But I recently tried to use it with fzf and bat and I was unsucessful. I simply tried calling a shell function like:

k() { kb list | fzf --preview 'bat {}' | kb view "$@" }

or

k() { kb list | fzf --preview 'kb view "$@" | bat -p {}' }

or something to that effect.

I'm a bit of a novice so I really dont know if it'll work without patching kb itself.

Do you think this might be possible to create an interactive kb function?

Distributed API to use kb (kb as a service)

I see that in the TODO list, there is kb as a service.

I'm in the middle of developing a very basic REST API which could suffice.

If you're interested in allowing me to continue this until a first Proof of Concept version works, then we can discuss if it is the correct direction ?

Great product, and great code too ! Thanks

Un-named buffer on creating a new note

Expected Behavior

Vim should create a buffer with a name so that it can be saved after writing the note.

Actual Behavior

When creating a new note, for example,
kb add --title "ftp" --category "notes" --tags "protocol;network"
Vim created an un-named buffer, the note cannot be saved.

Specifications

  • Platform: Mac OS 10.15.5

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 10: invalid continuation byte

Expected Behavior

trying to open pdf

Actual Behavior

Traceback (most recent call last):
File "/usr/local/bin/kb", line 33, in
sys.exit(load_entry_point('kb==0.1.1', 'console_scripts', 'kb')())
File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/main.py", line 62, in main
dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/main.py", line 52, in dispatch
return COMMANDS[function](*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/commands/view.py", line 78, in view
viewer.view(artifact_path, markers, color=color_mode)
File "/usr/local/lib/python3.8/site-packages/kb-0.1.1-py3.8.egg/kb/viewer.py", line 115, in view
content = fname.read()
File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 10: invalid continuation byte

Steps to Reproduce the Problem

1.kb add /Users/spencer/Code/pass/throwaway.pdf --title throwAway-Quote --category Project --tags "throwaway"
1.kbv 0
1.UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 10: invalid continuation byte

Specifications

  • Version: kb 0.1.0
  • Platform: Mac OS
  • Subsystem:

Asking for confirmation before deleting the artifact

Expected Behavior

When running kb delete --id some_id, It should ask for confirmation before deleting the artifact

Actual Behavior

It deletes the artifact right away

Specifications

  • Version: 0.1.6
  • Platform: Ubuntu 20.04

I think we should allow an option to specify if we want confirmation before deleting the artifact, since sometime accidently deleting an artifact can have a wreak havoc effect.

AttributeError: module 'attr' has no attribute 's'

I install all requirements and try this cmd in first,
then google error and make

$ pip uninstall attr
$ pip install attrs

didn't work for me

kb list -v
Traceback (most recent call last):
  File "/usr/local/bin/kb", line 11, in <module>
    load_entry_point('kb==0.1.1', 'console_scripts', 'kb')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2859, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2450, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2456, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.8/dist-packages/kb-0.1.1-py3.8.egg/kb/main.py", line 19, in <module>
    from kb.commands.add import add
  File "/usr/local/lib/python3.8/dist-packages/kb-0.1.1-py3.8.egg/kb/commands/add.py", line 19, in <module>
    import kb.db as db
  File "/usr/local/lib/python3.8/dist-packages/kb-0.1.1-py3.8.egg/kb/db.py", line 21, in <module>
    from kb.entities.artifact import Artifact
  File "/usr/local/lib/python3.8/dist-packages/kb-0.1.1-py3.8.egg/kb/entities/artifact.py", line 18, in <module>
    @attr.s(auto_attribs=True, frozen=True, slots=True)
AttributeError: module 'attr' has no attribute 's'

Specifications

  • Platform: Linux parrot 5.7.0-2parrot2-amd64 #1 SMP Debian 5.7.10-1parrot2 (2020-07-31) x86_64 GNU/Linux

Typos discovered by codespell

% codespell . --ignore-words-list=hist --skip=./.* --quiet-level=2 || true

./README.md:60: shoud ==> should
./docs/README.md:60: shoud ==> should
./kb/filesystem.py:198: containint ==> containing
./kb/commands/grep.py:64: specied ==> specified

kb grep "IndexError: list index out of range"

Hi! It's me again. I've been working on migrating my notes into kb, and I ran across this error. I'm planning on looking into it a bit, but I wanted to open the issue first.

Expected Behavior

kb ought to display a list of artifacts containing the word, as shown in https://github.com/gnebbia/kb#grep-through-the-knowledge-base

Actual Behavior

kb throws an IndexError. This only seems to occur if the grep successfully matches an artifact. Nothing seems to change if I use the -v flag. It works if I use the -m flag to show the matching lines instead of the artifacts.

Ghostbin with full error: https://ghostbin.co/paste/tyqqos

Steps to Reproduce the Problem

  1. Run kb grep with any word that exists in the knowledge base.

Specifications

  • Version: kb-git from the AUR.
  • Platform: Arch Linux

Add "stats" functionality

Expected Behavior

New function:

stats

will return number of artefacts, number of tags, number of categories, number of authors and anything else that seems useful.

python3.6 not work

Expected Behavior

kb list or kb add work fine

Actual Behavior

kb list or kb add cause exceptions
image

I use docker-compose works fine

Steps to Reproduce the Problem

  1. using python3.6
  2. install kb
  3. kb list

Specifications

  • Version: python 3.6
  • Platform: windows
  • Subsystem: wsl1

KB contents are lost when a docker container is restarted

Expected Behavior

a docker-compose up -d, some processing of the kb in the container, a docker-compose down and then a later docker-compose up -d should have the results of your kb manipulations.

Actual Behavior

Changes to the knowledge base are not persisted.

Steps to Reproduce the Problem

  1. Start a container with docker-compose up -d
  2. Enter the container with docker-compose exec kb bash
  3. Add a note with kba ....
  4. Exit the container
  5. Stop the container with docker-compose down
  6. Restart the container with docker-compose up -d
  7. Enter the container with docker-compose exec kb bash
  8. Look for notes with kbl

Specifications

  • Version:
  • Platform:
  • Subsystem:

Edit in external editor is broken

Expected Behavior

Edit artifact in external editor (specified in the %EDITOR% env variable)

Actual Behavior

Traceback (most recent call last):
  File "__main__.py", line 20, in <module>
  File "main.py", line 62, in main
  File "main.py", line 52, in dispatch
  File "commands\edit.py", line 44, in edit
  File "commands\edit.py", line 73, in edit_by_id
  File "subprocess.py", line 304, in call
  File "subprocess.py", line 756, in __init__
  File "subprocess.py", line 1100, in _execute_child
  File "subprocess.py", line 511, in list2cmdline
TypeError: argument of type 'WindowsPath' is not iterable
[7080] Failed to execute script __main__

Steps to Reproduce the Problem

  1. Add a file as artifact
  2. Edit the file with this command: kb edit --id "number"

Specifications

  • Version: 0.1.2
  • Platform: Windows

[Bug] Program fails to gracefully handle non-existent path for new artifact

Expected Behavior

Printed error describing that the path indicated by the command doesn't exist.

Actual Behavior

Stack trace because shutil can't open a write handle to the file.

Steps to Reproduce the Problem

  1. After installing kb normally via pip and activating the aliases, run kba /doesnt/exist/path

Specifications

  • Version: 0.1.4
  • Platform: Linux
  • Subsystem: ?

Module 'attr' has no attribute 's'

Expected Behavior

Working Normally

Actual Behavior

 $ kb
Traceback (most recent call last):
  File "/usr/local/bin/kb", line 11, in <module>
    load_entry_point('kb-manager==0.1.5', 'console_scripts', 'kb')()
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/usr/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.8/site-packages/kb_manager-0.1.5-py3.8.egg/kb/main.py", line 19, in <module>
    from kb.commands.add import add
  File "/usr/local/lib/python3.8/site-packages/kb_manager-0.1.5-py3.8.egg/kb/commands/add.py", line 20, in <module>
    import kb.db as db
  File "/usr/local/lib/python3.8/site-packages/kb_manager-0.1.5-py3.8.egg/kb/db.py", line 21, in <module>
    from kb.entities.artifact import Artifact
  File "/usr/local/lib/python3.8/site-packages/kb_manager-0.1.5-py3.8.egg/kb/entities/artifact.py", line 17, in <module>
    @attr.s(auto_attribs=True, frozen=True, slots=True)
AttributeError: module 'attr' has no attribute 's'

Steps to Reproduce the Problem

  1. Install kb from pip
  2. Run kb

Specifications

  • Version: Python 3.8.6, kb 0.1.5
  • Platform: Fedora 32 SilverBlue

Have same issue? I already install both of attr and attrs package. But not solving issue.

AttributeError: module 'attr' has no attribute 's'

Expected Behavior

kb runs.

Actual Behavior

When trying to run it, there is an error:

$ kb                            
Traceback (most recent call last):
  File "/home/yala/.local/bin/kb", line 5, in <module>
    from kb.main import main
  File "/home/yala/.local/lib/python3.8/site-packages/kb/main.py", line 19, in <module>
    from kb.commands.add import add
  File "/home/yala/.local/lib/python3.8/site-packages/kb/commands/add.py", line 19, in <module>
    import kb.db as db
  File "/home/yala/.local/lib/python3.8/site-packages/kb/db.py", line 21, in <module>
    from kb.entities.artifact import Artifact
  File "/home/yala/.local/lib/python3.8/site-packages/kb/entities/artifact.py", line 18, in <module>
    @attr.s(auto_attribs=True, frozen=True, slots=True)
AttributeError: module 'attr' has no attribute 's'

Steps to Reproduce the Problem

  1. Install with pip3 install -U kb-manager
  2. Run with kb

Specifications

  • Version: Python 3.8
  • Platform: Ubuntu 20.10

ModuleNotFoundError: No module named '_sqlite3'

Actual Behavior

$ kb list
Traceback (most recent call last):
  File "/home/dave/.local/bin/kb", line 5, in <module>
    from kb.main import main
  File "/home/dave/.local/lib/python3.7/site-packages/kb/main.py", line 19, in <module>
    from kb.commands.add import add
  File "/home/dave/.local/lib/python3.7/site-packages/kb/commands/add.py", line 19, in <module>
    import kb.db as db
  File "/home/dave/.local/lib/python3.7/site-packages/kb/db.py", line 16, in <module>
    import sqlite3
  File "/usr/pkg/lib/python3.7/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/pkg/lib/python3.7/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

Steps to Reproduce the Problem

  1. Install using pip install -U kb-management
  2. Run kb list

Specifications

  • Version: python 3.7
  • Platform: NetBSD

FYI

I did get this notice when installing, but I fixed my path.

Using legacy 'setup.py install' for attr, since package 'wheel' is not installed.
Using legacy 'setup.py install' for colored, since package 'wheel' is not installed.
Installing collected packages: attr, colored, attrs, toml, kb-manager
    Running setup.py install for attr ... done
    Running setup.py install for colored ... done
  WARNING: The script kb is installed in '/home/dave/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-lo
Successfully installed attr-0.3.1 attrs-20.3.0 colored-1.4.2 kb-manager-0.1.5 toml-0.10.2

Error when using "kb grep -m something"

Expected Behavior

Get the result of the grep with detailed search results

Actual Behavior

Got an exception :
Traceback (most recent call last):
File "/home/antoine/.pyenv/versions/3.7.5/bin/kb", line 11, in
load_entry_point('kb-manager==0.1.5', 'console_scripts', 'kb')()
File "/home/antoine/.pyenv/versions/3.7.5/lib/python3.7/site-packages/kb_manager-0.1.5-py3.7.egg/kb/main.py", line 64, in main
dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
File "/home/antoine/.pyenv/versions/3.7.5/lib/python3.7/site-packages/kb_manager-0.1.5-py3.7.egg/kb/main.py", line 54, in dispatch
return COMMANDS[function](*args, **kwargs)
File "/home/antoine/.pyenv/versions/3.7.5/lib/python3.7/site-packages/kb_manager-0.1.5-py3.7.egg/kb/commands/grep.py", line 66, in grep
printer.print_grep_matches(artifact_names)
TypeError: print_grep_matches() missing 1 required positional argument: 'hits_list'

Steps to Reproduce the Problem

  1. Simply use the command, I think...

Specifications

  • Version: 0.1.5
  • Platform: Linux
  • Subsystem: Ubuntu 20.04

Build a vscode Extension

Hi there, i find the product through @yihong0618 on twitter, and it's fantastic. I was wondering if you could build a vscode extension. Considering the popularity of vscode , the product will be a smash-hit when the extension releases.

Possible README error

Expected Behavior

kb Add launches editor

Actual Behavior

kb add fails to find editor

Steps to Reproduce the Problem

1.follow instructions to install for windows powershell
$env:EDITOR="C:\path\to\editor\here.exe"
[System.Environment]::SetEnvironmentVariable('EDITOR','"C:\path\to\editor\here.exe"', [System.EnvironmentVariableTarget]::User)

This appears to be missing the ' on the first line
I could not make it work until I added single quotes
$env:EDITOR='"C:\path\to\editor\here.exe"'

I am using notepad++ installed to C:Program Files\Notepad++

Specifications

  • Version:1.6
  • Platform:Windows
  • Subsystem:

Creating a new KB artifact from scratch fails on Windows 10

Expected Behavior

kb add --title "ftp" --category "notes" --tags "protocol;network"

brings up an editor

Actual Behavior

C:\Users\Uwe>kb add --title "ftp" --category "notes" --tags "protocol;network"
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\kb.exe_main
.py", line 7, in
File "c:\anaconda3\lib\site-packages\kb\main.py", line 64, in main
dispatch(cmd, cmd_params, config=DEFAULT_CONFIG)
File "c:\anaconda3\lib\site-packages\kb\main.py", line 54, in dispatch
return COMMANDS[function](*args, **kwargs)
File "c:\anaconda3\lib\site-packages\kb\commands\add.py", line 80, in add
call(shell_cmd)
File "c:\anaconda3\lib\subprocess.py", line 339, in call
with Popen(*popenargs, **kwargs) as p:
File "c:\anaconda3\lib\subprocess.py", line 800, in init
restore_signals, start_new_session)
File "c:\anaconda3\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden (cannot find the specified file)

Steps to Reproduce the Problem

  1. kb add --title "ftp" --category "notes" --tags "protocol;network"

Specifications

  • Version: 0.1.5
  • Platform: Windows 10
  • Subsystem: Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Upgrade to 0.1.6 did not upgrade typing_extensions or warn about compatibility issues

Expected Behavior

kb list
.... stuff

Actual Behavior

... yadda yadda yadda
from typing_extensions import Final, Literal, SupportsIndex # noqa: F401
ImportError: cannot import name 'SupportsIndex' frohm 'typing_extensions'

Steps to Reproduce the Problem

Specifications

  • Version: 0.1.8
  • Platform: Windows 10
  • Subsystem:

Note: I did resolve this by upgrading typing_extensions from 3.7.4 to 3.10.0.2

[request] use bat instead of cat

Is it possible to configure kb to use bat instead of cat when viewing notes and cheatsheets? for large files this will allow for easy scrolling.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.