예제 #1
0
class TestConfigData:
    def setup(self):
        print('Test start.')
        self.config = Config(
            '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml'
        )

    def teardown(self):
        del self.config
        print('Test end.')

    def test_get_attr_str(self):
        platform_name = self.config.platformName
        assert platform_name == 'Android'

    def test_get_attr_list(self):
        list_data = self.config.test_list
        for i in range(1, 4):
            assert list_data[i - 1] == i

    def test_get_attr_error(self):
        with pytest.raises(expected_exception=AttributeError):
            self.config.error_attr

    def test_get_appium_desired_caps(self):
        desired_caps = self.config.appium_desired_caps()
        assert desired_caps['appPackage'] == 'com.nbaimd.gametime.nba2011'
        assert desired_caps[
            'appActivity'] == 'com.neulion.nba.base.LaunchDispatcherActivity'

    def test_white_apps(self):
        white_apps = self.config.white_apps()
        assert isinstance(white_apps, Set)
        assert "com.nbaimd.gametime.nba2011" in white_apps
예제 #2
0
class TestAppiumUtil:

    def setup(self):
        print('Test start.')
        # config_path = '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml'
        config_path = os.path.join(os.path.dirname(__file__), 'testdata/config', 'NBA_Android_config.yml')
        uid = device_info_util.get_serial_numbers_android()
        self.config = Config(config_path, uid[0])

    def teardown(self):
        print('Test end.')
        del self.config

    def test_appium_init_driver(self):
        self.driver = Appium(self.config.appium_desired_caps())
        self.driver.quit()

    def test_save_page_source(self):
        self.driver = Appium(self.config.appium_desired_caps())
        time.sleep(20)
        page_source = self.driver.get_page_source()
        date = str(int(time.time()))
        with open('testdata/pageSource/{}.xml'.format(date), 'w', encoding='utf-8') as fp:
            fp.write(page_source)

        self.driver.quit()
예제 #3
0
 def setup(self):
     print('test start')
     uid = device_info_util.get_serial_numbers_android()
     config_path = os.path.join(os.path.dirname(__file__), 'testdata',
                                'config', 'NBA_Android_config.yml')
     config = Config(config_path, uid[0])
     screenshot = os.path.join(os.path.dirname(__file__),
                               'testdata\\screenshot')
     if not os.path.exists(screenshot):
         os.mkdir(screenshot)
     self.driver = Appium(config.appium_desired_caps())
예제 #4
0
 def __init__(self):
     config = Config('space_window.conf', __file__)
     location = config.get('weather', 'location',
                           'United_Kingdom/England/London')
     self.url = 'https://www.yr.no/place/%s/forecast.xml' % location
     self.re_top = re.compile('<time from=.*?\/time>', re.S)
     self.re_desc = re.compile('<symbol number=\".*?\" name=\"(.*?)\"')
     self.re_temp = re.compile('<temperature unit=\".*?\" value=\"(.*?)"')
     #self.re_wind_dir=re.compile('<windDirection.*? code=\"(.*?)\"')
     self.re_wind_speed=\
         re.compile('<windSpeed.*? mps=\"(.*?)\".*?name=\"(.*?)"')
예제 #5
0
    def load_config(self):
        config = Config('space_window.conf', __file__)
        self._player = config.get('player', 'player', 'omxplayer')

        self._player_args = config.get(
            'player', 'player_args',
            ' --timeout 60 --loop --no-osd -b').replace('-b', '')
        self._player_pl_args = config.get('player', 'playlist_player_args',
                                          ' --timeout 60 --no-osd -b').replace(
                                              '-b', '')

        self._player_cmd = self._player + ' ' + self._player_args
        self._player_pl_cmd = self._player + ' ' + self._player_pl_args
예제 #6
0
 def load_config(self):
     config = Config('space_window.conf', __file__)
     self._delay = config.getint('nasa', 'frame_delay', 5)
     self._fontname = config.get('font', 'name', 'comicsansms')
     self._fontsize = config.getint('nasa', 'font_size', 48)
     self._font = pg.font.SysFont(self._fontname, self._fontsize)
     self._text_col = config.getcolor('nasa', 'foreground', (100, 100, 100))
     self._text_height_ratio = config.getint('nasa', 'height_ratio', 10)
