コード例 #1
0
    def horizontal_scroll_once(self, to_left=True):
        """
        Single scroll that will get performed on a perticular tab
        @args:
            to_left : True, if travel to left
        """
        ele = "//android.widget.HorizontalScrollView[1]/" + \
              "android.widget.LinearLayout[1]//android.widget.TextView[1]"
        try:
            obj_list = self.get_element_by_xpath(ele)
        except Exception as exc :
            info(str(exc))
            raise Exception("not able to get horizontal tabs data from GUI")

        obj_list = [obj_list[0], obj_list[-1]]

        left_pt = (int(obj_list[0].location['x']) + 5,
                    int(obj_list[0].location['y']) + \
                     (int(obj_list[0].size['height']) / 2))

        right_pt = ( int(obj_list[-1].location['x']),
                     left_pt[1])

        if to_left:
            self.scroll('H', frm_pt=left_pt, to_pt=right_pt)
        else:
            self.scroll('H', frm_pt=right_pt, to_pt=left_pt)
コード例 #2
0
    def take_screenshot_of_element(self, element_name, generic_param=(),
                                   file_name=""):
        """
        Take screen shot of the whole screen and crop out the element pic
        """
        if not file_name:
            file_name = datetime.datetime.now().strftime("SS-%Y_%m_%d_%H_%M_%S.png")
            file_name = os.path.join(SCREEN_SHOT_DIR, file_name)

        ele_obj = self.get_element(element_name, generic_param=generic_param)
        ele_height = int(ele_obj.size['height'])
        ele_width = int(ele_obj.size['width'])
        ele_x_val = int(ele_obj.location['x'])
        ele_y_val = int(ele_obj.location['y'])

        ele_x1_val = ele_x_val + ele_width
        ele_y1_val = ele_y_val + ele_height
        self.take_screenshot(file_name)
        orientation_map = { 'LANDSCAPE': ( ele_x_val, ele_x1_val,
                                           ele_y_val, ele_y1_val),
                            'PORTRAIT': ( ele_y_val, ele_y1_val,
                                          ele_x_val, ele_x1_val )
                          }
        current_orientation = self.get_current_orientation()
        OpenCvLibrary.crop_file(file_name,
            *orientation_map[str(current_orientation)])
        info("screen shot taken : %s" % file_name)
        return file_name
コード例 #3
0
async def on_ready():
    login_msg = '[Bot Start] - Logged in as {}#{}'.format(
        client.user.name, client.user.discriminator)

    if config.verbose_start:
        login_msg += utils.get_all_channels(client)
        login_msg += utils.get_all_role_ids(client)

        login_msg += 'Registered message handlers:\n'
        for m in message_handlers:
            login_msg += '  {}'.format(str(m))

        login_msg += 'Registered background tasks:\n'
        for b in background_tasks:
            login_msg += '  {}'.format(str(b))

    # Log what we currently have
    print(login_msg)
    logger.info(login_msg)

    # Init background tasks
    for b in background_tasks:
        client.loop.create_task(b(client))

    await client.change_presence(activity=discord.Game(name='Haven Alpha')
                                 )  # tee-hee
コード例 #4
0
ファイル: pystemon.py プロジェクト: theDevilsVoice/pystemon
 def run(self):
     while not self.kill_received:
         sleep_time = random.randint(self.update_min, self.update_max)
         try:
             # grabs site from queue
             logger.info(
                 'Downloading list of new pastes from {name}. '
                 'Will check again in {time} seconds'.format(
                     name=self.name, time=sleep_time))
             # get the list of last pasties, but reverse it
             # so we first have the old entries and then the new ones
             last_pasties = self.get_last_pasties()
             if last_pasties:
                 for pastie in reversed(last_pasties):
                     queues[self.name].put(pastie)  # add pastie to queue
                 logger.info("Found {amount} new pasties for site {site}. There are now {qsize} pasties to be downloaded.".format(amount=len(last_pasties),
                                                                                                       site=self.name,
                                                                                                       qsize=queues[self.name].qsize()))
         # catch unknown errors
         except Exception as e:
             msg = 'Thread for {name} crashed unexpectectly, '\
                   'recovering...: {e}'.format(name=self.name, e=e)
             logger.error(msg)
             logger.debug(traceback.format_exc())
         time.sleep(sleep_time)
