Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions checkbox-core-snap/series16/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ parts:
snapcraftctl build
# install the dependencies of checkbox-support itself because this
# pip version pyproject.toml dependencies
$SNAPCRAFT_PART_INSTALL/usr/bin/python3 -m pip install "pyparsing<3.0.0" "requests<2.26.0" "distro<1.7.0" "requests_unixsocket<=0.3.0" "importlib_metadata<=1.0.0"
$SNAPCRAFT_PART_INSTALL/usr/bin/python3 -m pip install "requests<2.26.0" "distro<1.7.0" "requests_unixsocket<=0.3.0" "importlib_metadata<=1.0.0"
################################################################################
checkbox-ng:
plugin: python
Expand Down Expand Up @@ -236,7 +236,7 @@ parts:
snapcraftctl build
# install the dependencies of checkbox-support itself because this
# pip version pyproject.toml dependencies
$SNAPCRAFT_PART_INSTALL/usr/bin/python3 -m pip install "packaging<21.0" "psutil<=5.9.5" "requests<2.26.0" "urwid<=2.1.2" "Jinja2<=2.11.3" "XlsxWriter<=3.0.3" "tqdm<4.65.0" "importlib_metadata<=1.0.0"
$SNAPCRAFT_PART_INSTALL/usr/bin/python3 -m pip install "packaging<21.0" "psutil<=5.9.5" "pyparsing<3.0.0" "requests<2.26.0" "urwid<=2.1.2" "Jinja2<=2.11.3" "XlsxWriter<=3.0.3" "tqdm<4.65.0" "importlib_metadata<=1.0.0"
################################################################################
checkbox-provider-resource:
plugin: dump
Expand Down
2 changes: 1 addition & 1 deletion checkbox-core-snap/series20/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ parts:
stage-packages:
# actual requirements
- python3-bluez
- python3-pyparsing
- python3-requests-unixsocket
- libsystemd0
- v4l-utils
Expand Down Expand Up @@ -209,6 +208,7 @@ parts:
- python3-markupsafe
- python3-jinja2
- python3-packaging
- python3-pyparsing
- python3-requests-oauthlib
- python3-urwid
- python3-xlsxwriter
Expand Down
2 changes: 1 addition & 1 deletion checkbox-core-snap/series22/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ parts:
stage-packages:
# actual requirements
- python3-bluez
- python3-pyparsing
- python3-requests-unixsocket
- libsystemd0
- v4l-utils
Expand Down Expand Up @@ -216,6 +215,7 @@ parts:
- python3-markupsafe
- python3-jinja2
- python3-packaging
- python3-pyparsing
- python3-requests-oauthlib
- python3-urwid
- python3-xlsxwriter
Expand Down
2 changes: 1 addition & 1 deletion checkbox-core-snap/series24/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ parts:
stage-packages:
# actual requirements
- python3-bluez
- python3-pyparsing
- libsystemd0
- v4l-utils
# added to stage python:
Expand Down Expand Up @@ -201,6 +200,7 @@ parts:
- python3-markupsafe
- python3-jinja2
- python3-packaging
- python3-pyparsing
- python3-requests-oauthlib
- python3-urwid
- python3-xlsxwriter
Expand Down
9 changes: 9 additions & 0 deletions checkbox-ng/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ recursive-include docs *.rst *.py *.html *.conf
recursive-include plainbox/test-data *.json *.html *.tar.xz
recursive-exclude debian *
recursive-exclude build *

include checkbox_ng/support/parsers/cputable
recursive-include checkbox_ng/support/parsers/tests/cpuinfo_data *.txt
recursive-include checkbox_ng/support/parsers/tests/dmidecode_data *.txt
recursive-include checkbox_ng/support/parsers/tests/fixtures *.txt
recursive-include checkbox_ng/support/parsers/tests/pactl_data *.txt
recursive-include checkbox_ng/support/parsers/tests/udevadm_data *.txt *.lsblk.json
recursive-include checkbox_ng/support/snap_utils/tests/asserts_data *.txt
recursive-include checkbox_ng/support/parsers/tests/v4l2_compliance_data *.txt
38 changes: 38 additions & 0 deletions checkbox-ng/checkbox_ng/support/helpers/slugify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is part of Checkbox.
#
# Copyright 2024 Canonical Ltd.
# Written by:
# Pierre Equoy <pierre.equoy@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

import string


def slugify(_string):
"""
Slugify a string

Transform any string to one that can be used in filenames and Python
identifers.
"""
if not _string:
return _string

valid_chars = frozenset(
"_{}{}".format(string.ascii_letters, string.digits)
)
# Python identifiers cannot start with a digit
if _string[0].isdigit():
_string = "_" + _string
return "".join(c if c in valid_chars else "_" for c in _string)
Empty file.
44 changes: 44 additions & 0 deletions checkbox-ng/checkbox_ng/support/lib/bit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This file is part of Checkbox.
#
# Copyright 2008-2022 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

from struct import calcsize


def get_bitmask(key):
bitmask = []
for value in reversed(key.split()):
value = int(value, 16)
bitmask.append(value)
return bitmask


def get_bitcount(bitmask):
bitcount = 0
for value in bitmask:
while value:
bitcount += 1
value &= value - 1
return bitcount


def test_bit(bit, bitmask, bits=None):
if bits is None:
bits = calcsize("l") * 8
offset = bit % bits
long = int(bit / bits)
if long >= len(bitmask):
return 0
return (bitmask[long] >> offset) & 1
174 changes: 174 additions & 0 deletions checkbox-ng/checkbox_ng/support/lib/conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# This file is part of Checkbox.
#
# Copyright 2008-2022 Canonical Ltd.
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

import re
from datetime import datetime, timedelta

from checkbox_ng.support.lib.tz import tzutc


DATETIME_RE = re.compile(
r"""
^(?P<year>\d\d\d\d)-?(?P<month>\d\d)-?(?P<day>\d\d)
T(?P<hour>\d\d):?(?P<minute>\d\d):?(?P<second>\d\d)
(?:\.(?P<second_fraction>\d{0,6}))?
(?P<tz>
(?:(?P<tz_sign>[-+])(?P<tz_hour>\d\d):(?P<tz_minute>\d\d))
| Z)?$
""",
re.VERBOSE,
)

TYPE_FORMATS = (
(r"(yes|true)", lambda v: True),
(r"(no|false)", lambda v: False),
(r"-?\d+", lambda v: int(v.group(0))),
(r"-?\d+\.\d+", lambda v: float(v.group(0))),
(r"(-?\d+) ?([kmgt]?b?)", lambda v: int(v.group(1))),
(r"(-?\d+\.\d+) ?([kmgt]?b?)", lambda v: float(v.group(1))),
(r"(-?\d+) ?([kmgt]?hz)", lambda v: int(v.group(1))),
(r"(-?\d+\.\d+) ?([kmgt]?hz)", lambda v: float(v.group(1))),
)
TYPE_FORMATS = tuple(
(re.compile(r"^%s$" % pattern, re.IGNORECASE), format)
for pattern, format in TYPE_FORMATS
)

TYPE_MULTIPLIERS = (
(r"b", 1),
(r"kb?", 1024),
(r"mb?", 1024 * 1024),
(r"gb?", 1024 * 1024 * 1024),
(r"tb?", 1024 * 1024 * 1024 * 1024),
(r"hz", 1),
(r"khz?", 1024),
(r"mhz?", 1024 * 1024),
(r"ghz?", 1024 * 1024 * 1024),
(r"thz?", 1024 * 1024 * 1024 * 1024),
)
TYPE_MULTIPLIERS = tuple(
(re.compile(r"^%s$" % pattern, re.IGNORECASE), multiplier)
for pattern, multiplier in TYPE_MULTIPLIERS
)


def datetime_to_string(dt):
"""Return a consistent string representation for a given datetime.

:param dt: The datetime object.
"""
return dt.isoformat()


def string_to_datetime(string):
"""Return a datetime object from a consistent string representation.

:param string: The string representation.
"""
# we cannot use time.strptime: this function accepts neither fractions
# of a second nor a time zone given e.g. as '+02:30'.
match = DATETIME_RE.match(string)

# The Relax NG schema allows a leading minus sign and year numbers
# with more than four digits, which are not "covered" by _time_regex.
if not match:
raise ValueError("Datetime with unreasonable value: %s" % string)

time_parts = match.groupdict()

year = int(time_parts["year"])
month = int(time_parts["month"])
day = int(time_parts["day"])
hour = int(time_parts["hour"])
minute = int(time_parts["minute"])
second = int(time_parts["second"])
second_fraction = time_parts["second_fraction"]
if second_fraction is not None:
milliseconds = second_fraction + "0" * (6 - len(second_fraction))
milliseconds = int(milliseconds)
else:
milliseconds = 0

# The Relax NG validator accepts leap seconds, but the datetime
# constructor rejects them. The time values submitted by the HWDB
# client are not necessarily very precise, hence we can round down
# to 59.999999 seconds without losing any real precision.
if second > 59:
second = 59
milliseconds = 999999

dt = datetime(
year, month, day, hour, minute, second, milliseconds, tzinfo=tzutc
)

tz_sign = time_parts["tz_sign"]
tz_hour = time_parts["tz_hour"]
tz_minute = time_parts["tz_minute"]
if tz_sign in ("-", "+"):
delta = timedelta(hours=int(tz_hour), minutes=int(tz_minute))
if tz_sign == "-":
dt = dt + delta
else:
dt = dt - delta

return dt


def sizeof_bytes(bytes):
for x in ["bytes", "KB", "MB", "GB", "TB"]:
string = "%3.1f%s" % (bytes, x)
if bytes < 1024.0:
break
bytes /= 1024.0

return string


def sizeof_hertz(hertz):
for x in ["Hz", "KHz", "MHz", "GHz"]:
string = "%3.1f%s" % (hertz, x)
if hertz < 1000.0:
break
hertz /= 1000.0

return string


def string_to_type(string):
"""Return a typed representation for the given string.

The result might be a bool, int or float. The string might also be
supplemented by a multiplier like KB which would return an int or
float multiplied by 1024 for example.

:param string: The string representation.
"""
for regex, formatter in TYPE_FORMATS:
match = regex.match(string)
if match:
string = formatter(match)
if len(match.groups()) > 1:
unit = match.group(2)
for regex, multiplier in TYPE_MULTIPLIERS:
match = regex.match(unit)
if match:
string *= multiplier
break
else:
raise ValueError("Unknown multiplier: %s" % unit)
break

return string
Loading
Loading