From 470a393982b203c29b7c5fb105dc9ffb8c15e576 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Oct 14 2020 07:44:39 +0000 Subject: Add new layout for packages that missing specfile Some packages are missing some files that are essential for other layouts. For example specfile(s). Rpkg detects these packages and assigns the layout to them. It allows 'retire' command for these packages. JIRA: RHELCMP-2682 Resolves: rhbz#1885771 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/layout/__init__.py b/pyrpkg/layout/__init__.py index 7a3370a..8055d52 100644 --- a/pyrpkg/layout/__init__.py +++ b/pyrpkg/layout/__init__.py @@ -11,7 +11,8 @@ from pyrpkg.errors import LayoutError from .base import MetaLayout -from .layouts import DistGitLayout, RetiredLayout, SRPMLayout # noqa +from .layouts import (DistGitLayout, IncompleteLayout, RetiredLayout, + SRPMLayout) # noqa def build(path): diff --git a/pyrpkg/layout/layouts.py b/pyrpkg/layout/layouts.py index fe91b8c..3e4cec1 100644 --- a/pyrpkg/layout/layouts.py +++ b/pyrpkg/layout/layouts.py @@ -79,6 +79,33 @@ class SRPMLayout(BaseLayout): return cls(root_dir=path) +class IncompleteLayout(BaseLayout): + """ + This layout is possibly missing specfile(s) or some other essentials + of previous layouts. Doesn't have to be retired yet. Just enough layout + to allow run 'retire' command. + """ + def __init__(self, root_dir=None, sources_file_template='sources'): + """ + Default class constructor to create a new object instance. + """ + self.root_dir = root_dir + self.sources_file_template = sources_file_template + + @classmethod + def from_path(cls, path): + """ + Creates a new object instance from a valid path in the file system. + + Raises exception if package is already retired. + """ + super(IncompleteLayout, cls).from_path(path) + + if cls(root_dir=path).is_retired(): + raise LayoutError('Retired marker found.') + return cls(root_dir=path) + + class RetiredLayout(BaseLayout): """ This class represents situation that package or module is retired. diff --git a/tests/fixtures/layouts/incomplete-package/foobar.txt b/tests/fixtures/layouts/incomplete-package/foobar.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/fixtures/layouts/incomplete-package/foobar.txt diff --git a/tests/test_layout_incomplete.py b/tests/test_layout_incomplete.py new file mode 100644 index 0000000..04589fd --- /dev/null +++ b/tests/test_layout_incomplete.py @@ -0,0 +1,37 @@ +import os +import unittest + +from pyrpkg.layout import layouts +from pyrpkg import errors + + +fixtures_dir = os.path.join(os.path.dirname(__file__), 'fixtures') + + +class IncompleteLayoutTestCase(unittest.TestCase): + def setUp(self): + self.workdir = os.path.join(fixtures_dir, 'layouts/incomplete-package') + self.layout = layouts.IncompleteLayout.from_path(self.workdir) + + def test_layout_data(self): + self.assertEqual(self.layout.sourcedir, None) + self.assertEqual(self.layout.specdir, None) + self.assertEqual(self.layout.specdir, None) + self.assertEqual(self.layout.root_dir, self.workdir) + self.assertEqual(self.layout.builddir, None) + self.assertEqual(self.layout.rpmdir, None) + self.assertEqual(self.layout.srcrpmdir, None) + self.assertEqual(self.layout.sources_file_template, 'sources') + + def test_layout_not_retired(self): + self.assertEqual(None, self.layout.is_retired()) + + +class IncompleteLayoutErrorsTestCase(unittest.TestCase): + def setUp(self): + self.workdir = os.path.join(fixtures_dir, 'layouts') + + def test_path_error(self): + with self.assertRaises(errors.LayoutError) as e: + layouts.IncompleteLayout.from_path(os.path.join(self.workdir, 'notfound')) + self.assertEqual('package path does not exist', e.exception.args[0])