예제 #1
0
def get_version_info(pmaviewURL):
    """
    Get version info from PMA.view instance running at pmaviewURL
    """
    # purposefully DON'T use helper function _pma_api_url() here:
    # why? because GetVersionInfo can be invoked WITHOUT a valid SessionID;
    # _pma_api_url() takes session information into account
    url = pma._pma_join(pmaviewURL, "api/json/GetVersionInfo")
    version = ""
    try:
        # Are we looking at PMA.view/studio 2.x?
        if pma._pma_debug is True:
            print(url)
        contents = urlopen(url).read().decode("utf-8").strip("\"").strip("'")
        return contents
    except Exception as e:
        version = None

    url = pma._pma_join(pmaviewURL, "viewer/version")
    try:
        # Oops, perhaps this is a PMA.view 1.x version
        if pma._pma_debug is True:
            print(url)
        contents = urlopen(url).read().decode("utf-8").strip("\"").strip("'")
        return contents
    except Exception as e:
        version = None

    return version
예제 #2
0
def _pma_api_url(sessionID=None, xml=True):
    # let's get the base URL first for the specified session
    url = _pma_url(sessionID)
    if url is None:
        # sort of a hopeless situation; there is no URL to refer to
        return None
    # remember, _pma_url is guaranteed to return a URL that ends with "/"
    if (xml == True):
        return pma._pma_join(url, "api/xml/")
    else:
        return pma._pma_join(url, "api/json/")
예제 #3
0
파일: core.py 프로젝트: seoulite/pma_python
def get_version_info(pmacoreURL=_pma_pmacoreliteURL):
    """
    Get version info from PMA.core instance running at pmacoreURL.
    Return None if PMA.core not found running at pmacoreURL endpoint
    """
    # purposefully DON'T use helper function _pma_api_url() here:
    # why? because GetVersionInfo can be invoked WITHOUT a valid SessionID;
    # _pma_api_url() takes session information into account

    url = pma._pma_join(pmacoreURL, "api/json/GetVersionInfo")
    if pma._pma_debug == True:
        print(url)

    try:
        r = requests.get(url)
    except Exception:
        return None

    json = r.json()
    version = None
    if ("Code" in json):
        raise Exception("get version info resulted in: " + json["Message"])
    elif ("d" in json):
        version = json["d"]
    else:
        version = json

    return version
예제 #4
0
def register_participant_for_project(
        pmacontrolURL,
        participantUsername,
        pmacontrolProjectID,
        pmacontrolRole,
        pmacoreSessionID,
        pmacontrolInteractionMode=pma_interaction_mode_locked):
    """
	Registers a participant for all sessions in a given project, assigning a specific role
	"""
    url = pma._pma_join(pmacontrolURL, "api/Projects/") + str(
        pmacontrolProjectID) + "/AddParticipant?SessionID=" + pmacoreSessionID
    data = {
        "UserName": participantUsername,
        "Role": pmacontrolRole,
        "InteractionMode": pmacontrolInteractionMode
    }  # default interaction mode = Locked
    data = parse.urlencode(data).encode()
    if (pma._pma_debug == True):
        print("Posting to", url)
        print("   with payload", data)
    req = request.Request(url=url, data=data)  # this makes the method "POST"
    resp = request.urlopen(req)
    pma._pma_clear_url_cache()
    return resp
예제 #5
0
def register_participant_for_training_session(
        pmacontrolURL,
        participantUsername,
        pmacontrolTrainingSessionID,
        pmacontrolRole,
        pmacoreSessionID,
        pmacontrolInteractionMode=pma_interaction_mode_locked):
    """
	Registers a particpant for a given session, assign a specific role
	"""
    #if is_participant_in_training_session(pmacontrolURL, participantUsername, pmacontrolTrainingSessionID, pmacoreSessionID):
    #	raise NameError ("PMA.core user " + participantUsername + " is ALREADY registered in PMA.control training session " + str(pmacontrolTrainingSessionID))
    url = pma._pma_join(pmacontrolURL, "api/Sessions/") + str(
        pmacontrolTrainingSessionID
    ) + "/AddParticipant?SessionID=" + pmacoreSessionID
    data = {
        "UserName": participantUsername,
        "Role": pmacontrolRole,
        "InteractionMode": pmacontrolInteractionMode
    }  # default interaction mode = Locked
    data = parse.urlencode(data).encode()
    if (pma._pma_debug == True):
        print("Posting to", url)
        print("   with payload", data)
    req = request.Request(url=url, data=data)  # this makes the method "POST"
    resp = request.urlopen(req)
    pma._pma_clear_url_cache()
    return resp
