From ada039c13144fb10b0b1910a552012f70437cf98 Mon Sep 17 00:00:00 2001 From: Galileo Sartor Date: Fri, 18 Oct 2019 13:29:14 +0200 Subject: [PATCH 1/3] Move depends def and add test --- tests/small/test_frameworks_loader.py | 16 ++++++++++++++++ umake/__init__.py | 1 + umake/frameworks/__init__.py | 17 ++++++++++++++++- umake/frameworks/baseinstaller.py | 9 +++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/small/test_frameworks_loader.py b/tests/small/test_frameworks_loader.py index cfb853d2..72bcaf25 100644 --- a/tests/small/test_frameworks_loader.py +++ b/tests/small/test_frameworks_loader.py @@ -318,6 +318,22 @@ def test_parse_no_framework_run_default_for_category(self): self.assertTrue(setup_call.called) self.assertEqual(setup_call.call_args, call(install_path=None, auto_accept_license=False)) + def test_parse_category_and_framework_list_dependencies(self): + """Parsing category will run default framework""" + args = Mock() + args.category = "category-a" + args.destdir = None + args.framework = "framework-b" + args.depends = True + args.accept_license = False + args.remove = False + with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-a"], "depends")\ + as depends_call: + self.CategoryHandler.categories[args.category].run_for(args) + self.assertTrue(depends_call.called) + remove_call.assert_called_with() + # self.assertEqual(setup_call.call_args, call(install_path=None, auto_accept_license=False)) + def test_parse_category_and_framework_run_correct_remove_framework(self): """Parsing category and framework with --remove run remove on right category and framework""" args = Mock() diff --git a/umake/__init__.py b/umake/__init__.py index 13b5749e..83bb45af 100644 --- a/umake/__init__.py +++ b/umake/__init__.py @@ -132,6 +132,7 @@ def main(): parser.add_argument("-v", "--verbose", action="count", default=0, help=_("Increase output verbosity (2 levels)")) parser.add_argument('-r', '--remove', action="store_true", help=_("Remove specified framework if installed")) + parser.add_argument('-d', '--depends', action="store_true", help=_("List specified framework dependencies")) list_group = parser.add_argument_group("List frameworks").add_mutually_exclusive_group() list_group.add_argument('-l', '--list', action="store_true", help=_("List all frameworks")) diff --git a/umake/frameworks/__init__.py b/umake/frameworks/__init__.py index 4d825406..7e77fed2 100644 --- a/umake/frameworks/__init__.py +++ b/umake/frameworks/__init__.py @@ -34,6 +34,7 @@ from umake.settings import DEFAULT_INSTALL_TOOLS_PATH, UMAKE_FRAMEWORKS_ENVIRON_VARIABLE, DEFAULT_BINARY_LINK_PATH from umake.tools import ConfigHandler, NoneDict, classproperty, get_current_arch, get_current_distro_version,\ is_completion_mode, switch_to_current_user, MainLoop, get_user_frameworks_path, get_current_distro_id +from umake.interactions import DisplayMessage from umake.ui import UI @@ -263,6 +264,13 @@ def setup(self): # be a normal, kind user as we don't want normal files to be written as root switch_to_current_user() + @abc.abstractmethod + def depends(self): + """Method call to list depends for current framework""" + if not self.is_installable: + logger.error(_("Framework {} is not installable".format(self.name))) + UI.return_main_screen(status_code=2) + @abc.abstractmethod def remove(self): """Method call to remove the current framework""" @@ -302,7 +310,8 @@ def install_framework_parser(self, parser): help=_("Remove framework if installed")) this_framework_parser.add_argument('--dry-run', dest="dry_run", action="store_true", help=_("Fetch only the url, then exit.")) - + this_framework_parser.add_argument('-d', '--depends', action="store_true", + help=_("List dependencies")) if self.expect_license: this_framework_parser.add_argument('--accept-license', dest="accept_license", action="store_true", help=_("Accept license without prompting")) @@ -317,6 +326,12 @@ def run_for(self, args): logger.error(message) UI.return_main_screen(status_code=2) self.remove() + if args.depends: + if args.destdir: + message = "You can't specify a destination dir while listing framework dependencies" + logger.error(message) + UI.return_main_screen(status_code=2) + self.depends() else: install_path = None auto_accept_license = False diff --git a/umake/frameworks/baseinstaller.py b/umake/frameworks/baseinstaller.py index fd00199a..05599dea 100644 --- a/umake/frameworks/baseinstaller.py +++ b/umake/frameworks/baseinstaller.py @@ -122,6 +122,15 @@ def reinstall(self): self.confirm_path(self.arg_install_path) remove_framework_envs_from_user(self.name) + def depends(self): + """List necessary apt dependencies""" + if not self.need_root_access: + UI.display(DisplayMessage("Required packages are installed")) + else: + UI.display(DisplayMessage("Required packages will be installed")) + UI.display(DisplayMessage(' '.join(self.packages_requirements))) + UI.return_main_screen(status_code=0) + def remove(self): """Remove current framework if installed From 20a5fe512c7e4f215f9c6a85c48dec52092b8247 Mon Sep 17 00:00:00 2001 From: Galileo Sartor Date: Fri, 8 Nov 2019 10:27:44 +0100 Subject: [PATCH 2/3] Add depends method to tests --- tests/data/testframeworks/anotherothercategory.py | 6 ++++++ tests/data/testframeworks/category_f.py | 9 +++++++++ tests/data/testframeworks/category_g.py | 6 ++++++ tests/data/testframeworks/framework_for_removal.py | 9 +++++++++ tests/data/testframeworks/is_installable.py | 9 +++++++++ tests/data/testframeworks/oneframeworkcategory.py | 3 +++ tests/data/testframeworks/othercategory.py | 6 ++++++ tests/data/testframeworks/restrictions.py | 9 +++++++++ tests/data/testframeworks/uninstantiableframework.py | 3 +++ tests/data/testframeworks/withcategory.py | 6 ++++++ tests/data/testframeworks/withoutcategory.py | 6 ++++++ 11 files changed, 72 insertions(+) diff --git a/tests/data/testframeworks/anotherothercategory.py b/tests/data/testframeworks/anotherothercategory.py index 9a13b805..19cb0a0a 100644 --- a/tests/data/testframeworks/anotherothercategory.py +++ b/tests/data/testframeworks/anotherothercategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return False @@ -58,6 +61,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return True diff --git a/tests/data/testframeworks/category_f.py b/tests/data/testframeworks/category_f.py index 183b4e9f..39a1014b 100644 --- a/tests/data/testframeworks/category_f.py +++ b/tests/data/testframeworks/category_f.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -55,6 +58,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkC(umake.frameworks.BaseFramework): @@ -67,3 +73,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/testframeworks/category_g.py b/tests/data/testframeworks/category_g.py index dd2b46e5..5e2c67a8 100644 --- a/tests/data/testframeworks/category_g.py +++ b/tests/data/testframeworks/category_g.py @@ -42,6 +42,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -54,3 +57,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/testframeworks/framework_for_removal.py b/tests/data/testframeworks/framework_for_removal.py index c322ea82..f010e5c9 100644 --- a/tests/data/testframeworks/framework_for_removal.py +++ b/tests/data/testframeworks/framework_for_removal.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkRinstalled(umake.frameworks.BaseFramework): @@ -54,6 +57,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return True @@ -72,6 +78,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return True diff --git a/tests/data/testframeworks/is_installable.py b/tests/data/testframeworks/is_installable.py index edf95831..e33da244 100644 --- a/tests/data/testframeworks/is_installable.py +++ b/tests/data/testframeworks/is_installable.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installable(self): return super().is_installable @@ -60,6 +63,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installable(self): """overridden to say True""" @@ -79,6 +85,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installable(self): """overridden to say False""" diff --git a/tests/data/testframeworks/oneframeworkcategory.py b/tests/data/testframeworks/oneframeworkcategory.py index a3cab683..0ff3e72c 100644 --- a/tests/data/testframeworks/oneframeworkcategory.py +++ b/tests/data/testframeworks/oneframeworkcategory.py @@ -40,3 +40,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/testframeworks/othercategory.py b/tests/data/testframeworks/othercategory.py index 7a9ce825..a17df3ae 100644 --- a/tests/data/testframeworks/othercategory.py +++ b/tests/data/testframeworks/othercategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return True @@ -58,6 +61,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installed(self): return True diff --git a/tests/data/testframeworks/restrictions.py b/tests/data/testframeworks/restrictions.py index e2dc452c..e22de1f7 100644 --- a/tests/data/testframeworks/restrictions.py +++ b/tests/data/testframeworks/restrictions.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -54,6 +57,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkC(umake.frameworks.BaseFramework): @@ -67,3 +73,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/testframeworks/uninstantiableframework.py b/tests/data/testframeworks/uninstantiableframework.py index ad0e39cf..fc3150b7 100644 --- a/tests/data/testframeworks/uninstantiableframework.py +++ b/tests/data/testframeworks/uninstantiableframework.py @@ -40,6 +40,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class InheritedFromUninstantiable(Uninstantiable): diff --git a/tests/data/testframeworks/withcategory.py b/tests/data/testframeworks/withcategory.py index e80a7426..2e90e842 100644 --- a/tests/data/testframeworks/withcategory.py +++ b/tests/data/testframeworks/withcategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/testframeworks/withoutcategory.py b/tests/data/testframeworks/withoutcategory.py index d858c261..5126ebf1 100644 --- a/tests/data/testframeworks/withoutcategory.py +++ b/tests/data/testframeworks/withoutcategory.py @@ -35,6 +35,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkFreeB(umake.frameworks.BaseFramework): @@ -47,3 +50,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() From 9d70cf3aa9fb8da1b5b8bd04123bb67a19288557 Mon Sep 17 00:00:00 2001 From: Galileo Sartor Date: Thu, 3 Sep 2020 18:42:23 +0200 Subject: [PATCH 3/3] Fix tests to add depends option --- tests/data/duplicatedframeworks/category.py | 6 ++++++ tests/data/duplicatedframeworks/samecategory.py | 6 ++++++ .../defaultframeworkformain.py | 3 +++ .../multipledefaultsframeworks/twodefaultscategory.py | 6 ++++++ tests/data/overlayframeworks/duplicatedcategory.py | 6 ++++++ tests/data/overlayframeworks/duplicatedcategory2.py | 6 ++++++ tests/data/overlayframeworks/overlayframeworks.py | 6 ++++++ tests/data/overlayframeworks/withcategory.py | 6 ++++++ tests/data/overlayframeworks/withcategory2.py | 6 ++++++ tests/small/test_frameworks_loader.py | 11 +++++++++-- umake/frameworks/__init__.py | 3 +-- 11 files changed, 61 insertions(+), 4 deletions(-) diff --git a/tests/data/duplicatedframeworks/category.py b/tests/data/duplicatedframeworks/category.py index f5becb2b..3e6a7c1a 100644 --- a/tests/data/duplicatedframeworks/category.py +++ b/tests/data/duplicatedframeworks/category.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/duplicatedframeworks/samecategory.py b/tests/data/duplicatedframeworks/samecategory.py index 33910dc8..6be898c2 100644 --- a/tests/data/duplicatedframeworks/samecategory.py +++ b/tests/data/duplicatedframeworks/samecategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkD(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/multipledefaultsframeworks/defaultframeworkformain.py b/tests/data/multipledefaultsframeworks/defaultframeworkformain.py index 003ccfbb..83e3e4d4 100644 --- a/tests/data/multipledefaultsframeworks/defaultframeworkformain.py +++ b/tests/data/multipledefaultsframeworks/defaultframeworkformain.py @@ -34,3 +34,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/multipledefaultsframeworks/twodefaultscategory.py b/tests/data/multipledefaultsframeworks/twodefaultscategory.py index 4cfec322..d7cd9d60 100644 --- a/tests/data/multipledefaultsframeworks/twodefaultscategory.py +++ b/tests/data/multipledefaultsframeworks/twodefaultscategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/overlayframeworks/duplicatedcategory.py b/tests/data/overlayframeworks/duplicatedcategory.py index 6bdb59ae..60a4c161 100644 --- a/tests/data/overlayframeworks/duplicatedcategory.py +++ b/tests/data/overlayframeworks/duplicatedcategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/overlayframeworks/duplicatedcategory2.py b/tests/data/overlayframeworks/duplicatedcategory2.py index da942a2b..59ad8598 100644 --- a/tests/data/overlayframeworks/duplicatedcategory2.py +++ b/tests/data/overlayframeworks/duplicatedcategory2.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/overlayframeworks/overlayframeworks.py b/tests/data/overlayframeworks/overlayframeworks.py index 7f45faca..c2b72f9f 100644 --- a/tests/data/overlayframeworks/overlayframeworks.py +++ b/tests/data/overlayframeworks/overlayframeworks.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/overlayframeworks/withcategory.py b/tests/data/overlayframeworks/withcategory.py index 7f45faca..c2b72f9f 100644 --- a/tests/data/overlayframeworks/withcategory.py +++ b/tests/data/overlayframeworks/withcategory.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/data/overlayframeworks/withcategory2.py b/tests/data/overlayframeworks/withcategory2.py index a59264a7..e3a4ab3b 100644 --- a/tests/data/overlayframeworks/withcategory2.py +++ b/tests/data/overlayframeworks/withcategory2.py @@ -41,6 +41,9 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + def depends(self): + super().depends() + class FrameworkB(umake.frameworks.BaseFramework): @@ -53,3 +56,6 @@ def setup(self, install_path=None, auto_accept_license=False): def remove(self): super().remove() + + def depends(self): + super().depends() diff --git a/tests/small/test_frameworks_loader.py b/tests/small/test_frameworks_loader.py index 72bcaf25..ebea974c 100644 --- a/tests/small/test_frameworks_loader.py +++ b/tests/small/test_frameworks_loader.py @@ -297,6 +297,7 @@ def test_parse_category_and_framework_run_correct_framework(self): args.framework = "framework-b" args.accept_license = False args.remove = False + args.depends = False with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-b"], "setup")\ as setup_call: self.CategoryHandler.categories[args.category].run_for(args) @@ -312,6 +313,7 @@ def test_parse_no_framework_run_default_for_category(self): args.framework = None args.accept_license = False args.remove = False + args.depends = False with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-a"], "setup")\ as setup_call: self.CategoryHandler.categories[args.category].run_for(args) @@ -327,11 +329,11 @@ def test_parse_category_and_framework_list_dependencies(self): args.depends = True args.accept_license = False args.remove = False - with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-a"], "depends")\ + with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-b"], "depends")\ as depends_call: self.CategoryHandler.categories[args.category].run_for(args) self.assertTrue(depends_call.called) - remove_call.assert_called_with() + depends_call.assert_called_with() # self.assertEqual(setup_call.call_args, call(install_path=None, auto_accept_license=False)) def test_parse_category_and_framework_run_correct_remove_framework(self): @@ -393,6 +395,7 @@ def test_parse_category_and_framework_cannot_install_not_installable_but_install args.framework = "framework-r-installed-not-installable" args.accept_license = False args.remove = False + args.depends = False self.assertRaises(BaseException, self.CategoryHandler.categories[args.category].run_for, args) def test_parse_category_and_framework_can_remove_not_installable_but_installed_framework(self): @@ -418,6 +421,7 @@ def test_parse_category_and_framework_get_accept_license_arg(self): args.framework = "framework-b" args.accept_license = True args.remove = False + args.depends = False with patch.object(self.CategoryHandler.categories[args.category].frameworks["framework-b"], "setup")\ as setup_call: self.CategoryHandler.categories[args.category].run_for(args) @@ -1305,6 +1309,9 @@ def setup(self): def remove(self): super().remove() + def depends(self): + super().depends() + @property def is_installable(self): return False diff --git a/umake/frameworks/__init__.py b/umake/frameworks/__init__.py index 7e77fed2..a4ee5442 100644 --- a/umake/frameworks/__init__.py +++ b/umake/frameworks/__init__.py @@ -34,7 +34,6 @@ from umake.settings import DEFAULT_INSTALL_TOOLS_PATH, UMAKE_FRAMEWORKS_ENVIRON_VARIABLE, DEFAULT_BINARY_LINK_PATH from umake.tools import ConfigHandler, NoneDict, classproperty, get_current_arch, get_current_distro_version,\ is_completion_mode, switch_to_current_user, MainLoop, get_user_frameworks_path, get_current_distro_id -from umake.interactions import DisplayMessage from umake.ui import UI @@ -267,7 +266,7 @@ def setup(self): @abc.abstractmethod def depends(self): """Method call to list depends for current framework""" - if not self.is_installable: + if not self.is_installable and not self.is_installed: logger.error(_("Framework {} is not installable".format(self.name))) UI.return_main_screen(status_code=2)