コード例 #5
0
def execute_telnet():
    global EXIT_CAPTURE_LOG
    global EXITED_THREAD
    HOST = "192.168.50.177"
    USER = r"gouri"
    PASSWORD = r"Rebaca2015"
    OUT_FILE = "/Users/gouri/Desktop/Output/OUTPUT-%s.log" % \
               datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
    CLR_COMMAND = "adb logcat -c -v time\n"
    #COMMAND = "adb logcat -v time > %s\n" % OUT_FILE
    COMMAND = 'adb logcat -v time | grep -v "D/dalvikvm(" > %s\n' % OUT_FILE
    EXITED_THREAD = False

    # Connecting the telnet
    tn = telnetlib.Telnet(HOST)
    tn.read_until("login: "******"\n")
    tn.read_until("Password:"******"\n")

    # Executing the commands
    tn.write(CLR_COMMAND)
    tn.write(COMMAND)
    while not EXIT_CAPTURE_LOG:
        pass
    tn.write('\x03\n')

    # Exiting the telnet
    tn.write("exit\n")
    info("OUTPUT DEVICE LOG FILE SAVED AT -> %s" % OUT_FILE)
    EXIT_CAPTURE_LOG = False
    EXITED_THREAD = True
コード例 #6
0
 def set_up(self):
     """
     Connect with the Appium and set implicitly wait to find an element.
     This will also launch the application in the device.
     """
     info("CONNECTING APPIUM ON %s"%self.remote_host_url)
     self.driver = webdriver.Remote(self.remote_host_url, self.desired_caps)
     self.driver.implicitly_wait(4)#10
     info("CONNECTED APPIUM ON %s"%self.remote_host_url)
コード例 #7
0
def after_step(context, step):
    """ This gets called after executing the step """
    if 'failed' == step.status.lower().strip():
        call_fun = fail
    elif 'passed' == step.status.lower().strip():
        call_fun = success
    else:
        call_fun = info
    call_fun("EXECUTED-STEP : %s" % step.name)
    info("STEP STATUS : %s" % step.status)
    info("STEP DURATION : %s" % step.duration)
コード例 #8
0
def before_scenario(context, scenario):
    """ This gets called before executing the scenario """
    SCENARIO_DATA.clear()

    if ACCUMULATE_LOG:
        t = Thread(target=execute_telnet)
        t.daemon = True
        t.start()

    info("EXECUTING-SCENARIO : %s" % scenario.name)
    info("FILE : %s" % scenario.filename)
コード例 #9
0
ファイル: pystemon.py プロジェクト: theDevilsVoice/pystemon
def failed_proxy(proxy):
    proxies_failed.append(proxy)
    if proxies_failed.count(proxy) >= 2 and proxy in proxies_list:
        logger.info("Removing proxy {0} from proxy list because of to many errors errors.".format(proxy))
        proxies_lock.acquire()
        try:
            proxies_list.remove(proxy)
        except ValueError:
            pass
        proxies_lock.release()
        logger.info("Proxies left: {0}".format(len(proxies_list)))
コード例 #10
0
 def take_screenshot(self, file_name=""):
     """ Take the screen shot from the device
     @arg:
         file_name : provide name of the screen shot file to be saved
     """
     if not file_name:
         file_name = datetime.datetime.now().strftime("SS-%Y_%m_%d_%H_%M_%S.png")
         file_name = os.path.join(SCREEN_SHOT_DIR, file_name)
     self.driver.save_screenshot(file_name)
     info("screen shot taken : %s" % file_name)
     return file_name
コード例 #11
0
    def scrol_right_to_left(self, retry=2, indx=None, ret_all_data=False):
        """
        Scroll from right to left,
        @args:
            retry : Number of scroll retries after reaching to left
            indx  : If you pass a low value it will try to scroll more, which result
                    the big scrolling.
            ret_all_data : True if you want to get all data that found during the
                           scroll, else False
        """
        ele = "//android.widget.HorizontalScrollView[1]/" + \
              "android.widget.LinearLayout[1]//android.widget.TextView[1]"
        for echtry in range(4):
            try:
                ele_obj = self.get_element_by_xpath(ele)
                break
            except Exception as excp:
                warning(str(excp))
                if self.is_item_visible("setting-popup-cancel-btn"):
                    info("cancel button shown up, clicking on it")
                    self.click_on("setting-popup-cancel-btn")
                self.wait_for(1)
        else:
            raise Exception("not able to access the horizontal scroll element")

        list_text = list_text_old = [ech_ele.text for ech_ele in ele_obj]
        indx = len(ele_obj)/2 if indx == None else indx
        from_pt = ele_obj[0].location
        from_pt = (from_pt['x'], from_pt['y'])
        to_pt = ele_obj[indx].location
        to_pt = (to_pt['x'], to_pt['y'])

        tmp_retry = retry
        while tmp_retry > 0:
            self.scroll('H', frm_pt=from_pt, to_pt=to_pt)
            ele_obj = self.get_element_by_xpath(ele)
            list_text_new = [ech_ele.text for ech_ele in ele_obj]
            if list_text_new[:2] == list_text_old[:2]:
                tmp_retry -= 1
            else:
                if ret_all_data:
                    output = self.contains(list_text_old[:2], list_text_new)
                    if output == False:
                        info(str(list_text_old[:2]) + " not in " + \
                             str(list_text_new))
                        list_text[0:0] = list_text_new
                    else:
                        list_text[0:0] = list_text_new[:output[0]]

                list_text_old = list_text_new
                tmp_retry = retry

        if ret_all_data:
            return list_text
コード例 #12
0
 def should_visible(self, element_name, generic_param=()):
     """
     Check if an element is visible, raise exception if it is not.
     @args :
         element_name : name of the element (whose entry is in
                       element-path.cfg)
                       or the element object
         generic_param  : dynamic xpath/id variable
     """
     info("checking visibility :: %s :: %s" % (element_name, generic_param))
     ele_obj = self.get_element(element_name, generic_param=generic_param)
     if not ele_obj.is_displayed():
         raise Exception("Element %s is not visible"%element_name)
コード例 #13
0
 def should_not_visible(self, ele, generic_param=()):
     """
     Check if an element is not visible, raise exception if it is.
     @args :
         ele : name of the element (whose entry is in element-path.cfg)
               or the element object
         generic_param  : dynamic xpath/id variable
     """
     try:
         ele_obj = self.get_element(ele, generic_param=generic_param)
         if ele_obj.is_displayed():
             raise Exception("Element %s is visible"%ele)
     except Exception as ex:
         info(str(ex))
コード例 #14
0
ファイル: db.py プロジェクト: DSD-ESDC-EDSC/pass
 def __init__(self):
     try:
         self.pg_pool = pool.SimpleConnectionPool(1,
                                                  5,
                                                  user=DB.USER,
                                                  password=DB.PASSWORD,
                                                  host=DB.HOST,
                                                  database=DB.NAME)
         self.conn = self.pg_pool.getconn()
         self.cur = self.conn.cursor()
         logger.info('Connection to database succeeded')
     except Exception as e:
         logger.error(f'Connection to database failed: {e}')
     self.start_time = time.time()
コード例 #15
0
    def scrol_left_to_right(self, retry=2, indx=None, ret_all_data=False):
        """
        Scroll from left to right,
        @args :
            retry : Number of scroll retries after reaching to right
            indx  : If you pass a low value it will try to scroll more, which result
                    the big scrolling.
            ret_all_data : True if you want to get all data that found during the
                           scroll, else False
        """
        ele = "//android.widget.HorizontalScrollView[1]/" + \
              "android.widget.LinearLayout[1]//android.widget.TextView[1]"

        for echtry in range(4):
            try:
                ele_obj = self.get_element_by_xpath(ele)
                break
            except Exception as exc:
                info(str(exc))
                self.wait_for(1)

        list_text = list_text_old = [ech_ele.text for ech_ele in ele_obj]
        indx = -len(ele_obj)/2 if indx == None else indx
        from_pt = ele_obj[-1].location
        from_pt = (from_pt['x'], from_pt['y'])
        to_pt = ele_obj[indx].location
        to_pt = (to_pt['x'], to_pt['y'])

        tmp_retry = retry
        while tmp_retry > 0:
            self.scroll('H', frm_pt=from_pt, to_pt=to_pt)
            ele_obj = self.get_element_by_xpath(ele)
            list_text_new = [ech_ele.text for ech_ele in ele_obj]
            if list_text_new[-2:] == list_text_old[-2:]:
                tmp_retry -= 1
            else:
                if ret_all_data:
                    output = self.contains(list_text_old[-2:], list_text_new)
                    if output == False:
                        info(str(list_text_old[-2:]) + " not in " + \
                             str(list_text_new))
                        list_text.extend(list_text_new)
                    else:
                        list_text.extend(list_text_new[output[1]:])
                list_text_old = list_text_new
                tmp_retry = retry

        if ret_all_data:
            return list_text
コード例 #16
0
 def value_should_be(self, element_name, expected_value, generic_param=()):
     """
     Check element has the same value that we provided
     @args :
         element_name   : name of element (whose entry is in element-path.cfg)
                          or the element object
         expected_value : expected value
         generic_param  : dynamic xpath/id variable
     """
     info("checking exact value :: %s :: %s :::: value=%s" % \
         (element_name, generic_param, expected_value))
     ele_obj = self.get_element(element_name, generic_param=generic_param)
     if str(ele_obj.text).strip() != str(expected_value).strip():
         raise Exception("Expected value: %s, Got value: %s"%(expected_value,
                                                              ele_obj.text))
コード例 #17
0
ファイル: pystemon.py プロジェクト: theDevilsVoice/pystemon
 def action_on_match(self):
     msg = 'Found hit for {matches} in pastie {url}'.format(
         matches=self.matches_to_text(), url=self.url)
     logger.info(msg)
     # store info in DB
     if db:
         db.queue.put(self)
     # Save pastie to disk if configured
     if yamlconfig['archive']['save']:
         self.save_pastie(self.site.save_dir)
     if yamlconfig['mongo']['save']:
         self.save_mongo()
     # Send email alert if configured
     if yamlconfig['email']['alert']:
         self.send_email_alert()
コード例 #18
0
    def refresh_by_pull_down(self):
        """ Refresh your tab by pull it down """
        try:
            self.scrol_bottom_to_top(retry=1)
        except Exception as ex:
            info(str(ex))
        obj = self.get_element("tab-content")
        obj_data = {'width' :  int(obj.size['width']),
                    'height':  int(obj.size['height']),
                    'x' :      int(obj.location['x']),
                    'y' :      int(obj.location['y'])}

        start_pt = (obj_data['x'] + (obj_data['width']/2) , obj_data['y'])
        end_pt = (start_pt[0], start_pt[1] + int(obj_data['height'] * 0.75))
        self.driver.swipe(start_pt[0], start_pt[1], end_pt[0], end_pt[1])
コード例 #19
0
 def is_item_visible(self, element_name, generic_param=()):
     """
     Return True if item is visible else False
     @args :
         element_name  : name of element (whose entry is in element-path.cfg)
                         or the element object
         generic_param : dynamic xpath/id variable
     """
     info("is element :: %s::%s visible" % (element_name, generic_param))
     visible = False
     try:
         self.should_visible(element_name, generic_param=generic_param)
         visible = True
     except Exception as ex :
         info(str(ex))
     return visible
コード例 #20
0
    def __load_noise_machine_info(self):
        data = io.read_json(ng_info_filename)
        if not (data): logger.error("Could not load noise machine input file")

        pattern = r"(?i)(?<=(.*NoiseMachines/)).+"
        for nm in data["noiseMachines"]:
            nm_name = re.search(pattern, nm["href"])
            # need to handle custom.php: [Can't Take The Sky From Me](https://mynoise.net/NoiseMachines/custom.php?l=3035403037323015253200&amp;m=CINEMATIC1~INTERGALACTIC1~BATTLE1~EASTASIA2~CINEMATIC3~CANYON5~EASTASIA6~CANYON7~EASTASIA7~CINEMATIC9&amp;d=0&amp;title=Can't%20Take%20The%20Sky%20From%20Me)",
            if (nm_name):
                if nm_name not in self.__noise_machines:
                    self.__noise_machines[nm_name] = nm
                else:
                    logger.info(
                        "Noise machine already exists for: {}".format(nm_name))
            else:
                logger.info("Could not parse noise machine HREF: {}".format(
                    nm["href"]))
コード例 #21
0
 def clear_value(ele_obj):
     """
     Clear out the element text
     @arg :
         ele_obj : element object that text need to clear out
     """
     for i in range(7):
         try:
             txt = str(ele_obj.text).strip()
             if txt:
                 ele_obj.click()
                 ele_obj.clear()
             else:
                 info("object got clear out")
                 break
         except Exception as ex :
             warning("Got exception while clear out value :: " + str(ex))
