Exemplo n.º 1
0
def shutdown_wildbook_server(verbose=ut.NOT_QUIET):
    r"""

    Args:
        verbose (bool):  verbosity flag(default = True)

    Ignore:
        tail -f ~/.config/ibeis/tomcat/logs/catalina.out

    CommandLine:
        python -m ibeis shutdown_wildbook_server

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> wb_url = shutdown_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    tomcat_dpath = find_installed_tomcat(check_unpacked=False, strict=False)
    # TODO: allow custom specified tomcat directory
    #tomcat_dpath = find_installed_tomcat(check_unpacked=False)
    #catalina_out_fpath = join(tomcat_dpath, 'logs', 'catalina.out')
    if tomcat_dpath is not None:
        with ut.ChdirContext(get_tomcat_startup_tmpdir()):
            shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
            #ut.cmd(shutdown_fpath)
            ut.cmd(ut.quote_single_command(shutdown_fpath))
            time.sleep(.5)
Exemplo n.º 2
0
def startup_wildbook_server(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis.control.manual_wildbook_funcs --test-startup_wildbook_server
        python -m ibeis --tf startup_wildbook_server  --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.manual_wildbook_funcs import *  # NOQA
        >>> verbose = True
        >>> wb_url = startup_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    from os.path import join
    import time
    import ibeis
    tomcat_dpath = find_installed_tomcat()

    # Ensure environment variables
    #os.environ['JAVA_HOME'] = find_java_jvm()
    #os.environ['TOMCAT_HOME'] = tomcat_dpath
    #os.environ['CATALINA_HOME'] = tomcat_dpath

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        startup_fpath  = join(tomcat_dpath, 'bin', 'startup.sh')
        ut.cmd(ut.quote_single_command(startup_fpath))
        time.sleep(1)
    wb_url = 'http://localhost:8080/' + ibeis.const.WILDBOOK_TARGET
    return wb_url
Exemplo n.º 3
0
def startup_wildbook_server(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis startup_wildbook_server
        python -m ibeis startup_wildbook_server  --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> wb_url = startup_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    import ibeis
    tomcat_dpath = find_installed_tomcat()

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        startup_fpath = join(tomcat_dpath, 'bin', 'startup.sh')
        ut.cmd(ut.quote_single_command(startup_fpath))
        time.sleep(1)
    wb_url = 'http://localhost:8080/' + ibeis.const.WILDBOOK_TARGET
    # TODO go to http://localhost:8080/ibeis/createAssetStore.jsp
    return wb_url
Exemplo n.º 4
0
def shutdown_wildbook_server(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis.control.manual_wildbook_funcs --exec-shutdown_wildbook_server --exec-mode
        python -m ibeis --tf shutdown_wildbook_server

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.manual_wildbook_funcs import *  # NOQA
        >>> verbose = True
        >>> wb_url = shutdown_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    from os.path import join
    import time
    tomcat_dpath = find_installed_tomcat(check_unpacked=False)

    # Ensure environment variables
    #os.environ['JAVA_HOME'] = find_java_jvm()
    #os.environ['TOMCAT_HOME'] = tomcat_dpath
    #os.environ['CATALINA_HOME'] = tomcat_dpath

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
        #ut.cmd(shutdown_fpath)
        ut.cmd(ut.quote_single_command(shutdown_fpath))
        time.sleep(.5)
Exemplo n.º 5
0
def shutdown_wildbook_server(verbose=ut.NOT_QUIET):
    r"""

    Args:
        verbose (bool):  verbosity flag(default = True)

    Ignore:
        tail -f ~/.config/ibeis/tomcat/logs/catalina.out

    CommandLine:
        python -m ibeis shutdown_wildbook_server

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> wb_url = shutdown_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    tomcat_dpath = find_installed_tomcat(check_unpacked=False, strict=False)
    # TODO: allow custom specified tomcat directory
    #tomcat_dpath = find_installed_tomcat(check_unpacked=False)
    #catalina_out_fpath = join(tomcat_dpath, 'logs', 'catalina.out')
    if tomcat_dpath is not None:
        with ut.ChdirContext(get_tomcat_startup_tmpdir()):
            shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
            #ut.cmd(shutdown_fpath)
            ut.cmd(ut.quote_single_command(shutdown_fpath))
            time.sleep(.5)
