示例#1
0
def tryout_wildbook_login():
    r"""
    Helper function to test wildbook login automagically

    Returns:
        tuple: (wb_target, tomcat_dpath)

    CommandLine:
        python -m ibeis tryout_wildbook_login

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> tryout_wildbook_login()
    """
    # Use selenimum to login to wildbook
    import ibeis
    manaul_login = False
    wb_target = ibeis.const.WILDBOOK_TARGET
    wb_url = 'http://localhost:8080/' + wb_target
    if manaul_login:
        ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    else:
        print('Grabbing Driver')
        driver = ut.grab_selenium_driver(PREFERED_BROWSER)
        print('Going to URL')
        if False:
            driver.get(wb_url)
            print('Finding Login Button')
            #login_button = driver.find_element_by_partial_link_text('Log in')
            login_button = driver.find_element_by_partial_link_text(
                'welcome.jps')
            login_button.click()
        else:
            driver.get(wb_url + '/login.jsp')
        print('Finding Login Elements')
        username_field = driver.find_element_by_name('username')
        password_field = driver.find_element_by_name('password')
        submit_login_button = driver.find_element_by_name('submit')
        rememberMe_button = driver.find_element_by_name('rememberMe')
        print('Executing Login Elements')
        username_field.send_keys('tomcat')
        password_field.send_keys('tomcat123')
        rememberMe_button.click()
        submit_login_button.click()
        # Accept agreement
        import selenium.common.exceptions
        try:
            accept_aggrement_button = driver.find_element_by_name(
                'acceptUserAgreement')
            accept_aggrement_button.click()
        except selenium.common.exceptions.NoSuchElementException:
            pass

        # Goto individuals page
        individuals = driver.find_element_by_partial_link_text('Individuals')
        individuals.click()
        view_all = driver.find_element_by_partial_link_text('View All')
        view_all.click()
示例#2
0
def test_wildbook_login():
    r"""
    Helper function to test wildbook login automagically

    Returns:
        tuple: (wb_target, tomcat_dpath)

    CommandLine:
        python -m ibeis test_wildbook_login

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.wildbook_manager import *  # NOQA
        >>> test_wildbook_login()
    """
    # Use selenimum to login to wildbook
    import ibeis
    manaul_login = False
    wb_target = ibeis.const.WILDBOOK_TARGET
    wb_url = 'http://localhost:8080/' + wb_target
    if manaul_login:
        ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(wb_url)
    else:
        print('Grabbing Driver')
        driver = ut.grab_selenium_driver(PREFERED_BROWSER)
        print('Going to URL')
        if False:
            driver.get(wb_url)
            print('Finding Login Button')
            #login_button = driver.find_element_by_partial_link_text('Log in')
            login_button = driver.find_element_by_partial_link_text('welcome.jps')
            login_button.click()
        else:
            driver.get(wb_url + '/login.jsp')
        print('Finding Login Elements')
        username_field = driver.find_element_by_name('username')
        password_field = driver.find_element_by_name('password')
        submit_login_button = driver.find_element_by_name('submit')
        rememberMe_button = driver.find_element_by_name('rememberMe')
        print('Executing Login Elements')
        username_field.send_keys('tomcat')
        password_field.send_keys('tomcat123')
        rememberMe_button.click()
        submit_login_button.click()
        # Accept agreement
        import selenium.common.exceptions
        try:
            accept_aggrement_button = driver.find_element_by_name('acceptUserAgreement')
            accept_aggrement_button.click()
        except selenium.common.exceptions.NoSuchElementException:
            pass

        # Goto individuals page
        individuals = driver.find_element_by_partial_link_text('Individuals')
        individuals.click()
        view_all = driver.find_element_by_partial_link_text('View All')
        view_all.click()
示例#3
0
 def _complete(eid):
     encounter_uuid = ibs.get_encounter_uuid(eid)
     complete_url_ = complete_url_fmtstr.format(
         encounter_uuid=encounter_uuid)
     print('[_complete] URL=%r' % (complete_url_, ))
     if open_url_on_complete and not dryrun:
         _browser = ut.get_prefered_browser(PREFERED_BROWSER)
         _browser.open_new_tab(complete_url_)
