def generate_schema(project_root_path, logger):
    """
    Call django migrations to create testing database schema
    :param project_root_path: The full path to the root directory of the project
    :param logger: log handler
    :return: True: exit code of script was 0
             False: exit code of script was non-zero
    """
    path_to_manage = os.path.join(project_root_path, 'WebApp', 'autoreduce_webapp', 'manage.py')
    for database in ['admin', 'sessions', 'auth', 'reduction_viewer', 'instrument']:
        logger.info("Migrating %s" % database)
        if run_process_and_log([sys.executable, path_to_manage, 'makemigrations', database]) is False:
            logger.error("Error encountered when makingmigrations for %s" % database)
            return False
        if run_process_and_log([sys.executable, path_to_manage, 'migrate', database]) is False:
            logger.error("Error encountered when migrating %s" % database)
            return False

    logger.info("Adding super user")
    # Custom manage.py command
    if run_process_and_log([sys.executable, path_to_manage, 'add_super']) is False:
        logger.error("Error encountered when adding super user")
        return False
    logger.info("Database migrated successfully")
    return True
Exemple #2
0
def install_service(service_name, log_handler):
    """
    Given a service name, find the correct install script, run it and return boolean for success
    :param service_name: The name of the service to install
    :param log_handler: Handler for logging build info
    :return: True: exit code of installation script was 0
             False: exit code of installation script was non-zero
    """
    install_script = os.path.join(PATH_TO_DIR, (service_name + '.{}'))
    install_path = INSTALL_DIRS[service_name]
    unzip_path = ''
    if os.name == 'nt':
        if service_name == 'mantid':
            # No need to install mantid on windows currently so skip this
            return True
        install_script = install_script.format('bat')
        unzip_path = INSTALL_DIRS['7zip-location']
    else:
        install_script = install_script.format('sh')

    log_handler.logger.info("Installing %s with script %s" %
                            (service_name, install_script))
    if run_process_and_log([install_script, install_path, unzip_path
                            ]) is False:
        log_handler.print_and_log(
            "Error encountered when installing %s. "
            "Check the build.log for more information." % service_name,
            logging.ERROR)
        return False

    log_handler.print_and_log("%s installed successfully" % service_name)
    return True
Exemple #3
0
 def run(self):
     """
     If activemq in expected install path, run `activemq start`
     """
     # pylint:disable=import-outside-toplevel
     from build.settings import ACTIVEMQ_EXECUTABLE
     location = ACTIVEMQ_EXECUTABLE
     if os.name == 'nt':
         location = location + '.bat'
         start_new_terminal = ['start', 'cmd', '/c']
         if self._check_valid_path(location):
             run_process_with_shell(start_new_terminal +
                                    [location, 'start'])
             time.sleep(
                 2
             )  # Ensure that activemq process has started before you continue
     else:
         if self._check_valid_path(location):
             if run_process_and_log([location, 'start']):
                 time.sleep(
                     2
                 )  # Ensure that activemq process has started before you continue
             else:
                 print("Unable to start ActiveMQ service."
                       " Please see build.log for details.")
def load_fixtures(project_root_path, fixtures: list, logger):
    """
    Load fixtures into the database
    """

    path_to_manage = os.path.join(project_root_path, 'WebApp', 'autoreduce_webapp', 'manage.py')
    for fixture in fixtures:
        if run_process_and_log([sys.executable, path_to_manage, 'loaddata', fixture]) is False:
            logger.error("Error encountered when running loaddata for fixture %s" % fixture)
            return False
    return True