Esempio n. 1
0
def check_index_and_wipe_out(logger):
    """
    Check index by running the indexer. If the index does not match
    currently running version and the CHECK_INDEX environment variable
    is non empty, wipe out the directories under data root.
    """
    check_index = os.environ.get('CHECK_INDEX')
    if check_index and os.path.exists(OPENGROK_CONFIG_FILE):
        logger.info('Checking if index matches current version')
        indexer_options = ['-R', OPENGROK_CONFIG_FILE, '--checkIndex']
        indexer = Indexer(indexer_options,
                          logger=logger,
                          jar=OPENGROK_JAR,
                          doprint=True)
        indexer.execute()
        if indexer.getretcode() == 1:
            logger.info('Wiping out data root')
            root = OPENGROK_DATA_ROOT
            for entry in os.listdir(root):
                path = os.path.join(root, entry)
                if os.path.isdir(path):
                    try:
                        logger.info("Removing '{}'".format(path))
                        shutil.rmtree(path)
                    except Exception as e:
                        logger.error("cannot delete '{}': {}".format(path, e))
Esempio n. 2
0
def create_bare_config(logger, use_projects, extra_indexer_options=None):
    """
    Create bare configuration file with a few basic settings.
    """

    logger.info(
        'Creating bare configuration in {}'.format(OPENGROK_CONFIG_FILE))
    indexer_options = [
        '-s', OPENGROK_SRC_ROOT, '-d', OPENGROK_DATA_ROOT, '-c',
        '/usr/local/bin/ctags', '--remote', 'on', '-H', '-S', '-W',
        OPENGROK_CONFIG_FILE, '--noIndex'
    ]

    if extra_indexer_options:
        if type(extra_indexer_options) is not list:
            raise Exception("extra_indexer_options has to be a list")
        indexer_options.extend(extra_indexer_options)
    if use_projects:
        indexer_options.append('-P')
    indexer = Indexer(indexer_options,
                      jar=OPENGROK_JAR,
                      logger=logger,
                      doprint=True)
    indexer.execute()
    ret = indexer.getretcode()
    if ret != SUCCESS_EXITVAL:
        logger.error('Command returned {}'.format(ret))
        logger.error(indexer.geterroutput())
        raise Exception("Failed to create bare configuration")
Esempio n. 3
0
def create_bare_config(logger):
    """
    Create bare configuration file with a few basic settings.
    """

    logger.info(
        'Creating bare configuration in {}'.format(OPENGROK_CONFIG_FILE))
    indexer = Indexer([
        '-s', OPENGROK_SRC_ROOT, '-d', OPENGROK_DATA_ROOT, '-c',
        '/usr/local/bin/ctags', '--remote', 'on', '-P', '-H', '-W',
        OPENGROK_CONFIG_FILE, '--noIndex'
    ],
                      jar=os.path.join(OPENGROK_LIB_DIR, 'opengrok.jar'),
                      logger=logger,
                      doprint=True)
    indexer.execute()
    ret = indexer.getretcode()
    if ret != SUCCESS_EXITVAL:
        logger.error('Command returned {}'.format(ret))
        logger.error(indexer.geterroutput())
        raise Exception("Failed to create bare configuration")