示例#4
0
def submit_wildbook_url(url, payload=None, browse_on_error=True, dryrun=False,
                        timeout=2):
    """
    mirroring the one in IBEISController.py, but with changed functionality
    """
    if dryrun:
        print('[DRYrun_submit] URL=%r' % (url, ))
        response = None
        status = True
    else:
        if ut.VERBOSE:
            print('[submit] URL=%r' % (url, ))
        try:
            if payload is None:
                response = requests.get(url, timeout=timeout)
                #response = requests.get(url, auth=('tomcat', 'tomcat123'))
            else:
                response = requests.post(url, data=payload, timeout=timeout)
                #r = requests.post(url, data=None, auth=('tomcat', 'tomcat123'))
        except requests.ConnectionError as ex:
            ut.printex(ex, 'Could not connect to Wildbook server url=%r' % url)
            raise
        else:
            status = True
        if response is None or response.status_code != 200:
            errmsg_list = ([('Wildbook response NOT ok (200)')])
            if response is None:
                errmsg_list.extend([
                    ('WILDBOOK SERVER RESPONSE = %r' % (response, )),
                ])
            else:
                errmsg_list.extend([
                    ('WILDBOOK SERVER STATUS = %r' % (response.status_code,)),
                    ('WILDBOOK SERVER RESPONSE TEXT = %r' % (response.text,)),
                ])
            errmsg = '\n'.join(errmsg_list)
            print(errmsg)
            if browse_on_error:
                ut.get_prefered_browser(PREFERED_BROWSER).open_new_tab(url)
            raise AssertionError(errmsg)
            status = False
    return status, response