예제 #6
0
파일: core.py 프로젝트: seoulite/pma_python
def _pma_query_url(sessionID=None):
    # let's get the base URL first for the specified session
    url = _pma_url(sessionID)
    if url is None:
        # sort of a hopeless situation; there is no URL to refer to
        return None
    # remember, _pma_url is guaranteed to return a URL that ends with "/"
    return pma._pma_join(url, "query/json/")
예제 #7
0
def connect(pmacoreURL=_pma_pmacoreliteURL,
            pmacoreUsername="",
            pmacorePassword=""):
    """
    Attempt to connect to PMA.core instance; success results in a SessionID
    """
    global _pma_sessions  # so afterwards we can look up what username actually belongs to a sessions
    global _pma_usernames  # so afterwards we can determine the PMA.core URL to connect to for a given SessionID
    global _pma_slideinfos  # a caching mechanism for slide information; obsolete and should be improved
    global _pma_amount_of_data_downloaded  # keep track of how much data was downloaded

    if (pmacoreURL == _pma_pmacoreliteURL):
        if is_lite():
            # no point authenticating localhost / PMA.core.lite
            sessionID = _pma_pmacoreliteSessionID
            _pma_sessions[sessionID] = pmacoreURL
            if not (sessionID in _pma_slideinfos):
                _pma_slideinfos[sessionID] = {}
            _pma_amount_of_data_downloaded[sessionID] = 0
            return sessionID
        else:
            return None

    # purposefully DON'T use helper function _pma_api_url() here:
    # why? Because_pma_api_url() takes session information into account (which we don't have yet)
    url = pma._pma_join(pmacoreURL, "api/json/authenticate?caller=SDK.Python")
    if (pmacoreUsername != ""):
        url += "&username="******""):
        url += "&password="******"Success"]).lower() != "true"):
        sessionID = None
    else:
        sessionID = loginresult["SessionId"]

        _pma_usernames[sessionID] = pmacoreUsername
        _pma_sessions[sessionID] = pmacoreURL
        if not (sessionID in _pma_slideinfos):
            _pma_slideinfos[sessionID] = {}
        _pma_amount_of_data_downloaded[sessionID] = len(loginresult)

    return sessionID
예제 #8
0
def get_version_info(pmacontrolURL):
    """
	Get version info from PMA.control instance running at pmacontrolURL
	"""
    # why? because GetVersionInfo can be invoked WITHOUT a valid SessionID; _pma_api_url() takes session information into account
    url = pma._pma_join(pmacontrolURL, "api/version")
    try:
        headers = {'Accept': 'application/json'}
        r = pma._pma_http_get(url, headers)
    except Exception as e:
        print(e)
        return None
    return r.json()
예제 #9
0
def _pma_get_training_sessions(pmacontrolURL, pmacoreSessionID):
    """
	Retrieve a list of currently defined training sessions in PMA.control.
	"""
    url = pma._pma_join(
        pmacontrolURL,
        "api/Sessions?sessionID=" + pma._pma_q(pmacoreSessionID))
    try:
        headers = {'Accept': 'application/json'}
        r = pma._pma_http_get(url, headers)
    except Exception as e:
        print(e)
        return None
    return r.json()
예제 #10
0
def _pma_is_lite(pmacoreURL=_pma_pmacoreliteURL):
    """checks to see if PMA.core.lite (server component of PMA.start) is running at a given endpoint.
	if pmacoreURL is omitted, default check is to see if PMA.start is effectively running at localhost (defined by _pma_pmacoreliteURL).
		note that PMA.start may not be running, while it is actually installed. This method doesn't detect whether PMA.start is installed; merely whether it's running!
	if pmacoreURL is specified, then the method checks if there's an instance of PMA.start (results in True), PMA.core (results in False) 
	or nothing (at least not a Pathomation software platform component) at all (results in None)"""
    url = pma._pma_join(pmacoreURL, "api/json/IsLite")
    try:
        r = requests.get(url)
    except Exception as e:
        # this happens when NO instance of PMA.core is detected
        return None
    value = r.json()
    return value == True
예제 #11
0
def _pma_get_projects(pmacontrolURL, pmacoreSessionID):
    """
	Retrieve all projects and their data in PMA.control 
	(RAW JSON data; not suited for human consumption)
	"""
    global _pma_projects_json

    url = pma._pma_join(
        pmacontrolURL,
        "api/Projects?sessionID=" + pma._pma_q(pmacoreSessionID))
    try:
        headers = {'Accept': 'application/json'}
        r = pma._pma_http_get(url, headers)
        return r.json()
    except Exception as e:
        return None
