Skip to content

Commit

Permalink
gentodo: 1.1.0
Browse files Browse the repository at this point in the history
New Features:

Ability to pass commands into Gentodo to unlock the token values for
those that don't want to have secrets in plain-text.

(Note that a hardcoded token will override this)

commands.py:

- Fix PEP8 issues
- Remove unnecessary .join()
- Rename id arguments to id_

config.py:

- Add functionality for command parsing to get a token's value

main.py:

- Module doc-string

Signed-off-by: Christopher Fore <[email protected]>
  • Loading branch information
csfore committed Apr 17, 2024
1 parent 34ab0d1 commit 6aeed8f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 13 deletions.
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[gentodo]
token = "abcdefghijklmnopqrstuvqxyz"
token-cmd = "pass bugzilla 2>/dev/null | tr -d '\n'"
urls = ["https://bugs.gentoo.org/xmlrpc.cgi"]
emails = ["[email protected]"]
44 changes: 44 additions & 0 deletions gentodo-1.1.0.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{10..12} )

DISTUTILS_USE_PEP517=setuptools
inherit python-r1 distutils-r1 bash-completion-r1

if [[ ${PV} == 9999* ]] ; then
inherit git-r3
EGIT_REPO_URI="https://github.com/csfore/gentodo.git"
else
SRC_URI="https://github.com/csfore/gentodo/releases/download/${PV}/gentodo-${PV}.tar.gz"
KEYWORDS="~amd64"
fi

HOMEPAGE="https://github.com/csfore/gentodo"
DESCRIPTION="Todo program to help enhance your Gentoo workflow"

LICENSE="GPL-3"
SLOT="0"

IUSE="bash-completion"

REQUIRED_USE="${PYTHON_REQUIRED_USE}"

BDEPENDS="
${PYTHON_DEPS}
"
DEPEND="
${PYTHON_DEPS}
"
RDEPEND="
${PYTHON_DEPS}
dev-python/python-bugzilla
dev-python/click
"

python_install_all() {
newbashcomp src/gentodo/gentodo-completions.bash gentodo
distutils-r1_python_install_all
}
2 changes: 1 addition & 1 deletion src/gentodo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'''__init__.py'''
__version__ = "1.0.0"
__version__ = "1.1.0"
24 changes: 12 additions & 12 deletions src/gentodo/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def show(ctx, verbose, brief):
print(f"ID | {'Title'.ljust(spaces)}| Detail")
print(f"{'─'*(spaces+14)}")
for key in ctx.obj['GENTODO'].data:
print(f"{key:<2}{ctx.obj['GENTODO'].data[key]['title'].ljust(spaces)}{ctx.obj['GENTODO'].data[key]['details']}")
print(f"{key:<2}{ctx.obj['GENTODO'].data[key]['title'].ljust(spaces)}"\
f"│ {ctx.obj['GENTODO'].data[key]['details']}")
elif brief:
print("Title".center(spaces))
print(f"{'─'*spaces}")
Expand All @@ -101,7 +102,8 @@ def show(ctx, verbose, brief):
print(f"{'Title'.ljust(spaces)}| Details")
print(f"{'─'*(spaces+9)}")
for key in ctx.obj['GENTODO'].data:
print(f"{ctx.obj['GENTODO'].data[key]['title'].ljust(spaces)}| {ctx.obj['GENTODO'].data[key]['details']}")
print(f"{ctx.obj['GENTODO'].data[key]['title'].ljust(spaces)}"\
f"| {ctx.obj['GENTODO'].data[key]['details']}")


@click.command(help="Add an item to your todo list")
Expand All @@ -114,9 +116,6 @@ def add(ctx, title, details):

newest_id = 0 if len(gentodo.data.keys()) == 0 else int(list(gentodo.data.keys())[-1])


if isinstance(title, str):
title = " ".join(title)
if len(title) > 40:
title = title[:40]
title += "..."
Expand All @@ -132,13 +131,13 @@ def add(ctx, title, details):

@click.command(name="del", help="Remove an item from the todo list")
@click.pass_context
@click.argument("id")
def rm(ctx, id):
@click.argument("id_", metavar="ID")
def rm(ctx, id_):
'''Removes an item from the todo list by ID'''
gentodo = ctx.obj['GENTODO']

if os.path.exists(TODO_FILE) and os.path.getsize(TODO_FILE) > 0:
gentodo.data.pop(f"{id}")
gentodo.data.pop(f"{id_}")
gentodo.write()

@click.command(help="Shows the number of items remaining")
Expand All @@ -153,15 +152,15 @@ def count(ctx):

@click.command(help="Edit an item by ID")
@click.pass_context
@click.argument("id")
@click.argument("id_", metavar="ID")
@click.option("-t", "--title", required=True)
@click.option("-d", "--details", default="No details")
def edit(ctx, id, title, details):
def edit(ctx, id_, title, details):
'''Edits an item entry'''
gentodo = ctx.obj['GENTODO']

gentodo.data[id]['title'] = title
gentodo.data[id]['details'] = details
gentodo.data[id_]['title'] = title
gentodo.data[id_]['details'] = details

gentodo.write()

Expand All @@ -180,6 +179,7 @@ def search(ctx, term):
if term in gentodo.data[key][val]:
print(f"{key} | {gentodo.data[key][val]}")


@click.command(name="pull", help="Pulls bugs relating to you from the Bugzilla")
@click.pass_context
@click.option("-c", "--cc", is_flag=True)
Expand Down
21 changes: 21 additions & 0 deletions src/gentodo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tomllib
import sys
import os
import subprocess

STORAGE_DIR = os.path.expanduser("~/.config/gentodo")
CONFIG_FILE = os.path.join(STORAGE_DIR, "config.toml")
Expand All @@ -17,6 +18,8 @@ def __init__(self):
with open(CONFIG_FILE, "w", encoding="utf_8") as config:
config.write("[gentodo]\n")
self.data = self.load_config()
if "token" not in self.data:
self.data['gentodo']['token'] = self.get_token_cmd()

def load_config(self):
'''Loads the config from the TOML file'''
Expand All @@ -31,6 +34,24 @@ def get_token(self):
print("API Key not found, please add it to config.toml.")
sys.exit(1)

def get_token_cmd(self):
'''Gets a token from an arbitrary command'''
try:
token_res = subprocess.run(self.data['gentodo']['token-cmd'],
stdout=subprocess.PIPE,
shell=True,
check=True)
if token_res.stdout.decode() == '':
raise ValueError("Command resulted in an empty token (invalid credentials?)")
return token_res.stdout.decode()
except ValueError as e:
print(f"Error: {e}")
sys.exit(1)
except Exception as e:
print("An unexpected error has occurred, please report this to the"\
f" Issue tracker: {e}\nhttps://github.com/csfore/gentodo/issues/new")
sys.exit(1)

def get_urls(self):
'''Gets Bugzilla URLs'''
try:
Expand Down
4 changes: 4 additions & 0 deletions src/gentodo/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'''main.py
The main entrypoint for Gentodo
'''

import click

from gentodo import commands, __version__
Expand Down

0 comments on commit 6aeed8f

Please sign in to comment.