diff --git a/libraries/entropy/qa.py b/libraries/entropy/qa.py index 302f014de..0d6d3f9a2 100644 --- a/libraries/entropy/qa.py +++ b/libraries/entropy/qa.py @@ -991,6 +991,18 @@ class QAInterface: return valid + def __check_package_using_spm(self, package_path): + + from entropy.spm.plugins.factory import get_default_class + spm_class = get_default_class() + spm_rc, spm_msg = spm_class.execute_qa_tests(package_path) + + if spm_rc == 0: + return True + sys.stderr.write("QA Error: " + spm_msg) + sys.stderr.flush() + return False + def entropy_package_checks(self, package_path): """ Main method for the execution of QA tests on physical Entropy @@ -1001,7 +1013,8 @@ class QAInterface: @return: True, if all checks passed @rtype: bool """ - qa_methods = [self.__analyze_package_edb] + qa_methods = [self.__analyze_package_edb, + self.__check_package_using_spm] for method in qa_methods: qa_rc = method(package_path) if not qa_rc: diff --git a/libraries/entropy/spm/plugins/interfaces/portage_plugin.py b/libraries/entropy/spm/plugins/interfaces/portage_plugin.py index e5e1eff8b..4a3bc3ce0 100644 --- a/libraries/entropy/spm/plugins/interfaces/portage_plugin.py +++ b/libraries/entropy/spm/plugins/interfaces/portage_plugin.py @@ -2028,6 +2028,63 @@ class PortagePlugin(SpmPlugin): return 0 + @staticmethod + def execute_qa_tests(package_path): + """ + Reimplemented from SpmPlugin class. + """ + tests = [PortagePlugin._test_environment_bz2] + msg = None + exec_rc = 0 + for test in tests: + exec_rc, msg = test(package_path) + if exec_rc != 0: + break + return exec_rc, msg + + @staticmethod + def _test_environment_bz2(package_path): + + tmp_path = tempfile.mkdtemp() + entropy.tools.extract_xpak(package_path, tmpdir = tmp_path) + if not os.listdir(tmp_path): + shutil.rmtree(tmp_path) + return 1, "unable to extract xpak metadata" + + # make sure we have the environment.bz2 file to check + env_file = os.path.join(tmp_path, PortagePlugin.ENV_FILE_COMP) + if not (os.path.isfile(env_file) and os.access(env_file, os.R_OK)): + shutil.rmtree(tmp_path) + return 2, "unable to locate %s file" % ( + PortagePlugin.ENV_FILE_COMP,) + + # read env file + bz_f = bz2.BZ2File(env_file, "r") + valid_lc_all = True + msg = None + lc_all_str = const_convert_to_rawstring("LC_ALL") + lc_all_c = const_convert_to_rawstring("LC_ALL=C") + lc_all_enus = const_convert_to_rawstring("LC_ALL=en_US") + try: + + for line in bz_f.readlines(): + if line.startswith(lc_all_str): + if line.startswith(lc_all_c) or \ + line.startswith(lc_all_enus): + continue + valid_lc_all = False + msg = "LC_ALL set to => %s" % (line.strip(),) + break + + finally: + bz_f.close() + + env_rc = 0 + if not valid_lc_all: + env_rc = 1 + shutil.rmtree(tmp_path) + return env_rc, msg + @staticmethod def entropy_install_setup_hook(entropy_client, package_metadata): """ diff --git a/libraries/entropy/spm/plugins/skel.py b/libraries/entropy/spm/plugins/skel.py index 4af445ede..6b14b6708 100644 --- a/libraries/entropy/spm/plugins/skel.py +++ b/libraries/entropy/spm/plugins/skel.py @@ -524,6 +524,12 @@ class SpmPlugin(Singleton): files. This method can be used to test Entropy produced packages to make sure that they are fine on this side too. It is called by Entropy QA module (entropy.qa). + + @param package_path: path to Entropy package + @type package_path: string + @return: tuple composed by error status and error message (if any). + Error status is an int with != 0 values if error occured. + @rtype: tuple """ raise NotImplementedError()