~simpoir/landscape-charm/charm_push_target

« back to all changes in this revision

Viewing changes to charmhelpers/core/strutils.py

  • Committer: 🤖 Landscape Builder
  • Author(s): Simon Poirier
  • Date: 2019-05-24 14:06:39 UTC
  • mfrom: (396.1.1 charmhelpers-and-keys)
  • Revision ID: _landscape_builder-20190524140639-q3t8aavbxute9714
This branch updates charm helpers, and add the fix proposed as
https://github.com/juju/charm-helpers/pull/326

This should fix apt failures when specifying a deb source and key.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    if isinstance(value, six.string_types):
62
62
        value = six.text_type(value)
63
63
    else:
64
 
        msg = "Unable to interpret non-string value '%s' as boolean" % (value)
 
64
        msg = "Unable to interpret non-string value '%s' as bytes" % (value)
65
65
        raise ValueError(msg)
66
66
    matches = re.match("([0-9]+)([a-zA-Z]+)", value)
67
 
    if not matches:
68
 
        msg = "Unable to interpret string value '%s' as bytes" % (value)
69
 
        raise ValueError(msg)
70
 
    return int(matches.group(1)) * (1024 ** BYTE_POWER[matches.group(2)])
 
67
    if matches:
 
68
        size = int(matches.group(1)) * (1024 ** BYTE_POWER[matches.group(2)])
 
69
    else:
 
70
        # Assume that value passed in is bytes
 
71
        try:
 
72
            size = int(value)
 
73
        except ValueError:
 
74
            msg = "Unable to interpret string value '%s' as bytes" % (value)
 
75
            raise ValueError(msg)
 
76
    return size
71
77
 
72
78
 
73
79
class BasicStringComparator(object):