Skip to content

Commit

Permalink
Moved coerce_boolean() to humanfriendly package
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Nov 15, 2014
1 parent 2f3858e commit f0ec299
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 39 deletions.
4 changes: 2 additions & 2 deletions deb_pkg_tools/__init__.py
@@ -1,11 +1,11 @@
# Debian packaging tools.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 19, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

# Semi-standard module versioning.
__version__ = '1.29'
__version__ = '1.29.1'

debian_package_dependencies = (
'apt', # apt-get
Expand Down
6 changes: 3 additions & 3 deletions deb_pkg_tools/gpg.py
@@ -1,7 +1,7 @@
# Debian packaging tools: GPG key pair generation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: August 30, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand All @@ -24,10 +24,10 @@

# External dependencies.
from executor import execute
from humanfriendly import format_path, format_timespan
from humanfriendly import coerce_boolean, format_path, format_timespan

# Modules included in our package.
from deb_pkg_tools.utils import coerce_boolean, find_home_directory
from deb_pkg_tools.utils import find_home_directory

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down
5 changes: 2 additions & 3 deletions deb_pkg_tools/package.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Package manipulation.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 19, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand All @@ -27,13 +27,12 @@
# External dependencies.
from debian.deb822 import Deb822
from executor import execute
from humanfriendly import concatenate, format_path, pluralize, Spinner
from humanfriendly import coerce_boolean, concatenate, format_path, pluralize, Spinner

# Modules included in our package.
from deb_pkg_tools.control import (deb822_from_string,
parse_control_fields,
patch_control_file)
from deb_pkg_tools.utils import coerce_boolean
from deb_pkg_tools.version import Version

# Initialize a logger.
Expand Down
6 changes: 3 additions & 3 deletions deb_pkg_tools/repo.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Trivial repository management.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: October 19, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand Down Expand Up @@ -49,14 +49,14 @@

# External dependencies.
from executor import execute, ExternalCommandFailed
from humanfriendly import concatenate, format_path, Spinner, Timer
from humanfriendly import coerce_boolean, concatenate, format_path, Spinner, Timer

# Modules included in our package.
from deb_pkg_tools import config
from deb_pkg_tools.control import unparse_control_fields
from deb_pkg_tools.gpg import GPGKey, initialize_gnupg
from deb_pkg_tools.package import find_package_archives, inspect_package_fields
from deb_pkg_tools.utils import atomic_lock, coerce_boolean, optimize_order, sha1
from deb_pkg_tools.utils import atomic_lock, optimize_order, sha1

# Enable power users to disable the use of `sudo' (because it
# may not be available in non-Debian build environments).
Expand Down
10 changes: 1 addition & 9 deletions deb_pkg_tools/tests.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Automated tests.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: August 31, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

# Standard library modules.
Expand Down Expand Up @@ -35,7 +35,6 @@
from deb_pkg_tools.package import collect_related_packages, copy_package_files, find_latest_version, find_package_archives, group_by_latest_versions, inspect_package, parse_filename
from deb_pkg_tools.printer import CustomPrettyPrinter
from deb_pkg_tools.repo import apt_supports_trusted_option, update_repository
from deb_pkg_tools.utils import coerce_boolean

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -293,13 +292,6 @@ def test_filename_parsing(self):
self.assertRaises(ValueError, parse_filename, 'python2.7_2.7.3-0ubuntu3.4_amd64.not-a-deb')
self.assertRaises(ValueError, parse_filename, 'python2.7.deb')

def test_boolean_coercion(self):
for value in ['YES', 'Yes', 'yes', 'TRUE', 'True', 'true', '1']:
self.assertEqual(coerce_boolean(value), True)
for value in ['NO', 'No', 'no', 'FALSE', 'False', 'false', '0']:
self.assertEqual(coerce_boolean(value), False)
self.assertRaises(ValueError, coerce_boolean, 'not a boolean!')

def test_package_building(self, repository=None, overrides={}, contents={}):
with Context() as finalizers:
build_directory = finalizers.mkdtemp()
Expand Down
19 changes: 1 addition & 18 deletions deb_pkg_tools/utils.py
@@ -1,7 +1,7 @@
# Debian packaging tools: Utility functions.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: August 30, 2014
# Last Change: November 15, 2014
# URL: https://github.com/xolox/python-deb-pkg-tools

"""
Expand All @@ -28,23 +28,6 @@
# Modules included in our package.
from deb_pkg_tools.compat import total_ordering

def coerce_boolean(value):
"""
Coerce a command line argument or environment variable to a boolean.
:param value: One of the strings ``true``, ``1``, ``false`` or ``0``.
:raises: :py:exc:`exceptions.ValueError` when the string is not one of the
supported strings.
:returns: A boolean value.
"""
normalized_value = value.lower().strip()
if normalized_value in ('yes', 'true', '1'):
return True
elif normalized_value in ('no', 'false', '0'):
return False
else:
raise ValueError("Invalid boolean value %r!" % value)

def compact(text, **kw):
"""
Compact whitespace in a string and format any keyword arguments into the
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -2,7 +2,7 @@
cached-property >= 0.1.5
coloredlogs >= 0.4.6
executor >= 1.3
humanfriendly >= 1.8.6
humanfriendly >= 1.11
python-debian >= 0.1.21-nmu2
# Undocumented transitive dependency of python-debian...
chardet

0 comments on commit f0ec299

Please sign in to comment.