コード例 #22
0
def run_model():
    req = request.get_json()

    try:
        beta = float(req['beta'])
        transportation = req['transportation']
        threshold = int(
            req['threshold']
        ) * 1000  # multiply to get the minute threshold to match distance matrix meter units
        bounds = req['bounds']
        logger.info(
            f'User parameters include beta: {beta}, transport: {transportation}, threshold: {threshold}'
        )
    except Exception as e:
        logger.error(f'Parameters provided are incorrect: {e}')
        return e

    supply = req['supply']
    demand = req['demand']
    capacity = req['capacity']

    scores = model.accessibility(bounds, beta, transportation, threshold,
                                 demand, supply, capacity)
    scores_col = str(list(scores.columns.values))
    scores_row = str(scores.index)
    max = scores['scores'].max()

    try:
        scores['boundary'] = scores['boundary'].apply(wkt.loads)
        features = scores.apply(
            lambda row: Feature(geometry=row['boundary'],
                                properties={
                                    'geouid': row['geouid'],
                                    'score': row['scores']
                                }),
            axis=1).tolist()
        feature_collection = FeatureCollection(
            score_vals=scores['scores'].tolist(), max=max, features=features)
        feature_collection = json.dumps(feature_collection)
        return feature_collection
    except Exception as e:
        logger.error(f'{scores_row}')
        logger.error(f'{scores_col}')
        logger.error(f'Could not return results as geojson: {e}')
        return e
コード例 #23
0
 def test_on(self, platform, version, device_name):
     """ Set the desire capabilities according to the targeted platform
     @args:
         platform    : android / iOS
         version     : platform version
         device_name : name of the device
     """
     if platform.lower().strip() == "android":
         self.desired_caps['platformName'] = 'Android'
         self.desired_caps['platformVersion'] = str(version)
         self.desired_caps['deviceName'] = device_name
         info("TEST ON ANDROID ::: %s"%self.desired_caps)
     else:
         self.desired_caps['appium-version'] = '1.0'
         self.desired_caps['platformName'] = 'iOS'
         self.desired_caps['platformVersion'] = str(version)
         self.desired_caps['deviceName'] = device_name
         info("TEST ON IOS ::: %s" % self.desired_caps)
コード例 #24
0
 def value_should_contains(self, element_name, expected_value, generic_param=()):
     """
     Check if the element value contains a particular value
     @args :
         element_name   : name of the element
                          (whose entry is in element-path.cfg)
                          or the element object
         expected_value : expected value, that the element value should
                          contains
         generic_param  : dynamic xpath/id variable
     """
     info("check element :: %s:%s :: should contains :: value=%s" % \
                       (element_name, generic_param, expected_value))
     ele_obj = self.get_element(element_name, generic_param=generic_param)
     if str(ele_obj.text).strip() not in str(expected_value).strip():
         msg = "element: %s::%s, actual value received: %s, value doesn't contains: %s"
         raise Exception(msg % (element_name, generic_param,
                                ele_obj.text, expected_value))
コード例 #25
0
async def dump_dict(pugdict):
    '''
    Writes down the pugger list to disk.
    TODO: Avoid spamming the disk! Set limits!
    TODO: Make non-blocking write calls
    '''
    async with aiofiles.open(config.sfcpugger_mem_path, 'w') as file:
        try:
            await file.write(json.dumps(pugdict))
            logmsg = 'Saved pugger checkins to disk'
            print(logmsg)
            logger.info(logmsg)
        except Exception as ex:
            logmsg = 'Exception: {}\n'.format(str(ex))
            logmsg += 'Could not write to json from {0}'.format(
                config.sfcpugger_mem_path)
            print(logmsg)
            logger.info(logmsg)