예제 #7
0
 def __init__(self,status_update_func,screen):
     config = Config('space_window.conf',__file__)    
     self._start_with=config.get('global','start_with','streams')
     self._current_stream=None
     self._resume_stream=None
     self._check_timer_delay=20
     self._check_timer=None
     self._wait=False
     self._streams=Streams.load()
     self._nasa=NasaPod(screen)
     self._gallery=Gallery(status_update_func,screen)
     self._music=Music(status_update_func)
     self._clock=Clock(screen)
     self._mopidy=None
     self._status_update=status_update_func    
     if not _standalone:
         threading.Thread(target=self.launch_mopidy).start()
     self._streams.set_status_func(status_update_func)
     self._resume_func=self.run_something
예제 #8
0
def performer(config_path, serial, timer):
    config = Config(config_path, udid=serial)
    spider = Crawler(config, timer)
    try:
        while True:
            spider.run()
    except QuitAppiumException:
        # return test result.
        return spider.report_path, spider.record
        log.error('test end!')
예제 #9
0
 def load_config(self):
     config = Config('space_window.conf', __file__)
     self._forecol = config.getcolor('clock', 'foreground', (255, 128, 0))
     bckcol = config.getcolor('clock', 'background', (32, 0, 32))
     time_sz = config.getint('clock', 'time_size', 192)
     date_sz = config.getint('clock', 'date_size', 24)
     self._border = config.getint('clock', 'border', 10)
     self._separation = config.getint('clock', 'separation', 8)
     path = os.path.dirname(os.path.abspath(__file__))
     fontname = os.path.join(path, 'digital-7_mono.ttf')
     self._time_font = pygame.font.Font(fontname, time_sz)
     self._secs_font = pygame.font.Font(fontname, time_sz / 3)
     self._date_font = pygame.font.Font(fontname, date_sz)
     self._black.fill(bckcol)
     self._init_rects()
     timezone = config.get('clock', 'timezone', 'NONE')
     if timezone != 'NONE':
         os.environ['TZ'] = timezone
         time.tzset()
예제 #10
0
    def __init__(self,screen):
        config = Config('space_window.conf',__file__)    

        self._border=config.getint('message','border',10)
        self._left=config.getbool('message','left',False)
        self._top=config.getbool('message','top',False)
        self._forecol=config.getcolor('message','foreground',(255,128,0))
        bckcol=config.getcolor('message','background',(32,0,32))
        fontname=config.get('font','name','comicsansms')
        fontsz=config.getint('message','font_size',68)
        
        self.running=False
        self._delay=1
        self._screen=None
        self.text=None
        self.black=None
        self.font=None
        #sleep(1)
        self.screen = screen
        self.black=self.screen.copy()
        self.black.fill(bckcol)
        self.font = pg.font.SysFont(fontname, fontsz)
        self.lock=threading.Lock()
예제 #11
0
def screen():
    global _screen
    if _screen is None:
        config = Config('space_window.conf', __file__)
        fbdev = config.get('pygame', 'fbdev', 'None')
        if fbdev != 'None':
            os.putenv('SDL_VIDEODRIVER', 'fbcon')
            os.environ["SDL_FBDEV"] = fbdev

        pygame_init()
        scrw = config.getint('pygame', 'screen_width', 0)
        scrh = config.getint('pygame', 'screen_height', 0)
        depth = config.getint('pygame', 'screen_depth', 0)

        if depth == 0:
            _screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        else:
            _screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN, depth)
    return _screen
예제 #12
0
    def __init__(self, status_func=None):
        self._status_func = status_func
        self.playing = False
        config = Config('space_window.conf', __file__)
        self._player = config.get('player', 'player', _player)

        self._player_args = config.get('player', 'player_args', _player_args)
        self._player_pl_args=config.get('player','playlist_player_args',\
                _player_args)

        self._player_cmd = self._player + ' ' + self._player_args
        self._player_pl_cmd = self._player + ' ' + self._player_pl_args
        self._player_stream_cmd = self._player_pl_cmd
        self._player_fbcp = ''
        fbdev = config.get('pygame', 'fbdev', 'None')
        if fbdev != 'None':
            self._player_fbcp = 'fbcp&'
            self._player_cmd = 'fbcp& ' + self._player_cmd
            self._player_pl_cmd = 'fbcp& ' + self._player_pl_cmd

        _log = logger.get(__name__)