示例#5
0
def wildbook_signal_imgsetid_list(ibs,
                                  imgsetid_list=None,
                                  set_shipped_flag=True,
                                  open_url_on_complete=True,
                                  wb_target=None,
                                  dryrun=False):
    """
    Exports specified imagesets to wildbook. This is a synchronous call.

    Args:
        imgsetid_list (list): (default = None)
        set_shipped_flag (bool): (default = True)
        open_url_on_complete (bool): (default = True)

    RESTful:
        Method: PUT
        URL:    /api/wildbook/signal_imgsetid_list/

    Ignore:
        cd $CODE_DIR/Wildbook/tmp

        # Ensure IA server is up
        python -m ibeis --web --db PZ_MTEST

        # Reset IBEIS database
        python -m ibeis.tests.reset_testdbs --reset_mtest
        python -m ibeis  reset_mtest

        # Completely remove Wildbook database
        python -m ibeis  purge_local_wildbook

        # Install Wildbook
        python -m ibeis  install_wildbook

        # Startup Wildbook
        python -m ibeis  startup_wildbook_server

        # Login to wildbook
        python -m ibeis  test_wildbook_login

        # Ship ImageSets to wildbook
        python -m ibeis  wildbook_signal_imgsetid_list

        # Change annotations names to a single name
        python -m ibeis  wildbook_signal_annot_name_changes:1

        # Change annotations names back to normal
        python -m ibeis  wildbook_signal_annot_name_changes:2

    CommandLine:
        python -m ibeis wildbook_signal_imgsetid_list
        python -m ibeis wildbook_signal_imgsetid_list --dryrun
        python -m ibeis wildbook_signal_imgsetid_list --break

    SeeAlso:
        ~/local/build_scripts/init_wildbook.sh

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.manual_wildbook_funcs import *  # NOQA
        >>> dryrun = ut.get_argflag('--dryrun')
        >>> wb_target = None
        >>> import ibeis
        >>> # Need to start a web server for wildbook to hook into
        >>> defaultdb = 'PZ_MTEST'
        >>> ibs = ibeis.opendb(defaultdb=defaultdb)
        >>> #gid_list = ibs.get_valid_gids()[0:10]
        >>> gid_list = ibs.get_valid_gids()[3:6]
        >>> new_imgsetid = ibs.create_new_imageset_from_images(gid_list)  # NOQA
        >>> imgsetid = new_imgsetid
        >>> print('new imageset uuid = %r' % (ibs.get_imageset_uuid(new_imgsetid),))
        >>> print('new imageset text = %r' % (ibs.get_imageset_text(new_imgsetid),))
        >>> imgsetid_list = [new_imgsetid]
        >>> ibs.set_imageset_processed_flags([new_imgsetid], [1])
        >>> gid_list = ibs.get_imageset_gids(new_imgsetid)
        >>> ibs.set_image_reviewed(gid_list, [1] * len(gid_list))
        >>> set_shipped_flag = True
        >>> open_url_on_complete = True
        >>> if ut.get_argflag('--bg'):
        >>>     web_ibs = ibeis.opendb_bg_web(defaultdb)
        >>> result = ibs.wildbook_signal_imgsetid_list(imgsetid_list, set_shipped_flag, open_url_on_complete, wb_target, dryrun)
        >>> # cleanup
        >>> #ibs.delete_imagesets(new_imgsetid)
        >>> print(result)
        >>> if ut.get_argflag('--bg'):
        >>>     web_ibs.terminate2()

    """
    wb_url = ibs.get_wildbook_base_url(wb_target)
    try:
        ibs.assert_ia_available_for_wb(wb_target)
    except Exception:
        pass

    if imgsetid_list is None:
        imgsetid_list = ibs.get_valid_imgsetids()

    # Check to make sure imagesets are ok:
    for imgsetid in imgsetid_list:
        # First, check if imageset can be pushed
        aid_list = ibs.get_imageset_aids(imgsetid)
        assert len(aid_list) > 0, (
            'ImageSet imgsetid=%r cannot be shipped with0 annots' %
            (imgsetid, ))
        unknown_flags = ibs.is_aid_unknown(aid_list)
        unnamed_aid_list = ut.compress(aid_list, unknown_flags)
        assert len(unnamed_aid_list) == 0, (
            ('ImageSet imgsetid=%r cannot be shipped becuase '
             'annotation(s) %r have not been named') % (
                 imgsetid,
                 unnamed_aid_list,
             ))

    ## Call Wildbook url to signal update
    print(
        '[ibs.wildbook_signal_imgsetid_list] ship imgsetid_list = %r to wildbook'
        % (imgsetid_list, ))

    url = wb_url + '/ia'
    occur_url_fmt = (wb_url + '/occurrence.jsp?number={uuid}')
    #enc_url_fmt = (wb_url + '/encounters/encounter.jsp?number={uuid}')

    # Check and push 'done' imagesets
    status_list = []
    for imgsetid in imgsetid_list:
        imageset_uuid = ibs.get_imageset_uuid(imgsetid)
        print('[_send] URL=%r' % (url, ))
        json_payload = {'resolver': {'fromIAImageSet': str(imageset_uuid)}}
        if dryrun:
            status = False
        else:
            response = requests.post(url, json=json_payload)
            status = response.status_code == 200
            print('response = %r' % (response, ))
            if set_shipped_flag:
                ibs.set_imageset_shipped_flags([imgsetid], [status])
                if status and open_url_on_complete:
                    view_occur_url = occur_url_fmt.format(uuid=imageset_uuid, )
                    _browser = ut.get_prefered_browser(PREFERED_BROWSER)
                    _browser.open_new_tab(view_occur_url)
        status_list.append(status)
    return status_list
示例#6
0
def wildbook_signal_imgsetid_list(ibs, imgsetid_list=None,
                                  set_shipped_flag=True,
                                  open_url_on_complete=True,
                                  wb_target=None, dryrun=False):
    """
    Exports specified imagesets to wildbook. This is a synchronous call.

    Args:
        imgsetid_list (list): (default = None)
        set_shipped_flag (bool): (default = True)
        open_url_on_complete (bool): (default = True)

    RESTful:
        Method: PUT
        URL:    /api/wildbook/signal_imgsetid_list/

    Ignore:
        cd $CODE_DIR/Wildbook/tmp

        # Ensure IA server is up
        python -m ibeis --web --db PZ_MTEST

        # Reset IBEIS database
        python -m ibeis.tests.reset_testdbs --reset_mtest
        python -m ibeis  reset_mtest

        # Completely remove Wildbook database
        python -m ibeis  purge_local_wildbook

        # Install Wildbook
        python -m ibeis  install_wildbook

        # Startup Wildbook
        python -m ibeis  startup_wildbook_server

        # Login to wildbook
        python -m ibeis  test_wildbook_login

        # Ship ImageSets to wildbook
        python -m ibeis  wildbook_signal_imgsetid_list

        # Change annotations names to a single name
        python -m ibeis  wildbook_signal_annot_name_changes:1

        # Change annotations names back to normal
        python -m ibeis  wildbook_signal_annot_name_changes:2

    CommandLine:
        python -m ibeis wildbook_signal_imgsetid_list
        python -m ibeis wildbook_signal_imgsetid_list --dryrun
        python -m ibeis wildbook_signal_imgsetid_list --break

    SeeAlso:
        ~/local/build_scripts/init_wildbook.sh

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.control.manual_wildbook_funcs import *  # NOQA
        >>> dryrun = ut.get_argflag('--dryrun')
        >>> wb_target = None
        >>> import ibeis
        >>> # Need to start a web server for wildbook to hook into
        >>> defaultdb = 'PZ_MTEST'
        >>> ibs = ibeis.opendb(defaultdb=defaultdb)
        >>> #gid_list = ibs.get_valid_gids()[0:10]
        >>> gid_list = ibs.get_valid_gids()[3:6]
        >>> new_imgsetid = ibs.create_new_imageset_from_images(gid_list)  # NOQA
        >>> imgsetid = new_imgsetid
        >>> print('new imageset uuid = %r' % (ibs.get_imageset_uuid(new_imgsetid),))
        >>> print('new imageset text = %r' % (ibs.get_imageset_text(new_imgsetid),))
        >>> imgsetid_list = [new_imgsetid]
        >>> ibs.set_imageset_processed_flags([new_imgsetid], [1])
        >>> gid_list = ibs.get_imageset_gids(new_imgsetid)
        >>> ibs.set_image_reviewed(gid_list, [1] * len(gid_list))
        >>> set_shipped_flag = True
        >>> open_url_on_complete = True
        >>> if ut.get_argflag('--bg'):
        >>>     web_ibs = ibeis.opendb_bg_web(defaultdb)
        >>> result = ibs.wildbook_signal_imgsetid_list(imgsetid_list, set_shipped_flag, open_url_on_complete, wb_target, dryrun)
        >>> # cleanup
        >>> #ibs.delete_imagesets(new_imgsetid)
        >>> print(result)
        >>> if ut.get_argflag('--bg'):
        >>>     web_ibs.terminate2()

    """
    wb_url = ibs.get_wildbook_base_url(wb_target)
    try:
        ibs.assert_ia_available_for_wb(wb_target)
    except Exception:
        pass

    if imgsetid_list is None:
        imgsetid_list = ibs.get_valid_imgsetids()

    # Check to make sure imagesets are ok:
    for imgsetid in imgsetid_list:
        # First, check if imageset can be pushed
        aid_list = ibs.get_imageset_aids(imgsetid)
        assert len(aid_list) > 0, (
            'ImageSet imgsetid=%r cannot be shipped with0 annots' % (imgsetid,))
        unknown_flags = ibs.is_aid_unknown(aid_list)
        unnamed_aid_list = ut.compress(aid_list, unknown_flags)
        assert len(unnamed_aid_list) == 0, (
            ('ImageSet imgsetid=%r cannot be shipped becuase '
             'annotation(s) %r have not been named') % (imgsetid, unnamed_aid_list, ))

    ## Call Wildbook url to signal update
    print('[ibs.wildbook_signal_imgsetid_list] ship imgsetid_list = %r to wildbook' % (
        imgsetid_list, ))

    url = wb_url + '/ia'
    occur_url_fmt = (wb_url + '/occurrence.jsp?number={uuid}')
    #enc_url_fmt = (wb_url + '/encounters/encounter.jsp?number={uuid}')

    # Check and push 'done' imagesets
    status_list = []
    for imgsetid in imgsetid_list:
        imageset_uuid = ibs.get_imageset_uuid(imgsetid)
        print('[_send] URL=%r' % (url, ))
        json_payload = {'resolver': {'fromIAImageSet': str(imageset_uuid) }}
        if dryrun:
            status = False
        else:
            response = requests.post(url, json=json_payload)
            status = response.status_code == 200
            print('response = %r' % (response,))
            if set_shipped_flag:
                ibs.set_imageset_shipped_flags([imgsetid], [status])
                if status and open_url_on_complete:
                    view_occur_url = occur_url_fmt.format(uuid=imageset_uuid,)
                    _browser = ut.get_prefered_browser(PREFERED_BROWSER)
                    _browser.open_new_tab(view_occur_url)
        status_list.append(status)
    return status_list