コード例 #26
0
ファイル: appetite.py プロジェクト: gjanders/appetite
    def update_hosts(self):
        """Update each host

        Installs apps and run commands to each host.
        """

        # When running check, no connections to host will be used
        changed_hosts = [host for host in self.appetite_hosts if host.updates]

        # Lists Sites
        host_sites = list(set([host.site for host in self.appetite_hosts]))
        host_sites.sort()

        # Organize scripts to run in order
        for script_seq in Consts.DM_COMMANDS_SEQUENCE:
            for boot_group in self.boot_ordering:
                host_group = [
                    host for host in changed_hosts
                    if host.app_class in boot_group
                ]

                # If site override is enabled then do all hosts
                if self.args.site_override:
                    if len(host_group) > 0:
                        Logger.info("Starting script run hosts",
                                    site='all',
                                    boot_group=boot_group,
                                    script_level=script_seq)
                        self._thread_hosts('update_host', host_group,
                                           script_seq)
                    continue

                # By default will use sites to break up installs
                for host_site in host_sites:
                    host_site_group = [
                        host for host in host_group if host.site == host_site
                    ]
                    if len(host_site_group) > 0:
                        Logger.info("Starting script run hosts",
                                    site=str(host_site),
                                    boot_group=boot_group,
                                    script_level=script_seq)
                        self._thread_hosts('update_host', host_site_group,
                                           script_seq)
コード例 #27
0
    def set_value(self, element_name, value, generic_param=()):
        """
        Set a value to a GUI element, raise exception if the element
        does not present.
        @args :
            element_name  : name of the element
                            (whose entry is in element-path.cfg)
                            or the element object
            value : value to set for the GUI element
            generic_param : dynamic xpath/id variable
        """
        info("setting value :: %s :: %s ::: value=%s" % (element_name,
                                                         generic_param, value))
        ele_obj = self.get_element(element_name,
                                   generic_param=generic_param)
        self.clear_value(ele_obj)

        #ele_obj.set_text(str(value))
        info("setting the value")
        ele_obj.send_keys(str(value))
コード例 #28
0
ファイル: appetite.py プロジェクト: gjanders/appetite
    def bootstrap_firstrun_hosts(self, host, row_values):
        """Function used to bootstrap apps on the first run"""

        first_run = self.is_bootstrap(host)

        if first_run:
            # For the special case when instance is new,
            # start up apps have to be included
            if first_run['update_method'] == row_values.deployment:
                if not host.bootstrap:
                    host.bootstrap = True
                    Logger.info("Bootstrapping host", host=host.hostname)

                # get host name to check againt
                check_hostname = next(
                    (host.hostname for host in self.appetite_hosts
                     if host.app_class == first_run['app_class']), "")

                return self.add_to_host(host, row_values, check_hostname,
                                        first_run['ref_method'], True)
        return False
コード例 #29
0
 def click_on(self, element, generic_param=()):
     """
     If you provide element name then:
        It will get the details entry for this element from element-path.cfg
        and then get that element and click on that
     If you provide an element object then it will click on that element.
     If click successful then it will return the element object.
     @args :
         element : name of the element (whose entry is in element-path.cfg)
                   or the element object
         generic_param : dynamic xpath/id variable
     """
     info("clicking on : %s :: %s"%(element, generic_param))
     if type(element) == str:
         ele_obj = self.get_element(element, generic_param=generic_param)
         ele_obj.click()
     else:
         element.click()
         ele_obj = element
     info("clicked on the element")
     return ele_obj
コード例 #30
0
    def vertical_scroll_once(self, to_up=True, scroll_ele_typ=None):
        """
        Single scroll that will get performed on a perticular tab
        @args:
            to_up : True, if travel to up
            scroll_ele_typ : popup/ normal
        """

        if not scroll_ele_typ :
            ele = "//android.widget.ListView[1]//android.widget.TextView[1]"
        else:
            ele = "//android.widget.CheckedTextView"

        try:
            obj_list = self.get_element_by_xpath(ele)
        except Exception as exc :
            info(str(exc))
            if not scroll_ele_typ :
                raise Exception("not able to get list of data from GUI")
            else:
                raise Exception("not able to get list of checkbox from GUI")

        obj_list = [obj_list[0], obj_list[-1]]
        top_pt = (int(obj_list[0].location['x']) + \
                  (int(obj_list[0].size['width']) / 2),
                  int(obj_list[0].location['y']))
        if top_pt[1] == int(obj_list[-1].location['y']):
            down_pt = (top_pt[0],
                       int(obj_list[-1].location['y']) + \
                       int(obj_list[-1].size['height']))
        else:
            down_pt = (top_pt[0],
                       int(obj_list[-1].location['y']))
            # because sometime some part of the element is visible
            # so if we add height then it will goes out of bound

        if to_up:
            self.scroll('V', frm_pt=top_pt, to_pt=down_pt)
        else:
            self.scroll('V', frm_pt=down_pt, to_pt=top_pt)
