Skip to content

Commit

Permalink
kernelci/api: helper for version fields translation
Browse files Browse the repository at this point in the history
Implement `KernelVersion.translate_version_fields` method to
translate version string fields to integers.
Use it to write a helper function to enable its use
in the pipeline tarball service.

Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
  • Loading branch information
Jeny Sadadia committed Feb 19, 2024
1 parent 92f57ef commit ae84913
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernelci/api/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import requests

from . import API
from .models import KernelVersion


class APIHelper:
Expand Down Expand Up @@ -222,3 +223,7 @@ def load_json(cls, json_path, encoding='utf-8'):
"""Read content from JSON file"""
with open(json_path, encoding=encoding) as json_file:
return json.load(json_file)

def translate_version_fields(self, params: dict):

Check warning on line 227 in kernelci/api/helper.py

View workflow job for this annotation

GitHub Actions / Lint

Method could be a function
"""Translate kernel version fields"""
return KernelVersion.translate_version_fields(params)
13 changes: 13 additions & 0 deletions kernelci/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ class KernelVersion(BaseModel):
description="Version name e.g. People's Front for v4.19"
)

_STRICT_INT_FIELDS = ['version', 'patchlevel', 'sublevel']

@classmethod
def translate_version_fields(cls, params):
"""Translate StrictInt fields into `int` instances
Generate 2-tuple (key, value) objects for the parameters that need to
be converted to integer.
"""
for key, value in params.items():
if key in cls._STRICT_INT_FIELDS:
yield key, int(value)


class Revision(BaseModel):
"""Linux kernel Git revision model"""
Expand Down

0 comments on commit ae84913

Please sign in to comment.