예제 #13
0
 def test_config_file_incorrect(self, path):
     with pytest.raises(expected_exception=Exception):
         Config(path)
예제 #14
0
_wpa_block_open = """
\tnetwork={
\t        ssid="SSIDNAME"
\t        auth_alg=OPEN
\t        key_mgmt=NONE
\t        priority=10
}\n"""

_wpa_header = """
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

"""

config = Config('space_window.conf', __file__)

ap_name = config.get('access-point', 'name', 'UnusualWiFi')
_ap_driver = config.get('access-point', 'driver', 'nl80211')
# edimax driver is rtl871xdrv
_ap_interface = config.get('access-point', 'interface', 'wlan0')
ap_ip = config.get('access-point', 'ip', '192.168.4.1')
_ap_iprange = config.get('access-point', 'iprange', '192.168.4.2,192.168.4.20')


def _get_config_path():
    return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf')


# run a program and wait for it to finish
def run(rcmd):
예제 #15
0
 def load_config(self):
     config = Config('space_window.conf', __file__)
     self._delay = config.getint('gallery', 'frame_delay', 10)
예제 #16
0
 def setup(self):
     print('Test start.')
     # config_path = '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml'
     config_path = os.path.join(os.path.dirname(__file__), 'testdata/config', 'NBA_Android_config.yml')
     uid = device_info_util.get_serial_numbers_android()
     self.config = Config(config_path, uid[0])
예제 #17
0
import random

PORT_NUMBER = 80
MOPIDY_PORT=6680

_ip=wifi.get_ip()
_processes=None
_streams=None
_gallery=None
_music=None
_server=None
_standalone=False
_cnt=random.randint(0,1000)

_log=logger.get(__name__)
_config = Config('space_window.conf',__file__)    

def set_standalone(standalone):
    global _standalone
    _standalone=standalone
    procmod.set_standalone(standalone)

_screen=None
_msg=None
def set_screen(screen):
    global _screen
    global _msg
    _screen = screen
    _msg=msg.MsgScreen(_screen)

def _status_update(txt):
예제 #18
0
 def setup(self):
     print('Test start.')
     self.config = Config(
         '/Users/jameszhang/python/project/appCrawler/test/testdata/config/NBA_Android_config.yml'
     )
예제 #19
0
 def test_config_file_correct(self, path):
     Config(path)
예제 #20
0
def main():
    print_spider()
    try:
        params_dict = cmd_parse()
    except FilePathInvalid as msg:
        log.error(msg)
    else:
        config_path = params_dict.get('config')
        # default 2 minutes.
        timer = int(params_dict.get('timer', 2))
        # default 5 threads.
        max_workers = int(params_dict.get('max_workers', 5))
        # default dfs
        travel_mode = params_dict.get('travel_mode', 'mixture')
        support_mode = {'mixture', 'dfs', 'bfs'}

        if travel_mode not in support_mode:
            _origin_mode = travel_mode
            travel_mode = support_mode.pop()
            log.warning(
                f"{_origin_mode} travel mode is not support, set travel mode to {travel_mode}"
            )
        Crawler.travel_mode = travel_mode

        futures_map = dict()
        config = Config(config_path=config_path)
        devices_list = list()
        platform = config.platformName
        if platform == 'Android':
            devices_list = get_serial_numbers_android()
        elif platform == 'iOS':
            devices_list = get_serial_numbers_ios()
        else:
            log.error("Not support {} platform".format(platform))

        if not devices_list:
            log.warning("Not find any device.")
        else:
            with futures.ThreadPoolExecutor(max_workers) as executor:
                futures_list = []
                for serial in devices_list:
                    future = executor.submit(performer, config_path, serial,
                                             timer)
                    futures_map[future] = serial
                    futures_list.append(future)

                for future in futures.as_completed(futures_list):
                    print(futures_map.get(future))
                    report_dir, record = future.result()
                    json_gene = GenerateJson(report_dir, record)
                    json_gene.insert_crash_log()
                    json_gene.generate_json()

                    # generate report
                    report = Report(report_dir=report_dir)
                    try:
                        report.clear_expired_report(expired_day=3)
                    except Exception as exc:
                        log.error(exc)
                    finally:
                        report.generate_report()

            kill_adb_server()
            log.warning("All test end.")