コード例 #31
0
    def rotate_device(self, to_orientation=None):
        """
        Rotate the device:
        If the device is in horizontal then make it vertical and vice versa
        Output of setScreenOrientation:
            {u'status': 0, u'sessionId': u'48e6ef5f-8113-4418-88f2-537538a46169',
             u'value': u'LANDSCAPE'}
            {u'status': 0, u'sessionId': u'53a017b6-3839-433e-a851-4ba1861b398e',
             u'value': u'PORTRAIT'}
        """
        info("rotating the device")
        orientation_map = {'LANDSCAPE':'PORTRAIT', 'PORTRAIT':'LANDSCAPE'}
        change_from = self.get_current_orientation()
        if to_orientation == None:
            change_to = orientation_map[change_from]
        else:
            change_to = to_orientation.strip().upper()

        if change_from.strip().upper() != change_to.strip().upper() :
            out_put = self.driver.execute('setScreenOrientation',
                                          {'orientation': change_to})
        else:
            out_put = {}
        info(str(out_put))
        info("orientation changed from %s to %s"%(change_from, change_to))
        return change_from, change_to, out_put
コード例 #32
0
async def sfc_pugs_task(client):
    '''
    Background task to check for pugger status timeouts
    '''
    global puggers

    await client.wait_until_ready()

    while not client.is_closed():
        try:
            async with aiofiles.open(config.sfcpugger_mem_path, 'r') as f:
                try:
                    pd = json.loads(await f.read())
                    puggers = {**puggers, **{int(k): v for k, v in pd.items()}}
                except Exception as ex:
                    logmsg = 'Exception: {}\n'.format(str(ex))
                    logmsg += 'Could not write to json from {0}'.format(
                        config.sfcpugger_mem_path)
                    print(logmsg)
                    logger.info(logmsg)

            for k, v in puggers.items():
                time_diff = (
                    datetime.datetime.now() -
                    datetime.datetime.strptime(v['ts'], "%Y-%m-%d %H:%M"))

                if time_diff.seconds >= (config.sfcpugger_timeout * 60):
                    reason = 'Automatically restored from cached state'
                    guild = client.get_guild(id=v['g'])
                    user = guild.get_member(k)
                    await remove_pugger(client, user, reason)

        except FileNotFoundError:
            logmsg = 'File Not Found while attempting to read cache file at: {}\n'.format(
                config.sfcpugger_mem_path)
            print(logmsg)
            logger.info(logmsg)
        finally:
            await asyncio.sleep(config.sfcpugger_interval * 60)
コード例 #33
0
    def re_launch_limelight_app(self, app_display_name):
        """
        Re launch the application from the device menu
        @arg :
            app_display_name : Application name that is displaying in menu
        """
        try:
            self.click_on("phone-menu")
        except Exception as ex:
            info("while using phone-menu xpath got error: %s "%str(ex))
            info("using the phone-menu-samsung xpath")
            self.wait_for(3)
            self.click_on("phone-menu-samsung")

        from_point, to_point = None, None
        app_icn = "android.widget.TextView"
        set_coordinate = True

        for ech_try in range(3):

            for ech_element in self.driver.find_elements_by_class_name(app_icn):
                x_coordinate = int(ech_element.location['x'])
                y_coordinate = int(ech_element.location['y'])
                if set_coordinate:
                    if not from_point or from_point[1] == y_coordinate:
                        from_point = [x_coordinate, y_coordinate]
                    elif from_point[1] < y_coordinate:
                        from_point[1] = y_coordinate
                        to_point = [from_point[0]/2, y_coordinate]
                        set_coordinate = False

                if str(ech_element.text).strip() == app_display_name:
                    ech_element.click()
                    return True
            self.scroll("H", direction=None, frm_pt=from_point, to_pt=to_point)
        # If control reach here then then app-icon not found
        return False
コード例 #34
0
import os
import pandas as pandas
from modules import loadData, logger
import multiprocessing

if __name__ == '__main__':
	p = multiprocessing.Pool(3)
	logger.info('Getting file names...')
	fnames = loadData.get_fnames()
	logger.info('Reading in json files...')
	l_df = p.map(loadData.read_data, fnames)
	logger.info('Read successful!')
	logger.info('Separating nested JSON objects...')
	p.starmap(loadData.clean_tables, l_df)
	logger.info('Added dataframes to database!')
	del l_df