gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated (f


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant-frontend-examples] branch master updated (fdf40e3 -> bd3e5ba)
Date: Mon, 20 Feb 2017 17:08:05 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository merchant-frontend-examples.

    from fdf40e3  FIXME on adding images with payed content.
     new de86dc7  Adding initial logic for amounts arithmetics in Python 
library.
     new e5abc1b  Amount subtraction.
     new bd3e5ba  Merge branch 'master' of taler.net:merchant-frontend-examples

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile                   |  2 +-
 Python/pytaler/__init__.py |  0
 Python/pytaler/amounts.py  | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 Python/setup.py            | 11 ++++++++++
 4 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 Python/pytaler/__init__.py
 create mode 100644 Python/pytaler/amounts.py
 create mode 100755 Python/setup.py

diff --git a/Makefile b/Makefile
index d3a8693..4a1d444 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 .PHONY: graphics
 
-SUBDIRS := php
+SUBDIRS := php Python
 
 all: $(SUBDIRS)
 
diff --git a/Python/pytaler/__init__.py b/Python/pytaler/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/Python/pytaler/amounts.py b/Python/pytaler/amounts.py
new file mode 100644
index 0000000..d39663f
--- /dev/null
+++ b/Python/pytaler/amounts.py
@@ -0,0 +1,55 @@
+# This file is part of GNU TALER.
+# Copyright (C) 2014-2017 INRIA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free 
Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER 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 Lesser General Public License for more 
details.
+#
+# You should have received a copy of the GNU Lesser General Public License 
along with
+# GNU TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+#
+# @author Marcello Stanisci
+
+FRACTION = 100000000
+
+def amount_get_zero(currency):
+    return {"value": 0, "fraction": 0, "currency": currency}
+
+
+def amount_sum(a1, a2):
+    assert(a1['currency'] == a2['currency'])
+    fractions = a1['fraction'] + a2['fraction']
+    ret = {"value": a1["value"] + a2["value"] + int(fractions / FRACTION),
+           "fraction": fractions % FRACTION,
+           "currency": a1["currency"]}
+    return ret
+
+# Computes a1 - a2
+def amount_sub(a1, a2):
+    assert(a1["currency"] == a2["currency"])
+
+    # Normalize
+    a1["value"] += int(a1["fraction"] / FRACTION)
+    a2["value"] += int(a2["fraction"] / FRACTION)
+    a1["fraction"] = a1["fraction"] % FRACTION
+    a2["fraction"] = a2["fraction"] % FRACTION
+
+    # Extra care for fraction
+    if a1["fraction"] < a2["fraction"]:
+        a1["fraction"] += FRACTION
+        a1["value"] -= 1
+        assert(a1["value"] >= 0)
+
+    # Sub
+    ret = amount_get_zero(a1["currency"])
+    ret["value"] = a1["value"] - a2["value"]
+    ret["fraction"] = a1["fraction"] - a2["fraction"]
+
+    assert(ret["value"] >= 0)
+    assert(ret["fraction"] >= 0)
+
+    return ret
diff --git a/Python/setup.py b/Python/setup.py
new file mode 100755
index 0000000..5727698
--- /dev/null
+++ b/Python/setup.py
@@ -0,0 +1,11 @@
+from setuptools import setup, find_packages
+
+setup(name='pytaler',
+      version='0.0',
+      description='Helper functions for Taler amounts',
+      url='git://taler.net/merchant-frontend-examples',
+      author='Marcello Stanisci',
+      author_email='address@hidden',
+      license='GPL',
+      packages=find_packages(),
+      zip_safe=False)

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]