Exemplo n.º 6
0
def startup_wildbook_server(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis startup_wildbook_server
        python -m ibeis startup_wildbook_server  --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> wb_url = startup_wildbook_server()
        >>> ut.quit_if_noshow()
        >>> ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    """
    # TODO: allow custom specified tomcat directory
    import ibeis
    tomcat_dpath = find_installed_tomcat()

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        startup_fpath  = join(tomcat_dpath, 'bin', 'startup.sh')
        ut.cmd(ut.quote_single_command(startup_fpath))
        time.sleep(1)
    wb_url = 'http://localhost:8080/' + ibeis.const.WILDBOOK_TARGET
    # TODO go to http://localhost:8080/ibeis/createAssetStore.jsp
    return wb_url
Exemplo n.º 7
0
def monitor_wildbook_logs(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis monitor_wildbook_logs  --show

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> monitor_wildbook_logs()
    """
    # TODO: allow custom specified tomcat directory
    import ibeis
    tomcat_dpath = find_installed_tomcat()

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        startup_fpath = join(tomcat_dpath, 'bin', 'startup.sh')
        ut.cmd(ut.quote_single_command(startup_fpath))
        time.sleep(1)
    wb_url = 'http://localhost:8080/' + ibeis.const.WILDBOOK_TARGET
    return wb_url
Exemplo n.º 8
0
def monitor_wildbook_logs(verbose=ut.NOT_QUIET):
    r"""
    Args:
        verbose (bool):  verbosity flag(default = True)

    CommandLine:
        python -m ibeis monitor_wildbook_logs  --show

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> monitor_wildbook_logs()
    """
    # TODO: allow custom specified tomcat directory
    import ibeis
    tomcat_dpath = find_installed_tomcat()

    with ut.ChdirContext(get_tomcat_startup_tmpdir()):
        startup_fpath  = join(tomcat_dpath, 'bin', 'startup.sh')
        ut.cmd(ut.quote_single_command(startup_fpath))
        time.sleep(1)
    wb_url = 'http://localhost:8080/' + ibeis.const.WILDBOOK_TARGET
    return wb_url
Exemplo n.º 9
0
def install_wildbook(verbose=ut.NOT_QUIET):
    """
    Script to setup wildbook on a unix based system
    (hopefully eventually this will generalize to win32)

    CommandLine:
        # Reset
        ibeis purge_local_wildbook
        ibeis ensure_wb_mysql
        ibeis ensure_local_war
        # Setup
        ibeis install_wildbook
        # ibeis install_wildbook --nomysql
        # Startup
        ibeis startup_wildbook_server --show

        Alternates:
            ibeis install_wildbook --redownload-war
            ibeis install_wildbook --assets
            ibeis startup_wildbook_server --show

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> result = install_wildbook()
        >>> print(result)
    """
    import requests
    # Ensure that the war file has been unpacked
    tomcat_dpath, webapps_dpath, wb_target = ensure_local_war()

    unpacked_war_dpath = join(webapps_dpath, wb_target)
    tomcat_startup_dir = get_tomcat_startup_tmpdir()
    fresh_install = not ut.checkpath(unpacked_war_dpath, verbose=verbose)
    if fresh_install:
        # Need to make sure you start catalina in the same directory otherwise
        # the derby databsae gets put in in cwd
        with ut.ChdirContext(tomcat_startup_dir):
            # Starting and stoping catalina should be sufficient to unpack the
            # war
            startup_fpath = join(tomcat_dpath, 'bin', 'startup.sh')
            #shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
            ut.cmd(ut.quote_single_command(startup_fpath))
            print('It is NOT ok if the startup.sh fails\n')

            # wait for the war to be unpacked
            for retry_count in range(0, 6):
                time.sleep(1)
                if ut.checkpath(unpacked_war_dpath, verbose=True):
                    break
                else:
                    print('Retrying')

            # ensure that the server is ruuning
            print('Checking if we can ping the server')
            response = requests.get('http://localhost:8080')
            if response is None or response.status_code != 200:
                print('There may be an error starting the server')
            else:
                print('Seem able to ping the server')

            # assert tht the war was unpacked
            ut.assertpath(unpacked_war_dpath, (
                'Wildbook war might have not unpacked correctly.  This may '
                'be ok. Try again. If it fails a second time, then there is a '
                'problem.'),
                          verbose=True)

            # Don't shutdown just yet. Need to create assets

    update_wildbook_install_config(webapps_dpath, unpacked_war_dpath)
    asset_flag_fpath = join(tomcat_startup_dir, 'made_assets.flag')

    # Pinging the server to create asset store
    # Ensureing that createAssetStore exists
    if not ut.checkpath(asset_flag_fpath):
        if not fresh_install:
            startup_wildbook_server()
        #web_url = startup_wildbook_server(verbose=False)
        print('Creating asset store')
        wb_url = 'http://localhost:8080/' + wb_target
        response = requests.get(wb_url + '/createAssetStore.jsp')
        if response is None or response.status_code != 200:
            print('There may be an error starting the server')
            #if response.status_code == 500:
            print(response.text)
            assert False, 'response error'
        else:
            print('Created asset store')
            # Create file signaling we did this
            ut.writeto(asset_flag_fpath, 'True')
        shutdown_wildbook_server(verbose=False)
        print('It is ok if the shutdown fails')
    elif fresh_install:
        shutdown_wildbook_server(verbose=False)

    #127.0.0.1:8080/wildbook_data_dir/test.txt
    print('Wildbook is installed and waiting to be started')
Exemplo n.º 10
0
def install_wildbook(verbose=ut.NOT_QUIET):
    """
    Script to setup wildbook on a unix based system
    (hopefully eventually this will generalize to win32)

    CommandLine:
        # Reset
        python -m ibeis --tf reset_local_wildbook
        # Setup
        python -m ibeis --tf install_wildbook
        # Startup
        python -m ibeis --tf startup_wildbook_server --show --exec-mode

        # Reset
        python -m ibeis.control.manual_wildbook_funcs --test-reset_local_wildbook
        # Setup
        python -m ibeis.control.manual_wildbook_funcs --test-install_wildbook
        # Startup
        python -m ibeis.control.manual_wildbook_funcs --test-startup_wildbook_server --show --exec-mode


    Example:
        >>> # SCRIPT
        >>> from ibeis.control.manual_wildbook_funcs import *  # NOQA
        >>> verbose = True
        >>> result = install_wildbook()
        >>> print(result)
    """
    # TODO: allow custom specified tomcat directory
    from os.path import basename, splitext, join
    import time
    import re
    import subprocess
    try:
        output = subprocess.check_output(['java', '-version'],
                                         stderr=subprocess.STDOUT)
        _java_version = output.split('\n')[0]
        _java_version = _java_version.replace('java version ', '')
        java_version = _java_version.replace('"', '')
        print('java_version = %r' % (java_version,))
        if not java_version.startswith('1.7'):
            print('Warning wildbook is only supported for java 1.7')
    except OSError:
        output = None
    if output is None:
        raise ImportError(
            'Cannot find java on this machine. '
            'Please install java: http://www.java.com/en/download/')

    tomcat_dpath = find_or_download_tomcat()
    assert tomcat_dpath is not None, 'Could not find tomcat'
    war_fpath = find_or_download_wilbook_warfile()
    war_fname = basename(war_fpath)
    wb_target = splitext(war_fname)[0]

    # Ensure environment variables
    #os.environ['JAVA_HOME'] = find_java_jvm()
    #os.environ['TOMCAT_HOME'] = tomcat_dpath
    #os.environ['CATALINA_HOME'] = tomcat_dpath

    # Move the war file to tomcat webapps if not there
    webapps_dpath = join(tomcat_dpath, 'webapps')
    deploy_war_fpath = join(webapps_dpath, war_fname)
    if not ut.checkpath(deploy_war_fpath, verbose=verbose):
        ut.copy(war_fpath, deploy_war_fpath)

    # Ensure that the war file has been unpacked

    unpacked_war_dpath = join(webapps_dpath, wb_target)
    if not ut.checkpath(unpacked_war_dpath, verbose=verbose):
        # Need to make sure you start catalina in the same directory otherwise
        # the derby databsae gets put in in cwd
        tomcat_startup_dir = get_tomcat_startup_tmpdir()
        with ut.ChdirContext(tomcat_startup_dir):
            # Starting and stoping catalina should be sufficient to unpack the
            # war
            startup_fpath  = join(tomcat_dpath, 'bin', 'startup.sh')
            shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
            ut.cmd(ut.quote_single_command(startup_fpath))
            print('It is NOT ok if the startup.sh fails\n')

            # wait for the war to be unpacked
            for retry_count in range(0, 6):
                time.sleep(1)
                if ut.checkpath(unpacked_war_dpath, verbose=True):
                    break
                else:
                    print('Retrying')

            # ensure that the server is ruuning
            import requests
            print('Checking if we can ping the server')
            response = requests.get('http://localhost:8080')
            if response is None or response.status_code != 200:
                print('There may be an error starting the server')
            else:
                print('Seem able to ping the server')

            # assert tht the war was unpacked
            ut.assertpath(unpacked_war_dpath, (
                'Wildbook war might have not unpacked correctly.  This may '
                'be ok. Try again. If it fails a second time, then there is a '
                'problem.'), verbose=True)

            # shutdown the server
            ut.cmd(ut.quote_single_command(shutdown_fpath))
            print('It is ok if the shutdown.sh fails')
            time.sleep(.5)

    # Make sure permissions are correctly set in wildbook
    # Comment out the line that requires authentication
    permission_fpath = join(unpacked_war_dpath, 'WEB-INF/web.xml')
    ut.assertpath(permission_fpath)
    permission_text = ut.readfrom(permission_fpath)
    lines_to_remove = [
        '/EncounterSetMarkedIndividual = authc, roles[admin]'
    ]
    new_permission_text = permission_text[:]
    for line in lines_to_remove:
        re.search(re.escape(line), permission_text)
        prefix = ut.named_field('prefix', '\\s*')
        suffix = ut.named_field('suffix', '\\s*\n')
        pattern = ('^' + prefix + re.escape(line) + suffix)
        match = re.search(pattern, permission_text,
                          flags=re.MULTILINE | re.DOTALL)
        if match is None:
            continue
        newline = '<!--%s -->' % (line,)
        repl = ut.bref_field('prefix') + newline + ut.bref_field('suffix')
        new_permission_text = re.sub(pattern, repl, permission_text,
                                     flags=re.MULTILINE | re.DOTALL)
        assert new_permission_text != permission_text, (
            'text should have changed')
    if new_permission_text != permission_text:
        print('Need to write new permission texts')
        ut.writeto(permission_fpath, new_permission_text)
    else:
        print('Permission file seems to be ok')

    print('Wildbook is installed and waiting to be started')
Exemplo n.º 11
0
def install_wildbook(verbose=ut.NOT_QUIET):
    """
    Script to setup wildbook on a unix based system
    (hopefully eventually this will generalize to win32)

    CommandLine:
        # Reset
        ibeis purge_local_wildbook
        ibeis ensure_wb_mysql
        ibeis ensure_local_war
        # Setup
        ibeis install_wildbook
        # ibeis install_wildbook --nomysql
        # Startup
        ibeis startup_wildbook_server --show

        Alternates:
            ibeis install_wildbook --redownload-war
            ibeis install_wildbook --assets
            ibeis startup_wildbook_server --show

    Example:
        >>> # SCRIPT
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> verbose = True
        >>> result = install_wildbook()
        >>> print(result)
    """
    import requests
    # Ensure that the war file has been unpacked
    tomcat_dpath, webapps_dpath, wb_target = ensure_local_war()

    unpacked_war_dpath = join(webapps_dpath, wb_target)
    tomcat_startup_dir = get_tomcat_startup_tmpdir()
    fresh_install = not ut.checkpath(unpacked_war_dpath, verbose=verbose)
    if fresh_install:
        # Need to make sure you start catalina in the same directory otherwise
        # the derby databsae gets put in in cwd
        with ut.ChdirContext(tomcat_startup_dir):
            # Starting and stoping catalina should be sufficient to unpack the
            # war
            startup_fpath  = join(tomcat_dpath, 'bin', 'startup.sh')
            #shutdown_fpath = join(tomcat_dpath, 'bin', 'shutdown.sh')
            ut.cmd(ut.quote_single_command(startup_fpath))
            print('It is NOT ok if the startup.sh fails\n')

            # wait for the war to be unpacked
            for retry_count in range(0, 6):
                time.sleep(1)
                if ut.checkpath(unpacked_war_dpath, verbose=True):
                    break
                else:
                    print('Retrying')

            # ensure that the server is ruuning
            print('Checking if we can ping the server')
            response = requests.get('http://localhost:8080')
            if response is None or response.status_code != 200:
                print('There may be an error starting the server')
            else:
                print('Seem able to ping the server')

            # assert tht the war was unpacked
            ut.assertpath(unpacked_war_dpath, (
                'Wildbook war might have not unpacked correctly.  This may '
                'be ok. Try again. If it fails a second time, then there is a '
                'problem.'), verbose=True)

            # Don't shutdown just yet. Need to create assets

    update_wildbook_install_config(webapps_dpath, unpacked_war_dpath)
    asset_flag_fpath = join(tomcat_startup_dir, 'made_assets.flag')

    # Pinging the server to create asset store
    # Ensureing that createAssetStore exists
    if not ut.checkpath(asset_flag_fpath):
        if not fresh_install:
            startup_wildbook_server()
        #web_url = startup_wildbook_server(verbose=False)
        print('Creating asset store')
        wb_url = 'http://localhost:8080/' + wb_target
        response = requests.get(wb_url + '/createAssetStore.jsp')
        if response is None or response.status_code != 200:
            print('There may be an error starting the server')
            #if response.status_code == 500:
            print(response.text)
            assert False, 'response error'
        else:
            print('Created asset store')
            # Create file signaling we did this
            ut.writeto(asset_flag_fpath, 'True')
        shutdown_wildbook_server(verbose=False)
        print('It is ok if the shutdown fails')
    elif fresh_install:
        shutdown_wildbook_server(verbose=False)

    #127.0.0.1:8080/wildbook_data_dir/test.txt
    print('Wildbook is installed and waiting to be started')