New version

- Add the __init__.py file to provide a proper package (vpodzime)
- Merge pull request #7 from vpodzime/master-decimal_locale (vpodzime)
- Make sure we pass a locale-agnostic string to Decimal() (vpodzime)
- Adapt the package description to no longer using GI (vpodzime)
- Make Size instances hashable (vpodzime)
- Sync the spec file with downstream (vpodzime)
This commit is contained in:
Vratislav Podzimek 2016-03-09 17:29:27 +01:00
parent 7deccfd1fc
commit 23696856e4
5 changed files with 18 additions and 111 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/libbytesize-0.1.tar.gz
/libbytesize-0.2.tar.gz
/libbytesize-0.3.tar.gz
/libbytesize-0.4.tar.gz

View File

@ -1,14 +1,11 @@
Name: libbytesize
Version: 0.3
Release: 3%{?dist}
Version: 0.4
Release: 1%{?dist}
Summary: A library for working with sizes in bytes
License: LGPLv2+
URL: https://github.com/rhinstaller/libbytesize
Source0: https://github.com/rhinstaller/libbytesize/archive/%{name}-%{version}.tar.gz
Patch0: size_instances_hashable.patch
Patch1: locale_agnostic_dec.patch
%define realname bytesize
BuildRequires: gmp-devel
@ -20,11 +17,10 @@ BuildRequires: python3-devel
BuildRequires: gtk-doc
%description
The libbytesize is a C library with GObject introspection support that
facilitates work with sizes in bytes. Be it parsing the input from users or
producing a nice human readable representation of a size in bytes this library
takes localization into account. It also provides support for sizes bigger than
MAXUINT64.
The libbytesize is a C library that facilitates work with sizes in
bytes. Be it parsing the input from users or producing a nice human readable
representation of a size in bytes this library takes localization into
account. It also provides support for sizes bigger than MAXUINT64.
%package devel
Summary: Development files for libbytesize
@ -55,8 +51,6 @@ the library from Python 3 easier and more convenient.
%prep
%setup -q -n %{name}-%{version}
%patch0 -p1
%patch1 -p1
%build
%configure
@ -87,10 +81,18 @@ find %{buildroot} -type f -name "*.la" | xargs %{__rm}
%{python2_sitearch}/bytesize/*
%files -n python3-%{realname}
%{python3_sitearch}/bytesize/bytesize.py
%{python3_sitearch}/bytesize/__pycache__/bytesize.*
%{python3_sitearch}/bytesize/*
%{python3_sitearch}/bytesize/__pycache__/*
%changelog
* Wed Mar 09 2016 Vratislav Podzimek <vpodzime@redhat.com> - 0.4-1
- Add the __init__.py file to provide a proper package (vpodzime)
- Merge pull request #7 from vpodzime/master-decimal_locale (vpodzime)
- Make sure we pass a locale-agnostic string to Decimal() (vpodzime)
- Adapt the package description to no longer using GI (vpodzime)
- Make Size instances hashable (vpodzime)
- Sync the spec file with downstream (vpodzime)
* Wed Mar 9 2016 Vratislav Podzimek <vpodzime@redhat.com> - 0.3-3
- Make sure we pass a locale-agnostic string to Decimal() (vpodzime)

View File

@ -1,49 +0,0 @@
From d2642df497ad0d0e66c3d46347df7b7b659b3c7d Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Tue, 8 Mar 2016 16:56:43 +0100
Subject: [PATCH] Make sure we pass a locale-agnostic string to Decimal()
Decimal() doesn't take into account the current locale, but we get a localized
result from bs_convert_to().
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
---
src/python/bytesize.py | 12 ++++++++++--
tests/lbs_py_override_unittest.py | 26 ++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/python/bytesize.py b/src/python/bytesize.py
index 179719c..3a32b65 100644
--- a/src/python/bytesize.py
+++ b/src/python/bytesize.py
@@ -4,6 +4,8 @@ from ctypes import POINTER, byref
import six
from decimal import Decimal
+import locale
+
import gettext
_ = lambda x: gettext.translation("libbytesize", fallback=True).gettext(x) if x != "" else ""
@@ -356,9 +358,15 @@ class Size(object):
real_unit = unit_strs.get(unit)
if real_unit is None:
raise ValueError("Invalid unit specification: '%s'" % unit)
- return Decimal(self._c_size.convert_to(real_unit))
+ ret = self._c_size.convert_to(real_unit)
else:
- return Decimal(self._c_size.convert_to(unit))
+ ret = self._c_size.convert_to(unit)
+
+ radix = locale.nl_langinfo(locale.RADIXCHAR)
+ if radix != '.':
+ ret = ret.replace(radix, '.')
+
+ return Decimal(ret)
def human_readable(self, min_unit=B, max_places=2, xlate=True):
if isinstance(min_unit, six.string_types):
--
2.5.0

View File

@ -1,47 +0,0 @@
From 5463719b1a0c27e9c7f6017531a1d90ac762b31b Mon Sep 17 00:00:00 2001
From: Vratislav Podzimek <vpodzime@redhat.com>
Date: Mon, 7 Mar 2016 11:56:14 +0100
Subject: [PATCH] Make Size instances hashable
This is useful e.g. for getting rid of duplicate items in lists and/or creation
of sets of sizes in general.
---
src/python/bytesize.py | 3 +++
tests/lbs_py_override_unittest.py | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/src/python/bytesize.py b/src/python/bytesize.py
index e3c9098..179719c 100644
--- a/src/python/bytesize.py
+++ b/src/python/bytesize.py
@@ -547,5 +547,8 @@ class Size(object):
def __reduce__(self):
return (self.__class__, (self.get_bytes(),))
+ def __hash__(self):
+ return self.get_bytes()
+
def __del__(self):
del(self._c_size)
diff --git a/tests/lbs_py_override_unittest.py b/tests/lbs_py_override_unittest.py
index 17043ac..b502b30 100755
--- a/tests/lbs_py_override_unittest.py
+++ b/tests/lbs_py_override_unittest.py
@@ -244,6 +244,14 @@ class SizeTestCase(unittest.TestCase):
self.assertIsNot(size1, size2)
self.assertEqual(size1, size2)
+ def testHashable(self):
+ size = Size("1 KiB")
+ hs = hash(size)
+ self.assertIsNotNone(hs)
+
+ size_set = set((Size("1 KiB"), Size("1 KiB"), Size("1 KiB"), Size("2 KiB"), Size(0)))
+ self.assertEqual(len(size_set), 3)
+
#endclass
# script entry point
--
2.5.0

View File

@ -1 +1 @@
eef829bddac464709d314f0a3e096364 libbytesize-0.3.tar.gz
bc40503a5fec22adbf8894f56c3121b9 libbytesize-0.4.tar.gz