Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor all the things! Turn into a module and use setuptools.
Refactor into a module + switching to using setuptools with entrypoints.
- Loading branch information
Showing
5 changed files
with
142 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# kittypack: Grabs package info off archlinux.org/packages | ||
# Copyright (C) 2012 Øyvind 'Mr.Elendig' Heggstad | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
|
||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
# Various formaters etc for kittypack | ||
import curtsies | ||
import re | ||
|
||
def template_output(pkg): | ||
""" Creates a output string from a package | ||
:parmans pkg: dict like object describing a package | ||
:returns string | ||
""" | ||
template = ("{repo}/{arch}/{pkgname} {epoch}:{pkgver}-{pkgrel}{ood}\n" | ||
" Updated: {last_update} Built: {build_date}") | ||
data = {} | ||
data["repo"] = curtsies.fmtstr(pkg["repo"], fg="magenta", bold=True) | ||
data["arch"] = curtsies.fmtstr(pkg["arch"], fg="yellow", bold=True) | ||
data["pkgname"] = curtsies.fmtstr(pkg["pkgname"], fg="green", bold=True) | ||
if pkg["flag_date"]: | ||
ver_colour = "red" | ||
data["ood"] = curtsies.fmtstr(" <!>", fg=ver_colour) | ||
else: | ||
ver_colour = "green" | ||
data["ood"] = "" | ||
for itm in ("epoch", "pkgver", "pkgrel"): | ||
# fmtstr doesn't like ints | ||
data[itm] = curtsies.fmtstr(str(pkg[itm]), fg=ver_colour, bold=True) | ||
data["last_update"] = pkg["last_update"] | ||
data["build_date"] = pkg["build_date"] | ||
return template.format(**data) | ||
|
||
|
||
def format_output(fstring, pkg): | ||
""" Creates a output string from a format string naively | ||
:params fstring: format string | ||
:parmans pkg: dict like object describing a package | ||
:returns string | ||
""" | ||
lookup = { | ||
"%a": "arch", | ||
"%B": "build_date", | ||
"%b": "pkgbase", | ||
"%C": "compressed_size", | ||
"%c": "conflicts", | ||
"%D": "depends", | ||
"%d": "pkgdesc", | ||
"%e": "epoch", | ||
"%f": "filename", | ||
"%f": "flag_date", | ||
"%g": "groups", | ||
"%I": "installed_size", | ||
"%L": "licenses", | ||
"%l": "pkgrel", | ||
"%M": "mainainers", | ||
"%n": "pkgname", | ||
"%p": "packager", | ||
"%P": "provides", | ||
"%R": "replaces", | ||
"%r": "repo", | ||
"%U": "last_updated", | ||
"%u": "url", | ||
"%v": "pkgver", | ||
} | ||
|
||
tokens = set(re.findall('(%.)', fstring)) | ||
for token in tokens: | ||
if token == "%%": | ||
fstring = re.sub("%%", "%", fstring) | ||
else: | ||
fstring = re.sub(token, str(pkg[lookup[token]]), fstring) | ||
return fstring | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import distutils.core | ||
|
||
distutils.core.setup( | ||
name='kittypack', | ||
version='0.2', | ||
description='A silly little tool to get info from archlinux.org/packages', | ||
author="Øyvind 'Mr.Elendig' Heggstad", | ||
author_email='mrelendig@har-ikkje.net', | ||
url='https://github.com/MrElendig/kittypack', | ||
scripts=['bin/kittypack'], | ||
data_files=[('/etc/', ['conf/kittypack.conf'])] | ||
# kittypack: Grabs package info off archlinux.org/packages | ||
# Copyright (C) 2012 Øyvind 'Mr.Elendig' Heggstad | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero 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 Affero General Public License for more details. | ||
|
||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name="kittypack", | ||
version="0.2.1", | ||
description="A silly little tool to get info from archlinux.org/packages", | ||
url="https://github.com/MrElendig/kittypack", | ||
author="Øyvind \"Mr.Elendig\" Heggstad", | ||
author_email="mrelendig@har-ikkje.net", | ||
license="AGPLv3", | ||
classifiers=[ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: System Administrators", | ||
"Intended Audience :: End Users/Desktop", | ||
"License :: OSI Approved :: GNU Affero General Public License v3", | ||
"Programming Language :: Python :: 3.5", | ||
"Environment :: Console" | ||
], | ||
|
||
keywords="sample setuptools development", | ||
packages=["kittypack"], | ||
install_requires=["docopt", "requests", "pyyaml", "curtsies", | ||
"setuptools"], | ||
package_data={ | ||
"kittypack": ["kittypack.conf"], | ||
}, | ||
entry_points={ | ||
"console_scripts": [ | ||
"kittypack=kittypack.app:main", | ||
], | ||
}, | ||
) |