new upstream release - 2.18

This commit is contained in:
Kamil Dudka 2018-10-29 13:14:39 +01:00
parent b1e91b59e5
commit 48b9f73cc8
6 changed files with 10 additions and 162 deletions

View File

@ -1,152 +0,0 @@
From 9d1129f41f193a47d6791f44f14abe9479999266 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 8 Aug 2018 17:42:17 +0200
Subject: [PATCH] units_cur: validate rate data from server
---
units_cur | 72 ++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 55 insertions(+), 17 deletions(-)
diff --git a/units_cur b/units_cur
index 00281d8..d625570 100755
--- a/units_cur
+++ b/units_cur
@@ -28,8 +28,12 @@ from __future__ import absolute_import, division, print_function
#
#
-version = '4.2'
+version = '4.3'
+# Version 4.3: 20 July 2018
+#
+# Validate rate data from server
+#
# Version 4.2: 18 April 2018
#
# Handle case of empty/malformed entry returned from the server
@@ -55,6 +59,10 @@ from sys import exit, stderr, stdout
outfile_name = 'currency.units'
+# valid metals
+
+validmetals = ['silver','gold','platinum']
+
# This exchange rate table lists the currency ISO 4217 codes, their
# long text names, and any fixed definitions. If the definition is
# empty then units_cur will query the server for a value.
@@ -271,11 +279,19 @@ ap.add_argument('-v','--verbose',
help='display details when fetching currency data',
)
+
+def validfloat(x):
+ try:
+ float(x)
+ return True
+ except ValueError:
+ return False
+
outfile_name = ap.parse_args().output_file
verbose = ap.parse_args().verbose
try:
- res = requests.get('http://finance.yahoo.com/webservice/v1/symbols'
+ res = requests.get('https://finance.yahoo.com/webservice/v1/symbols'
'/allcurrencies/quote?format=json')
res.raise_for_status()
webdata = res.json()['list']['resources']
@@ -299,10 +315,16 @@ for data in webdata:
stderr.write('Got unknown currency with code {}\n'.format(code))
else:
if not currency[code][rate_index]:
- currency[code][rate_index] = '1|{} US$'.format(rate)
+ if validfloat(rate):
+ currency[code][rate_index] = '1|{} US$'.format(rate)
+ else:
+ stderr.write('Got invalid rate "{}" for currency "{}"\n'.format(
+ rate, code))
elif verbose:
- stderr.write('Got value "{}" for currency "{}" but '
- 'it is already defined\n'.format(rate, code))
+ if currency[code][rate_index] != '1|{} US$'.format(rate):
+ stderr.write('Got value "{}" for currency "{}" but '
+ 'it is already defined as {}\n'.format(rate, code,
+ currency[code][rate_index]))
# Delete currencies where we have no rate data
@@ -313,17 +335,15 @@ for code in currency.keys():
del currency[code]
try:
- req = requests.get('http://services.packetizer.com/spotprices/?f=json')
+ req = requests.get('https://services.packetizer.com/spotprices/?f=json')
req.raise_for_status()
metals = req.json()
except requests.exceptions.RequestException as e:
stderr.write('Error connecting to spotprices server:\n{}\n'.format(e))
exit(1)
-del metals['date']
-
try:
- req = requests.get('http://services.packetizer.com/btc/?f=json')
+ req = requests.get('https://services.packetizer.com/btc/?f=json')
req.raise_for_status()
bitcoin = req.json()
except requests.exceptions.RequestException as e:
@@ -344,13 +364,31 @@ ratestr = '\n'.join(
'{:{}}{}'.format(name, maxlen, rate) for (name, rate) in zip(cnames, crates)
)
-ozzystr = '\n'.join('{:19}{} US$/troyounce'.format(
- metal + 'price',
- price,
- ) for metal, price in metals.items())
-
-bitcoinstr = '{:{}}{} US$ # From services.packetizer.com/btc\n'.format(
+metallist = ['']*len(validmetals)
+for metal, price in metals.items():
+ if metal in validmetals:
+ metalindex = validmetals.index(metal)
+ if validfloat(price):
+ if not metallist[metalindex]:
+ metallist[validmetals.index(metal)] = '{:19}{} US$/troyounce'.format(
+ metal + 'price', price)
+ elif verbose:
+ stderr.write('Got value "{}" for metal "{}" but '
+ 'it is already defined\n'.format(price,metal))
+ else:
+ stderr.write('Got invalid rate "{}" for metal "{}"\n'.format(
+ price, metal))
+ elif metal != 'date' and verbose: # Don't print a message for the "date" entry
+ stderr.write('Got unknown metal "{}" with value "{}"\n',metal,price)
+metalstr = '\n'.join(metallist)
+
+if validfloat(bitcoin['usd']):
+ bitcoinstr = '{:{}}{} US$ # From services.packetizer.com/btc\n'.format(
'bitcoin',maxlen,bitcoin['usd'])
+else:
+ stderr.write('Got invalid bitcoin rate "{}"\n', bitcoint['usd'])
+ bitcointstr=''
+
outstr = (
"""# ISO Currency Codes
@@ -366,9 +404,9 @@ outstr = (
# Precious metals prices from Packetizer (services.packetizer.com/spotprices)
-{ozzystr}
+{metalstr}
-""".format(codestr=codestr, datestr=datestr, ratestr=ratestr, ozzystr=ozzystr,
+""".format(codestr=codestr, datestr=datestr, ratestr=ratestr, metalstr=metalstr,
bitcoinstr=bitcoinstr)
).replace('\n', linesep)
--
2.17.1

View File

@ -12,8 +12,8 @@ diff --git a/Makefile.in b/Makefile.in
index 70e2e10..7c1ee5b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -58,8 +58,6 @@ DEFS=-DUNITSFILE=\"@UDAT@definitions.units\" -DLOCALEMAP=\"@UDAT@locale_map.txt\
CFLAGS = @CFLAGS@
@@ -61,8 +61,6 @@ CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
OBJECTS = units.@OBJEXT@ parse.tab.@OBJEXT@ getopt.@OBJEXT@ getopt1.@OBJEXT@ @STRFUNC@
-.PHONY: currency-units-update
@ -21,7 +21,7 @@ index 70e2e10..7c1ee5b 100644
.SUFFIXES:
.SUFFIXES: .c .@OBJEXT@ .rc .res .texinfo .pdf
@@ -107,7 +105,7 @@ units_cur_inst: units_cur
@@ -110,7 +108,7 @@ units_cur_inst: units_cur
-e "s@/usr/bin/python@$(PYTHON)@" \
$(srcdir)/units_cur > units_cur_inst
@ -30,7 +30,7 @@ index 70e2e10..7c1ee5b 100644
$(MKDIR_P) $(DESTDIR)@UDAT@ $(DESTDIR)$(bindir) $(DESTDIR)@CDAT@
$(INSTALL_DATA) $(srcdir)/definitions.units $(DESTDIR)@UDAT@definitions.units
-rm -f $(DESTDIR)@UDAT@currency.units
@@ -204,11 +202,6 @@ texclean:
@@ -207,11 +205,6 @@ texclean:
-rm -f units.log UnitsMKS.log UnitsWin.log \
*.aux *.cp *.fn *.ky *.op *.pg *.toc *.tp *.vr

View File

@ -1 +1 @@
SHA512 (units-2.17.tar.gz) = e4114f7dc0e40146f969375511c5d930497cb9502306ef82feac78c8e09a03e84ed0b582ff82e2878beae41702c9612f7a3d28fc6e9ed2cfae708f9feb8b737b
SHA512 (units-2.18.tar.gz) = 2ae9f08acb03f2f443514800dafb454434d7d1a43497d2a937c2e9e8429f63d821be11ae3090693e8cadbd2f9cdeafba8f80c1671d84a9cceb0f72ad75d8cad7

Binary file not shown.

BIN
units-2.18.tar.gz.sig Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
Summary: A utility for converting amounts from one unit to another
Name: units
Version: 2.17
Release: 5%{?dist}
Version: 2.18
Release: 1%{?dist}
Source: https://ftp.gnu.org/gnu/units/%{name}-%{version}.tar.gz
URL: https://www.gnu.org/software/units/units.html
License: GPLv3+
@ -14,9 +14,6 @@ BuildRequires: ncurses-devel
BuildRequires: python3-devel
BuildRequires: readline-devel
# units_cur: validate rate data from server (#1598913)
Patch1: 0001-units-2.17-units_cur-validate.patch
# do not update currency.units from network during build
Patch2: 0002-units-2.17-no-network.patch
@ -69,6 +66,9 @@ fi
%{_mandir}/man1/*
%changelog
* Mon Oct 29 2018 Kamil Dudka <kdudka@redhat.com> - 2.18-1
- new upstream release
* Wed Aug 08 2018 Kamil Dudka <kdudka@redhat.com> - 2.17-5
- do not update currency.units from network during build
- units_cur: validate rate data from server (#1598913)