mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
remove troublesome colon from record files
This commit is contained in:
parent
e5d89e8ce8
commit
b7534c9091
4 changed files with 14 additions and 11 deletions
15
README.rst
15
README.rst
|
@ -22,11 +22,11 @@ You normally will like to specify some "version record files"; see below.
|
||||||
|
|
||||||
Version Record Files
|
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 ``:`` ::
|
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 a space\ [#]_::
|
||||||
|
|
||||||
fcitx: 4.2.7
|
fcitx 4.2.7
|
||||||
google-chrome: 27.0.1453.93-200836
|
google-chrome 27.0.1453.93-200836
|
||||||
vim: 7.3.1024
|
vim 7.3.1024
|
||||||
|
|
||||||
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``::
|
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``::
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ Compare the two files for updates (assuming they are sorted alphabetically; file
|
||||||
|
|
||||||
comm -13 old_ver.txt new_ver.txt
|
comm -13 old_ver.txt new_ver.txt
|
||||||
# or say that in English:
|
# or say that in English:
|
||||||
comm -13 old_ver.txt new_ver.txt | sed 's/:/ has updated to version/;s/$/./'
|
comm -13 old_ver.txt new_ver.txt | awk '{print $1 " has updated to version " $2 "."}'
|
||||||
# show both old and new versions
|
# show both old and new versions
|
||||||
join old_ver.txt new_ver.txt | awk '$2 != $3'
|
join old_ver.txt new_ver.txt | awk '$2 != $3'
|
||||||
|
|
||||||
|
@ -137,4 +137,7 @@ TODO
|
||||||
====
|
====
|
||||||
* Tool to replace the ``join`` command
|
* Tool to replace the ``join`` command
|
||||||
* Support GitHub tags
|
* Support GitHub tags
|
||||||
* Remove troublesome colon from record files
|
|
||||||
|
Footnotes
|
||||||
|
=========
|
||||||
|
.. [#] Note: with nvchecker <= 0.2, there are one more colon each line. You can use ``sed -i 's/://' FILES...`` to remove them.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = '0.2'
|
__version__ = '0.3'
|
||||||
|
|
|
@ -52,10 +52,10 @@ def print_version_update(name, version):
|
||||||
|
|
||||||
oldver = g_oldver.get(name, None)
|
oldver = g_oldver.get(name, None)
|
||||||
if not oldver or parse_version(oldver) < parse_version(version):
|
if not oldver or parse_version(oldver) < parse_version(version):
|
||||||
logger.info('%s: updated version %s', name, version)
|
logger.info('%s updated version %s', name, version)
|
||||||
_updated(name, version)
|
_updated(name, version)
|
||||||
else:
|
else:
|
||||||
logger.info('%s: current version %s', name, version)
|
logger.info('%s current version %s', name, version)
|
||||||
task_dec()
|
task_dec()
|
||||||
|
|
||||||
def _updated(name, version):
|
def _updated(name, version):
|
||||||
|
|
|
@ -72,14 +72,14 @@ def read_verfile(file):
|
||||||
v = {}
|
v = {}
|
||||||
with open(file) as f:
|
with open(file) as f:
|
||||||
for l in f:
|
for l in f:
|
||||||
name, ver = [x.strip() for x in l.split(':', 1)]
|
name, ver = l.rstrip().split(None, 1)
|
||||||
v[name] = ver
|
v[name] = ver
|
||||||
return v
|
return v
|
||||||
|
|
||||||
def write_verfile(file, versions):
|
def write_verfile(file, versions):
|
||||||
# sort using only alphanums, as done by the sort command, and needed by
|
# sort using only alphanums, as done by the sort command, and needed by
|
||||||
# comm command
|
# comm command
|
||||||
data = ['%s: %s\n' % item
|
data = ['%s %s\n' % item
|
||||||
for item in sorted(versions.items(), key=lambda i: (''.join(filter(str.isalnum, i[0])), i[1]))]
|
for item in sorted(versions.items(), key=lambda i: (''.join(filter(str.isalnum, i[0])), i[1]))]
|
||||||
safe_overwrite(file, data, method='writelines')
|
safe_overwrite(file, data, method='writelines')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue