-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add distroinfo and initial skeleton structure
- Loading branch information
Showing
12 changed files
with
245 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ Sphinx==1.8.5 | |
twine==1.14.0 | ||
|
||
pytest==4.6.5 | ||
pytest-runner==5.1 | ||
pytest-runner==5.1 | ||
|
||
Distroinfo>=0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Parse configuration information.""" | ||
|
||
from distroinfo import info | ||
|
||
|
||
def parse_distro_info_path(path): | ||
"""Break distro_info path into repo + file""" | ||
path = path.strip().rsplit("/", 1) | ||
info_repo = path[0] | ||
info_file = path[1] | ||
remote = False | ||
|
||
if info_repo.startswith("http"): | ||
remote = True | ||
|
||
return info_file, info_repo, remote | ||
|
||
|
||
def setup_distro_info(distroinfo_repo): | ||
"""Set up distro_info based on path""" | ||
info_file, info_repo, remote = parse_distro_info_path(distroinfo_repo) | ||
|
||
if remote: | ||
di = info.DistroInfo(info_file, remote_git_info=info_repo) | ||
else: | ||
di = info.DistroInfo(info_file, local_info=info_repo) | ||
|
||
return di.get_info() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /usr/bin/env python | ||
"""This module acts as an interface for locating patches in composes""" | ||
|
||
|
||
class ComposeLocator(object): | ||
|
||
def __init__(self, locator, logger): | ||
"""Constructor for ComposeLocator object | ||
:param rtls.Locator locator: A pre-constructed Locator | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
self.locator = locator | ||
self.logger = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /usr/bin/env python | ||
"""This module acts as an interface for locating patches in containers""" | ||
|
||
|
||
class ContainerLocator(object): | ||
|
||
def __init__(self, locator, logger): | ||
"""Constructor for ContainerLocator object | ||
:param rtls.Locator locator: A pre-constructed Locator | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
self.locator = locator | ||
self.logger = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /usr/bin/env python | ||
"""This module acts as an interface for locating patches in git""" | ||
|
||
|
||
class GitLocator(object): | ||
|
||
def __init__(self, distro_info, logger): | ||
"""Constructor for GitLocator object | ||
:param dict distro_info: A distro info dictionary | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
self.distro_info = distro_info | ||
self.logger = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#! /usr/bin/env python | ||
"""This module acts as an interface for locating patches in rpms""" | ||
|
||
|
||
class RpmLocator(object): | ||
|
||
def __init__(self, distro_info, logger): | ||
"""Constructor for RpmLocator object | ||
:param dict distro_info: A distro info dictionary | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
self.distro_info = distro_info | ||
self.logger = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,121 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Main module.""" | ||
|
||
import logging | ||
|
||
from rtls import config | ||
from rtls.lib.git import GitLocator | ||
from rtls.lib.rpm import RpmLocator | ||
from rtls.lib.compose import ComposeLocator | ||
from rtls.lib.container import ContainerLocator | ||
|
||
|
||
LOGGER = logging.getLogger("rtls") | ||
LOGGER.setLevel(logging.INFO) | ||
|
||
|
||
class Locator(object): | ||
"""Provides functions to locate a patch through its life cycle""" | ||
|
||
def __init__(self, distroinfo_path='', logger=None): | ||
"""Constructor for Locator object | ||
:param str distroinfo_path: Path to local or remote distroinfo repo | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
self._git = None | ||
self._rpm = None | ||
self._container = None | ||
self._compose = None | ||
|
||
self.distro_info = config.setup_distro_info(distroinfo_path) | ||
self._setup_logger(logger) | ||
|
||
def _setup_logger(self, logger): | ||
"""Set up a pre-configured logger or create a new one | ||
:param logging.Logger logger: A pre-configured Python Logger object | ||
""" | ||
if logger: | ||
self.logger = logger | ||
else: | ||
self.logger = logging.getLogger(__name__) | ||
|
||
@property | ||
def git(self): | ||
"""Return object to locate a patch in git""" | ||
if not self._git: | ||
self._git = GitLocator(distro_info=self.distro_info, | ||
logger=self.logger) | ||
return self._git | ||
|
||
@git.setter | ||
def git(self, new_git): | ||
"""Set up object to interact with git | ||
:param rtls.git.GitLocator new_git: Pre-constructed GitLocator | ||
""" | ||
if not isinstance(new_git, GitLocator): | ||
raise TypeError("Git must be a GitLocator object.") | ||
self._git = new_git | ||
|
||
@property | ||
def rpm(self): | ||
"""Return object to locate a patch in rpms""" | ||
if not self._rpm: | ||
self._rpm = RpmLocator(distro_info=self.distro_info, | ||
logger=self.logger) | ||
return self._rpm | ||
|
||
@rpm.setter | ||
def rpm(self, new_rpm): | ||
"""Set up object to interact with rpms | ||
:param rtls.rpm.RpmLocator new_rpm: Pre-constructed RpmLocator | ||
""" | ||
if not isinstance(new_rpm, RpmLocator): | ||
raise TypeError("Rpm must be a RpmLocator object.") | ||
self._rpm = new_rpm | ||
|
||
@property | ||
def container(self): | ||
"""Return object to locate a patch in containers""" | ||
if not self._container: | ||
# TODO: Only send the required config options rather than | ||
# the full Locator | ||
self._container = ContainerLocator( | ||
locator=self, logger=self.logger | ||
) | ||
return self._container | ||
|
||
@container.setter | ||
def container(self, new_container): | ||
"""Set up object to interact with containers | ||
:param rtls.container.ContainerLocator new_container: | ||
Pre-constructed ContainerLocator | ||
""" | ||
if not isinstance(new_container, ContainerLocator): | ||
raise TypeError("Container must be a ContainerLocator object.") | ||
self._container = new_container | ||
|
||
@property | ||
def compose(self): | ||
"""Return object to locate a patch in composes""" | ||
if not self._compose: | ||
# TODO: Only send the required config options rather than | ||
# the full Locator | ||
self._compose = ComposeLocator(locator=self, logger=self.logger) | ||
return self._compose | ||
|
||
@compose.setter | ||
def compose(self, new_compose): | ||
"""Set up object to interact with composes | ||
:param rtls.compose.ComposeLocator new_compose: Pre-constructed | ||
ComposeLocator | ||
""" | ||
if not isinstance(new_compose, ComposeLocator): | ||
raise TypeError("Compose must be a ComposeLocator object.") | ||
self._compose = new_compose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Tests for `rtls.config` package.""" | ||
|
||
from rtls.config import parse_distro_info_path | ||
|
||
|
||
def test_parse_distro_info_path(): | ||
# Result form: file, path, remote boolean | ||
data = { | ||
"/home/dlrn/di/test.yaml": ("test.yaml", "/home/dlrn/di", False), | ||
"https://example.com/info/info.yml": ("info.yml", | ||
"https://example.com/info", | ||
True), | ||
} | ||
|
||
for path, result in data.items(): | ||
assert parse_distro_info_path(path) == result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters