def processDeviceModificationForList(frame, chunk, tagsFromGrid, aliasDic,
                                     maxGaugeAction):
    changeSucceeded = 0
    succeeded = 0
    numNewName = 0
    for device in chunk:
        t = wxThread.GUIThread(
            frame,
            changeTagsForDevice,
            args=(device, tagsFromGrid, frame, maxGaugeAction),
            name="changeTagsForDevice",
        )
        t.start()
        t2 = wxThread.GUIThread(
            frame,
            changeAliasForDevice,
            args=(device, aliasDic, frame, maxGaugeAction),
            name="changeAliasForDevice",
        )
        t2.start()
        joinThreadList([t, t2])
        if t.result:
            changeSucceeded += t.result
        if t2.result:
            numNewName += t2.result[0]
            succeeded += t2.result[1]

    return (changeSucceeded, succeeded, numNewName, tagsFromGrid)
def createCommand(frame, command_args, commandType, schedule, schType):
    """ Attempt to apply a Command given user specifications """
    result, isGroup = confirmCommand(command_args, commandType, schedule,
                                     schType)

    if schType.lower() == "immediate":
        schType = esperclient.V0CommandScheduleEnum.IMMEDIATE
    elif schType.lower() == "window":
        schType = esperclient.V0CommandScheduleEnum.WINDOW
    elif schType.lower() == "recurring":
        schType = esperclient.V0CommandScheduleEnum.RECURRING
    t = None
    if result and isGroup:
        t = wxThread.GUIThread(
            frame,
            apiCalls.executeCommandOnGroup,
            args=(frame, command_args, schedule, schType, commandType),
            eventType=wxThread.myEVT_COMMAND,
            name="executeCommandOnGroup",
        )
    elif result and not isGroup:
        t = wxThread.GUIThread(
            frame,
            apiCalls.executeCommandOnDevice,
            args=(frame, command_args, schedule, schType, commandType),
            eventType=wxThread.myEVT_COMMAND,
            name="executeCommandOnDevice",
        )
    if t:
        frame.menubar.disableConfigMenu()
        frame.gauge.Pulse()
        t.start()
def iterateThroughDeviceList(frame,
                             action,
                             api_response,
                             entId,
                             isDevice=False,
                             isUpdate=False):
    """Iterates Through Each Device And Performs A Specified Action"""
    if len(api_response.results):
        number_of_devices = 0
        if not isDevice and not isUpdate:
            splitResults = splitListIntoChunks(api_response.results)

            threads = []
            for chunk in splitResults:
                t = wxThread.GUIThread(
                    frame,
                    processDevices,
                    args=(
                        chunk,
                        number_of_devices,
                        action,
                    ),
                    name="processDevices",
                )
                threads.append(t)
                t.start()
                number_of_devices += len(chunk)

            t = wxThread.GUIThread(
                frame,
                waitTillThreadsFinish,
                args=(
                    tuple(threads),
                    action,
                    entId,
                    1,
                    None,
                    len(api_response.results) * 2,
                ),
                name="waitTillThreadsFinish_1",
                eventType=wxThread.myEVT_FETCH,
            )
            t.start()
        else:
            deviceList = processDevices(api_response.results,
                                        number_of_devices,
                                        action,
                                        isUpdate=isUpdate)[1]
            return deviceList
    else:
        if hasattr(threading.current_thread(), "isStopped"):
            if threading.current_thread().isStopped():
                return
        frame.Logging("---> No devices found for group")
        displayMessageBox(("No devices found for group.", wx.ICON_INFORMATION))
def setAppStateForAllAppsListed(state, maxAttempt=Globals.MAX_RETRY):
    api_instance = esperclient.DeviceApi(
        esperclient.ApiClient(Globals.configuration))
    api_response = None
    for attempt in range(maxAttempt):
        try:
            api_response = api_instance.get_all_devices(
                Globals.enterprise_id,
                limit=Globals.limit,
                offset=Globals.offset,
            )
            break
        except Exception as e:
            if attempt == maxAttempt - 1:
                postEventToFrame(
                    wxThread.myEVT_LOG,
                    "---> ERROR: Failed to get devices ids to modify tags and aliases",
                )
                print(e)
                ApiToolLog().LogError(e)
                return
            time.sleep(Globals.RETRY_SLEEP)

    deviceIdentifers = Globals.frame.gridPanel.getDeviceIdentifersFromGrid()
    if api_response:
        tempRes = []
        for device in api_response.results:
            for deviceIds in deviceIdentifers:
                if (device.device_name in deviceIds
                        or device.hardware_info["serialNumber"] in deviceIds):
                    tempRes.append(device)
        if tempRes:
            api_response.results = tempRes
        threads = []
        for device in api_response.results:
            if (device.device_name in deviceIdentifers or
                    device.hardware_info["serialNumber"] in deviceIdentifers):
                t = wxThread.GUIThread(
                    Globals.frame,
                    setAllAppsState,
                    args=(Globals.frame, device, state),
                    name="setAllAppsState",
                )
                threads.append(t)
                t.start()
                limitActiveThreads(threads)
        t = wxThread.GUIThread(
            Globals.frame,
            waitTillThreadsFinish,
            args=(tuple(threads), state, -1, 4),
            name="waitTillThreadsFinish%s" % state,
        )
        t.start()
Example #5
0
 def updateTagCell(self, name, tags=None):
     """ Update the Tag Column in the Device Grid """
     wxThread.GUIThread(
         self.parentFrame,
         self.processUpdateTagCell,
         (name, tags),
         name="UpdateTagCell",
     )
 def onUpdateCheck(self, event):
     if not self.isCheckingForUpdates:
         update = wxThread.GUIThread(self,
                                     self.updateCheck,
                                     None,
                                     name="UpdateCheck")
         update.start()
         self.isCheckingForUpdates = True
def modifyDevice(frame):
    """ Start a thread that will attempt to modify device data """
    t = wxThread.GUIThread(
        frame,
        executeDeviceModification,
        args=(frame),
        eventType=None,
        name="executeDeviceModification",
    )
    t.start()
    return t
 def onChoice2Select(self, event):
     myCursor = wx.Cursor(wx.CURSOR_WAIT)
     self.SetCursor(myCursor)
     self.destTemplate = []
     self.choice2thread = wxThread.GUIThread(
         self,
         self.fetchDestTempaltes,
         (event.String if event.String else False),
         name="fetchDestTempaltes",
     )
     self.choice2thread.start()
 def onChoice1Select(self, event):
     myCursor = wx.Cursor(wx.CURSOR_WAIT)
     self.SetCursor(myCursor)
     self.sourceTemplate = []
     self.check_list_box_1.Clear()
     self.choice1thread = wxThread.GUIThread(
         self,
         self.populateSourceTempaltes,
         (event.String if event.String else False),
         name="populateSourceTempaltes",
     )
     self.choice1thread.start()
def processCollectionDevices(collectionList):
    if collectionList["results"]:
        splitResults = splitListIntoChunks(collectionList["results"])
        if splitResults:
            threads = []
            number_of_devices = 0
            for chunk in splitResults:
                t = wxThread.GUIThread(
                    Globals.frame,
                    fillInDeviceInfoDict,
                    args=(chunk, number_of_devices,
                          len(collectionList["results"] * 2)),
                    name="fillInDeviceInfoDict",
                )
                threads.append(t)
                t.start()
                number_of_devices += len(chunk)

            t = wxThread.GUIThread(
                Globals.frame,
                waitTillThreadsFinish,
                args=(
                    tuple(threads),
                    GeneralActions.SHOW_ALL_AND_GENERATE_REPORT.value,
                    Globals.enterprise_id,
                    3,
                ),
                eventType=wxThread.myEVT_FETCH,
                name="waitTillThreadsFinish3",
            )
            t.start()
    else:
        if Globals.frame:
            Globals.frame.Logging("---> No devices found for EQL query")
        postEventToFrame(
            wxThread.myEVT_MESSAGE_BOX,
            ("No devices found for EQL query.", wx.ICON_INFORMATION),
        )
        postEventToFrame(wxThread.myEVT_COMPLETE, (True))
Example #11
0
 def processMissingApplications(self, template, newTemplate, apps, config,
                                entId, missingAppThreads):
     for app in template["template"]["application"]["apps"]:
         if ("isGPlay" in app and app["isGPlay"]) or ("is_g_play" in app
                                                      and app["is_g_play"]):
             newTemplate["application"]["apps"].append(app)
         else:
             found = False
             for toApp in apps:
                 if (toApp.application_name == app["applicationName"]
                         or toApp.package_name == app["packageName"]):
                     found = True
             if not found:
                 upload = wxThread.GUIThread(
                     self.parent,
                     self.uploadMissingApk,
                     (app, template, newTemplate, config, entId),
                 )
                 missingAppThreads.append(upload)
                 upload.start()
def executeDeviceModification(frame, maxAttempt=Globals.MAX_RETRY):
    """ Attempt to modify device data according to what has been changed in the Grid """
    api_instance = esperclient.DeviceApi(
        esperclient.ApiClient(Globals.configuration))
    api_response = None
    for attempt in range(maxAttempt):
        try:
            api_response = api_instance.get_all_devices(
                Globals.enterprise_id,
                limit=Globals.limit,
                offset=Globals.offset,
            )
            break
        except Exception as e:
            if attempt == maxAttempt - 1:
                postEventToFrame(
                    wxThread.myEVT_LOG,
                    "---> ERROR: Failed to get devices ids to modify tags and aliases",
                )
                print(e)
                ApiToolLog().LogError(e)
                return
            time.sleep(Globals.RETRY_SLEEP)

    tagsFromGrid = frame.gridPanel.getDeviceTagsFromGrid()
    aliasDic = frame.gridPanel.getDeviceAliasFromList()
    frame.gauge.SetValue(1)

    maxGaugeAction = len(tagsFromGrid.keys()) + len(aliasDic.keys())
    if api_response:
        tempRes = list(
            filter(lambda x: x.device_name in tagsFromGrid.keys(),
                   api_response.results))
        if not tempRes:
            if "serialNumber" in api_response.results[0].hardware_info:
                tempRes = list(
                    filter(
                        lambda x: x.hardware_info["serialNumber"] in
                        tagsFromGrid.keys(),
                        api_response.results,
                    ))
        if tempRes:
            api_response.results = tempRes

        splitResults = splitListIntoChunks(api_response.results)

        threads = []
        for chunk in splitResults:
            t = wxThread.GUIThread(
                frame,
                processDeviceModificationForList,
                args=(frame, chunk, tagsFromGrid, aliasDic, maxGaugeAction),
                name="processDeviceModificationForList",
            )
            threads.append(t)
            t.start()

        t = wxThread.GUIThread(
            frame,
            waitTillThreadsFinish,
            args=(tuple(threads), -1, -1, 2),
            name="waitTillThreadsFinish",
        )
        t.start()