예제 #12
0
def _pma_get_case_collections(pmacontrolURL, pmacoreSessionID):
    """
	Retrieve all the data for all the defined case collections in PMA.control
	(RAW JSON data; not suited for human consumption)
	"""
    global _pma_casecollections_json

    url = pma._pma_join(
        pmacontrolURL,
        "api/CaseCollections?sessionID=" + pma._pma_q(pmacoreSessionID))
    try:
        headers = {'Accept': 'application/json'}
        r = pma._pma_http_get(url, headers)
        return r.json()
    except Exception as e:
        return None
예제 #13
0
def set_participant_interactionmode(pmacontrolURL, participantUsername,
                                    pmacontrolTrainingSessionID,
                                    pmacontrolCaseCollectionID,
                                    pmacontrolInteractionMode,
                                    pmacoreSessionID):
    """
	Assign an interaction mode to a particpant for a given Case Collection within a trainingsession
	"""
    if not is_participant_in_training_session(
            pmacontrolURL, participantUsername, pmacontrolTrainingSessionID,
            pmacoreSessionID):
        raise NameError("PMA.core user " + participantUsername +
                        " is NOT registered in PMA.control training session " +
                        str(pmacontrolTrainingSessionID))
    url = pma._pma_join(pmacontrolURL, "api/Sessions/") + str(
        pmacontrolTrainingSessionID
    ) + "/InteractionMode?SessionID=" + pmacoreSessionID
    data = {
        "UserName": participantUsername,
        "CaseCollectionId": pmacontrolCaseCollectionID,
        "InteractionMode": pmacontrolInteractionMode
    }
    #pmacontrolTrainingSessionCaseCollectionID = _pma_get_case_collection_training_session_id(pmacontrolURL, pmacontrolTrainingSessionID, pmacontrolCaseCollectionID, pmacoreSessionID)
    #data = { "UserName": participantUsername, "CaseCollectionId": pmacontrolTrainingSessionCaseCollectionID, "InteractionMode": pmacontrolInteractionMode }
    data = parse.urlencode(data).encode()
    if (pma._pma_debug == True):
        print("Posting to", url)
        print("   with payload", data)
    req = request.Request(url=url, data=data)  # this makes the method "POST"
    try:
        resp = request.urlopen(req)
    except urllib.error.HTTPError as e:
        if (pma._pma_debug == True):
            print("HTTP ERROR")
            print(e.__dict__)
        return None
    except urllib.error.URLError as e:
        if (pma._pma_debug == True):
            print("URL ERROR")
            print(e.__dict__)
        return None
    pma._pma_clear_url_cache()
    return resp
예제 #14
0
def get_training_session_participants(pmacontrolURL,
                                      pmacontrolTrainingSessionID,
                                      pmacoreSessionID):
    """
	Extract the participants in a particular session
	"""
    url = pma._pma_join(
        pmacontrolURL, "api/Sessions/" + str(pmacontrolTrainingSessionID) +
        "/Participants?sessionID=" + pma._pma_q(pmacoreSessionID))
    try:
        headers = {'Accept': 'application/json'}
        r = pma._pma_http_get(url, headers)
    except Exception as e:
        print(e)
        return None
    parts = {}
    for part in r.json():
        parts[part['User']] = part
    return parts
예제 #15
0
def admin_connect(pmacoreURL, pmacoreAdmUsername, pmacoreAdmPassword):
    """
	Attempt to connect to PMA.core instance; success results in a SessionID
	only success if the user has administrative status
	"""
    _pma_check_for_pma_start("admin_connect", pmacoreURL)

    # purposefully DON'T use helper function _pma_api_url() here:
    # why? Because_pma_api_url() takes session information into account (which we don't have yet)
    url = pma._pma_join(pmacoreURL,
                        "admin/json/AdminAuthenticate?caller=SDK.Python")
    url += "&username="******"&password="******"Success"]).lower() != "true"):
        admSessionID = None
    else:
        admSessionID = loginresult["SessionId"]

        core._pma_sessions[admSessionID] = pmacoreURL
        core._pma_usernames[admSessionID] = pmacoreAdmUsername

        if not (admSessionID in core._pma_slideinfos):
            core._pma_slideinfos[admSessionID] = dict()
        core._pma_amount_of_data_downloaded[admSessionID] = len(loginresult)

    return (admSessionID)
예제 #16
0
파일: core.py 프로젝트: seoulite/pma_python
def get_api_version(pmacoreURL=_pma_pmacoreliteURL):
    url = pma._pma_join(pmacoreURL, "api/json/GetAPIVersion")
    if pma._pma_debug == True:
        print(url)

    try:
        r = requests.get(url)
    except Exception:
        return None

    try:
        json = r.json()
    except Exception:
        raise Exception("GetAPIVersion method not available at " + pmacoreURL)

    version = None
    if ("Code" in json):
        raise Exception("get_api_version resulted in: " + json["Message"])
    elif ("d" in json):
        version = json["d"]
    else:
        version = json

    return version