mirror of
https://github.com/lilydjwg/nvchecker
synced 2025-02-03 12:01:57 +00:00
use argparse instead of tornado.options and change a few terms
This commit is contained in:
parent
59852778d0
commit
ff46f33752
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1 @@
|
||||
nvchecker.egg-info/
|
||||
versions/
|
||||
records/
|
||||
|
26
README.rst
26
README.rst
@ -6,7 +6,7 @@ Dependency
|
||||
==========
|
||||
- Python 3
|
||||
- Tornado
|
||||
- All commands used in your configuration files
|
||||
- All commands used in your version source files
|
||||
|
||||
Running
|
||||
=======
|
||||
@ -14,23 +14,23 @@ To see available options::
|
||||
|
||||
./nvchecker --help
|
||||
|
||||
Run with one or more configuration files::
|
||||
Run with one or more software version source files::
|
||||
|
||||
./nvchecker config_file_1 config_file_2 ...
|
||||
./nvchecker source_file_1 source_file_2 ...
|
||||
|
||||
You normally will like to specify some "version files"; see below.
|
||||
You normally will like to specify some "version record files"; see below.
|
||||
|
||||
Version Files
|
||||
=============
|
||||
Version files record which version of the software you know or is available. They are simple key-value pairs of ``(name, version)`` seperated by ``:`` ::
|
||||
Version Record Files
|
||||
====================
|
||||
Version record files record which version of the software you know or is available. They are simple key-value pairs of ``(name, version)`` seperated by ``:`` ::
|
||||
|
||||
fcitx: 4.2.7
|
||||
google-chrome: 27.0.1453.93-200836
|
||||
vim: 7.3.1024
|
||||
|
||||
Say you've got a version file called ``old_ver.txt`` which records all your watched software and their versions. To update it using ``nvchecker``::
|
||||
Say you've got a version record file called ``old_ver.txt`` which records all your watched software and their versions. To update it using ``nvchecker``::
|
||||
|
||||
./nvchecker --oldverfile=old_ver.txt --verfile=new_ver.txt config.ini
|
||||
./nvchecker --oldver old_ver.txt --newver new_ver.txt source.ini
|
||||
|
||||
Compare the two files for updates (assuming they are sorted alphabetically; files generated by ``nvchecker`` are already sorted)::
|
||||
|
||||
@ -40,11 +40,11 @@ Compare the two files for updates (assuming they are sorted alphabetically; file
|
||||
# show both old and new versions
|
||||
join old_ver.txt new_ver.txt | awk '$2 != $3'
|
||||
|
||||
Configuration Files
|
||||
===================
|
||||
The configuration files are in ini format. *Section names* is the name of the software. Following fields are used to tell nvchecker how to determine the current version of that software.
|
||||
Version Source Files
|
||||
====================
|
||||
The software version source files are in ini format. *Section names* is the name of the software. Following fields are used to tell nvchecker how to determine the current version of that software.
|
||||
|
||||
See ``sample_config.ini`` for an example.
|
||||
See ``sample_source.ini`` for an example.
|
||||
|
||||
Search in a Webpage
|
||||
-------------------
|
||||
|
@ -1,207 +0,0 @@
|
||||
[3to2]
|
||||
aur
|
||||
|
||||
[android-apktool]
|
||||
aur
|
||||
|
||||
[android-docs]
|
||||
aur
|
||||
|
||||
[android-ndk]
|
||||
aur
|
||||
|
||||
[android-sdk]
|
||||
aur
|
||||
|
||||
; [aufs3-util-lily-git]
|
||||
|
||||
[cgdb]
|
||||
aur
|
||||
|
||||
[coffee-script]
|
||||
aur
|
||||
|
||||
[dcron]
|
||||
aur
|
||||
|
||||
[dmg2img]
|
||||
aur
|
||||
|
||||
[dnscrypt-proxy-git]
|
||||
; my aur
|
||||
github = jedisct1/dnscrypt-proxy
|
||||
|
||||
[elflibviewer]
|
||||
aur
|
||||
|
||||
[evince-nodbus]
|
||||
cmd = LANG=C pacman -Si evince | grep -F Version | awk '{print $3}'
|
||||
|
||||
[fcitx-lilydjwg-git]
|
||||
github = fcitx/fcitx
|
||||
|
||||
[google-appengine-python]
|
||||
aur
|
||||
|
||||
; [gvim-lily]
|
||||
|
||||
[hfsprogs]
|
||||
aur
|
||||
|
||||
[kingsoft-office]
|
||||
aur
|
||||
|
||||
[latencytop]
|
||||
aur
|
||||
|
||||
[libsodium]
|
||||
aur
|
||||
|
||||
; [linux-lily]
|
||||
|
||||
; [linux-lily-headers]
|
||||
|
||||
[msdl]
|
||||
aur
|
||||
|
||||
[nautilus-dropbox]
|
||||
aur
|
||||
|
||||
[nodejs-jake]
|
||||
aur
|
||||
|
||||
[openresty-dev]
|
||||
; my aur
|
||||
url = http://openresty.org/
|
||||
regex = ngx_openresty-([\d.]+)\.tar\.gz\|
|
||||
|
||||
[perl-data-random]
|
||||
aur
|
||||
|
||||
[perl-goo-canvas]
|
||||
aur
|
||||
|
||||
[perl-gtk2-imageview]
|
||||
aur
|
||||
|
||||
[perl-gtk2-unique]
|
||||
aur
|
||||
|
||||
[perl-mouse]
|
||||
aur
|
||||
|
||||
[perl-net-dropbox-api]
|
||||
aur
|
||||
|
||||
[perl-net-oauth]
|
||||
aur
|
||||
|
||||
[perl-proc-processtable]
|
||||
aur
|
||||
|
||||
[perl-yaml-tiny]
|
||||
aur
|
||||
|
||||
[perl4-corelibs]
|
||||
aur
|
||||
|
||||
[python-autopep8]
|
||||
aur
|
||||
|
||||
[python-bitstring]
|
||||
aur
|
||||
|
||||
[python-blist]
|
||||
aur
|
||||
|
||||
[python-cffi]
|
||||
; my aur
|
||||
url = https://pypi.python.org/pypi/cffi
|
||||
regex = cffi-([\d.]+)\.tar\.gz
|
||||
|
||||
[python-pycparser-git]
|
||||
aur
|
||||
|
||||
[python-setproctitle]
|
||||
aur
|
||||
|
||||
; [python-you-get-git]
|
||||
; RSS'ed
|
||||
|
||||
[python2-netlib-git]
|
||||
aur
|
||||
|
||||
[python3-pycurl]
|
||||
aur
|
||||
|
||||
[reaver-wps-svn]
|
||||
aur
|
||||
|
||||
[ruby-gettext]
|
||||
aur
|
||||
|
||||
[ruby-levenshtein]
|
||||
aur
|
||||
|
||||
[ruby-locale]
|
||||
aur
|
||||
|
||||
[ruby-maruku]
|
||||
aur
|
||||
|
||||
[ruby-sass]
|
||||
aur
|
||||
|
||||
[ruby-yard]
|
||||
aur
|
||||
|
||||
[shutter]
|
||||
aur
|
||||
|
||||
[spideroak]
|
||||
aur
|
||||
|
||||
[sqlite-manager]
|
||||
aur
|
||||
|
||||
[ssed]
|
||||
; my aur
|
||||
url = http://sed.sourceforge.net/grabbag/ssed/
|
||||
regex = The current version is ([\d.]+)\.
|
||||
proxy = localhost:8087
|
||||
|
||||
[tp_smapi-dkms]
|
||||
aur
|
||||
|
||||
[ttf-ume]
|
||||
aur
|
||||
|
||||
[urlview]
|
||||
aur
|
||||
|
||||
; [vim-lily]
|
||||
|
||||
[wdiff]
|
||||
aur
|
||||
|
||||
[wireshark-gtk2]
|
||||
cmd = LANG=C pacman -Si wireshark-gtk | grep -F Version | awk '{print $3}'
|
||||
|
||||
[xf86-input-wizardpen]
|
||||
aur
|
||||
|
||||
[xkbset]
|
||||
aur
|
||||
|
||||
[xmind]
|
||||
aur
|
||||
|
||||
[zbar]
|
||||
aur
|
||||
|
||||
; [zhcon]
|
||||
; my aur
|
||||
; last update is six years ago
|
||||
|
||||
[zint]
|
||||
aur
|
@ -0,0 +1 @@
|
||||
__version__ = '0.2'
|
3
nvchecker/config.py
Normal file
3
nvchecker/config.py
Normal file
@ -0,0 +1,3 @@
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
|
0
nvchecker/lib/__init__.py
Normal file
0
nvchecker/lib/__init__.py
Normal file
69
nvchecker/lib/nicelogger.py
Normal file
69
nvchecker/lib/nicelogger.py
Normal file
@ -0,0 +1,69 @@
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
|
||||
class TornadoLogFormatter(logging.Formatter):
|
||||
def __init__(self, color, *args, **kwargs):
|
||||
super().__init__(self, *args, **kwargs)
|
||||
self._color = color
|
||||
if color:
|
||||
import curses
|
||||
curses.setupterm()
|
||||
if sys.hexversion < 50463728:
|
||||
fg_color = str(curses.tigetstr("setaf") or
|
||||
curses.tigetstr("setf") or "", "ascii")
|
||||
else:
|
||||
fg_color = curses.tigetstr("setaf") or curses.tigetstr("setf") or b""
|
||||
self._colors = {
|
||||
logging.DEBUG: str(curses.tparm(fg_color, 4), # Blue
|
||||
"ascii"),
|
||||
logging.INFO: str(curses.tparm(fg_color, 2), # Green
|
||||
"ascii"),
|
||||
logging.WARNING: str(curses.tparm(fg_color, 3), # Yellow
|
||||
"ascii"),
|
||||
logging.ERROR: str(curses.tparm(fg_color, 1), # Red
|
||||
"ascii"),
|
||||
}
|
||||
self._normal = str(curses.tigetstr("sgr0"), "ascii")
|
||||
|
||||
def format(self, record):
|
||||
try:
|
||||
record.message = record.getMessage()
|
||||
except Exception as e:
|
||||
record.message = "Bad message (%r): %r" % (e, record.__dict__)
|
||||
record.asctime = time.strftime(
|
||||
"%m-%d %H:%M:%S", self.converter(record.created))
|
||||
record.asctime += '.%03d' % ((record.created % 1) * 1000)
|
||||
prefix = '[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]' % \
|
||||
record.__dict__
|
||||
if self._color:
|
||||
prefix = (self._colors.get(record.levelno, self._normal) +
|
||||
prefix + self._normal)
|
||||
formatted = prefix + " " + record.message
|
||||
if record.exc_info:
|
||||
if not record.exc_text:
|
||||
record.exc_text = self.formatException(record.exc_info)
|
||||
if record.exc_text:
|
||||
formatted = formatted.rstrip() + "\n" + record.exc_text
|
||||
return formatted.replace("\n", "\n ")
|
||||
|
||||
def enable_pretty_logging(level=logging.DEBUG):
|
||||
logger = logging.getLogger()
|
||||
h = logging.StreamHandler()
|
||||
formatter = logging.Formatter('%(asctime)s:%(levelname)-7s:%(name)-12s:%(message)s')
|
||||
try:
|
||||
import curses
|
||||
color = False
|
||||
curses.setupterm()
|
||||
if curses.tigetnum("colors") > 0:
|
||||
color = True
|
||||
formatter = TornadoLogFormatter(color=color)
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
h.setLevel(level)
|
||||
h.setFormatter(formatter)
|
||||
logger.setLevel(level)
|
||||
logger.addHandler(h)
|
||||
|
@ -5,14 +5,16 @@ import os
|
||||
import sys
|
||||
import configparser
|
||||
import logging
|
||||
import argparse
|
||||
from functools import partial
|
||||
|
||||
from pkg_resources import parse_version
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.options import parse_command_line, define, options
|
||||
|
||||
from nvchecker.get_version import get_version
|
||||
from nvchecker import notify
|
||||
from .lib import notify, nicelogger
|
||||
|
||||
from .get_version import get_version
|
||||
from . import __version__
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
notifications = []
|
||||
@ -20,13 +22,6 @@ g_counter = 0
|
||||
g_oldver = {}
|
||||
g_curver = {}
|
||||
|
||||
define("notify", type=bool,
|
||||
help="show desktop notifications when a new version is available")
|
||||
define("oldverfile", type=str, metavar="FILE",
|
||||
help="a text file listing current version info in format 'name: version'")
|
||||
define("verfile", type=str, metavar="FILE",
|
||||
help="write a new version file")
|
||||
|
||||
def task_inc():
|
||||
global g_counter
|
||||
g_counter += 1
|
||||
@ -57,10 +52,10 @@ def load_oldverfile(file):
|
||||
return v
|
||||
|
||||
def write_verfile():
|
||||
if not options.verfile:
|
||||
if not args.newver:
|
||||
return
|
||||
|
||||
with open(options.verfile, 'w') as f:
|
||||
with open(args.newver, 'w') as f:
|
||||
# sort using only alphanums, as done by the sort command, and needed by
|
||||
# comm command
|
||||
for item in sorted(g_curver.items(), key=lambda i: (''.join(filter(str.isalnum, i[0])), i[1])):
|
||||
@ -78,7 +73,7 @@ def print_version_update(name, version):
|
||||
def _updated(name, version):
|
||||
g_curver[name] = version
|
||||
|
||||
if options.notify:
|
||||
if args.notify:
|
||||
msg = '%s updated to version %s' % (name, version)
|
||||
notifications.append(msg)
|
||||
notify.update('nvchecker', '\n'.join(notifications))
|
||||
@ -91,14 +86,39 @@ def get_versions(config):
|
||||
task_dec()
|
||||
|
||||
def main():
|
||||
files = parse_command_line()
|
||||
if not files:
|
||||
global args
|
||||
|
||||
parser = argparse.ArgumentParser(description='New version checker for software')
|
||||
parser.add_argument('files', metavar='FILE', nargs='*',
|
||||
help='software version source files')
|
||||
parser.add_argument('-i', '--oldver',
|
||||
help='read an existing version record file')
|
||||
parser.add_argument('-o', '--newver',
|
||||
help='write a new version record file')
|
||||
# parser.add_argument('-r', '--rc', default=os.path.expanduser('~/.nvcheckerrc'),
|
||||
# help='specify the nvcheckerrc file to use')
|
||||
parser.add_argument('-n', '--notify', action='store_true', default=False,
|
||||
help='show desktop notifications when a new version is available')
|
||||
parser.add_argument('-l', '--logging',
|
||||
choices=('debug', 'info', 'warning', 'error'), default='info',
|
||||
help='logging level (default: info)')
|
||||
parser.add_argument('-V', '--version', action='store_true',
|
||||
help='show version and exit')
|
||||
|
||||
args = parser.parse_args()
|
||||
nicelogger.enable_pretty_logging(getattr(logging, args.logging.upper()))
|
||||
|
||||
if args.version:
|
||||
print('nvchecker v' + __version__)
|
||||
return
|
||||
|
||||
if not args.files:
|
||||
return
|
||||
|
||||
def run_test():
|
||||
config = load_config(*files)
|
||||
if options.oldverfile:
|
||||
g_oldver.update(load_oldverfile(options.oldverfile))
|
||||
config = load_config(*args.files)
|
||||
if args.current:
|
||||
g_oldver.update(load_oldverfile(args.current))
|
||||
g_curver.update(g_oldver)
|
||||
get_versions(config)
|
||||
|
||||
|
13
nvchecker/tools.py
Normal file
13
nvchecker/tools.py
Normal file
@ -0,0 +1,13 @@
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
from tornado.options import parse_command_line, define, options
|
||||
|
||||
def take():
|
||||
raise NotImplementedError
|
||||
|
||||
define("notify", type=bool,
|
||||
help="show desktop notifications when a new version is available")
|
||||
define("oldverfile", type=str, metavar="FILE",
|
||||
help="a text file listing current version info in format 'name: version'")
|
||||
define("verfile", type=str, metavar="FILE",
|
||||
help="write a new version file")
|
3
setup.py
3
setup.py
@ -2,10 +2,11 @@
|
||||
# vim:fileencoding=utf-8
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
import nvchecker
|
||||
|
||||
setup(
|
||||
name = 'nvchecker',
|
||||
version = '0.1',
|
||||
version = nvchecker.__version__,
|
||||
packages = find_packages(),
|
||||
install_requires = ['tornado'],
|
||||
entry_points = {
|
||||
|
Loading…
Reference in New Issue
Block a user