def _install_7zip(self, packages_to_install): if '7zip' in packages_to_install: BUILD_LOGGER.print_and_log("Installing 7zip") if install_package('7zip', BUILD_LOGGER) is False: print("Unable to install 7zip. Check build logs for more info") return del self.packages['7zip'] packages_to_install.remove('7zip')
def _check_input(self): """ Check the user input is valid :return: False if user input is invalid """ # pylint:disable=import-outside-toplevel from build.install.install_services import valid_services, validate_input if not validate_input(self.services, BUILD_LOGGER): BUILD_LOGGER.print_and_log( "Some services supplied were not valid.\n" "Valid services are: %s" % valid_services(), logging.ERROR) return False return True
def check_input(packages): """ Check the user input is valid. @returns :: False if user input is invalid """ from build.install.install_packages import valid_packages, validate_input if not validate_input(packages, BUILD_LOGGER): BUILD_LOGGER.print_and_log("Some packages supplied were not valid.\n" "Optional valid packages are: %s" % valid_packages(), logging.ERROR) return False return True
def _check_imports(): """ Check that imports can be performed :return: False if imports fail """ try: # pylint:disable=unused-import,import-outside-toplevel from build.install.install_services import (install_service, validate_input, valid_services) except ImportError: BUILD_LOGGER.print_and_log( "Could not import install_services. " "Have you migrated the test settings correctly?", logging.ERROR) return False return True
def check_imports(): """ Check that imports can be performed. @returns :: False if imports fail """ try: # pylint:disable=unused-variable from build.install.install_packages import (install_package, validate_input, valid_packages) except ImportError: BUILD_LOGGER.print_and_log("Could not import install_packages. ", logging.ERROR) return False return True
def run(self): """ Validate packages to see if any are currently installed Install each package required by the project that did not validate Re-validate to ensure packages are now installed """ self._perform_preliminary_checks() BUILD_LOGGER.print_and_log("=== Installing external dependencies ===") packages_to_install = self._get_valid_packages_to_install() # explanation for installing the below is in build.install.install_packages self._install_7zip(packages_to_install) self._check_package_dictionary(packages_to_install) self._install_packages(packages_to_install) self._check_if_invalid_install(packages_to_install) logging.shutdown()
def validate_packages(list_of_packages, quiet=True): """ Check if packages are installed and usable. Current checks: 7Zip, Mantid @param quiet :: boolean to decide if anything is printed on validation failure @returns :: dictionary of {"package_name": validity(True/False)} """ print("=======================") package_validity = validate_installs(list_of_packages) if quiet is False: for package in package_validity: if package_validity[package] is False: BUILD_LOGGER.print_and_log("%s: False" % package, logging.INFO) else: if package == 'mantid' and os.name == 'nt': # not required on windows BUILD_LOGGER.print_and_log("Mantid: Skipped", logging.WARNING) else: BUILD_LOGGER.print_and_log("%s: True" % package) print("=======================") return package_validity
def _validate_services(list_of_services, quiet=True): """ Check if services are installed and usable. Current checks: 7Zip, ActiveMQ, Mantid :param quiet: boolean to decide if anything is printed on validation failure :return: dictionary of {"service_name": validity(True/False)} """ # pylint:disable=import-outside-toplevel from build.tests.validate_installs import validate_installs print("=======================") service_validity = validate_installs(list_of_services) if quiet is False: for service in service_validity: if service_validity[service] is False: BUILD_LOGGER.print_and_log("%s: False" % service, logging.ERROR) else: if service == 'mantid' and os.name == 'nt': # not required on windows BUILD_LOGGER.print_and_log("Mantid: Skipped", logging.WARNING) else: BUILD_LOGGER.print_and_log("%s: True" % service) print("=======================") return service_validity
def run(self): """ Run the setup scripts required for localhost database """ # pylint:disable=import-outside-toplevel BUILD_LOGGER.print_and_log( "==================== Building Database ======================") BUILD_LOGGER.print_and_log("Migrating databases from django model") if generate_schema(ROOT_DIR, BUILD_LOGGER.logger) is False: return BUILD_LOGGER.print_and_log("Test database successfully initialised\n")
def run(self): """ Run the setup scripts required for localhost database """ # pylint:disable=import-outside-toplevel from utils.clients.database_client import DatabaseClient from utils.settings import LOCAL_MYSQL_SETTINGS local_db_connection = DatabaseClient(LOCAL_MYSQL_SETTINGS).connect() BUILD_LOGGER.print_and_log( "==================== Building Database ======================") BUILD_LOGGER.print_and_log("Migrating databases from django model") if generate_schema(ROOT_DIR, BUILD_LOGGER.logger) is False: return BUILD_LOGGER.print_and_log("Populating database with test data") if run_sql(connection=local_db_connection, sql=get_sql_from_file(self.populate_sql_path), logger=BUILD_LOGGER.logger) is False: return BUILD_LOGGER.print_and_log("Test database successfully initialised\n")
def _check_if_invalid_install(packages_to_install): valid = checks.validate_packages(packages_to_install, quiet=False) if False in valid.values(): BUILD_LOGGER.print_and_log( "One or more packages did not " "correctly install:", logging.ERROR) for package_name, _ in valid.items(): if valid[package_name] is False: BUILD_LOGGER.print_and_log("* %s" % package_name, logging.ERROR) BUILD_LOGGER.print_and_log("See build.log for more details.", logging.ERROR)
def run(self): """ Copy all test files from the test files list to desired locations """ BUILD_LOGGER.print_and_log("================== Migrate credentials ====================") self._migrate_test_settings(self.utils_path) BUILD_LOGGER.print_and_log("Credentials successfully migrated\n")
def run(self): """ Validate services to see if any are currently installed Install each service required by the project that did not validate Re-validate to ensure services are now installed """ # Validate if not self._check_imports(): return # pylint:disable=import-outside-toplevel from build.install.install_services import install_service if not self._check_input(): return BUILD_LOGGER.print_and_log("======== Installing external dependencies ==========") # pylint:disable=attribute-defined-outside-init self.services = self._validate_services(self.services.keys(), quiet=False) # Return a list of all non-valid services (those with value of false) services_to_install = [ service_name for service_name in self.services.keys() if self.services[service_name] is False ] # Ensure 7zip is installed first if '7zip' in services_to_install: BUILD_LOGGER.print_and_log("Installing 7zip (required for other installations") if install_service('7zip', BUILD_LOGGER) is False: print("Unable to install 7zip. Check build logs for more information") return del self.services['7zip'] services_to_install.remove('7zip') if not services_to_install: BUILD_LOGGER.print_and_log("Nothing to install - All given services are valid") return for service in services_to_install: if install_service(service, BUILD_LOGGER) is False: print("Unable to install %s. See build log below:" % service) BUILD_LOGGER.print_full_log() sys.exit(1) valid = self._validate_services(services_to_install, quiet=False) if False in valid.values(): BUILD_LOGGER.print_and_log("One or more services did not correctly install:", logging.ERROR) for service_name, _ in valid.items(): if valid[service_name] is False: BUILD_LOGGER.print_and_log("* %s" % service_name, logging.ERROR) BUILD_LOGGER.print_and_log("See build.log for more details.", logging.ERROR)
def _check_package_dictionary(packages_to_install): if not packages_to_install: BUILD_LOGGER.print_and_log("Nothing to install - " "All given packages are valid") return