Ejemplo n.º 1
0
    async def test_time_updates(self):
        self.my_game_lister = ListGames()
        self.my_game_lister.cache_filepath = self.my_game_lister.cache_filepath + "-test_time_updates"
        self.my_tasks = []
        self.configuration = DefaultConfig()
        self.backend = Backend()
        if os.path.exists(self.backend.cache_times_filepath):
            os.remove(self.backend.cache_times_filepath)
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        my_threads = []
        my_thread = Mock()
        my_thread.is_alive = MagicMock(return_value=False)
        my_threads.append(my_thread)
        my_current_time = datetime.now() - timedelta(minutes=1)
        my_thread.name = "{\"time\":\"" + str(
            my_current_time) + "\", \"id\":\"12345A\"}"

        await time_tracking(self, my_threads)

        #local_time_cache = await self.my_game_lister.read_from_cache_filename(self.backend.cache_times_filepath)
        self.assertEqual(1, len(self.backend.local_time_cache))
        my_timed_entry = self.backend.local_time_cache[0]

        self.assertGreaterEqual(my_timed_entry["run_time_total"], 1)
        self.assertEqual(my_timed_entry["last_time_played"],
                         math.floor(my_current_time.timestamp()))
        self.assertEqual(my_timed_entry["hash_digest"], "12345A")

        if os.path.exists(self.backend.cache_times_filepath):
            os.remove(self.backend.cache_times_filepath)
Ejemplo n.º 2
0
    async def test_added_backend(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        systems = await setup_folders_for_testing(self, "TestDirectory11")
        insert_file_into_folder(self, systems, "gbc0", "mygame.gb", "")
        insert_file_into_folder(self, systems, "gbc0", "game.gb", "")
        insert_file_into_folder(self, systems, "dos0", "game.exe", "mygame")
        new_local = await systems.list_all_recursively("test_user")
        for entry in new_local:
            logging.debug("Check")
            if ("local_game_state" not in entry):
                logging.debug("should")
                entry["local_game_state"] = LocalGameState.Installed
        myresult = await get_state_changes([], new_local)

        await added_games(self, new_local, myresult["old"], myresult["new"])
        self.assertEqual(
            3, self.backend.my_queue_update_local_game_status._qsize())
        game_update_from_queue = self.backend.my_queue_update_local_game_status.get(
        )
        self.assertEqual(game_update_from_queue.local_game_state,
                         LocalGameState.Installed)

        self.assertEqual(3, self.backend.my_queue_add_game._qsize())
Ejemplo n.º 3
0
    async def test_start_and_stop_library(self):
        #loop = asyncio.new_event_loop()
        #self.my_library_started = False
        self.keep_ticking = True
        self.my_tasks = []
        self.my_library_started = False
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)
        logging.debug("starting")

        self.started_async_tick = True
        asyncio.get_event_loop()
        my_task = asyncio.create_task(tick_async(self))
        self.my_tasks.append(my_task)

        self.my_library_thread = threading.Thread(target=library_thread,
                                                  args=(self, ))
        self.my_library_thread.daemon = True
        self.my_library_thread.start()

        asyncio.get_event_loop()
        my_task = asyncio.create_task(
            update_local_games(self, "test_user", self.backend.my_game_lister))
        self.my_tasks.append(my_task)
        #self.assertEqual(True, self.my_library_thread.is_alive())
        #self.assertEqual(True, self.my_library_started)
        self.assertEqual(True, self.backend.library_run)
        await shutdown_library(self)
        await shutdown_tasks(self, self.my_tasks)
        #self.assertEqual(False, self.my_library_thread.is_alive())
        self.assertEqual(False, self.backend.library_run)
Ejemplo n.º 4
0
 async def test_config(self):
     config = DefaultConfig()
     logging.debug(config)
     self.assertEqual(config.my_user_to_gog, "username01")
     self.assertEqual(config.my_platform_to_gog, "test")
     self.assertEqual(config.minimum_seconds_between_notification_updates,
                      7)
     self.assertEqual(config.minimize_logging, bool("false"))
     self.assertEqual(config.force_batch_mode_initial_seed, bool("false"))
Ejemplo n.º 5
0
 async def test_launch_thread(self):
     self.my_game_lister = ListGames()
     self.local_game_cache = await self.my_game_lister.list_all_recursively(
         "test_user")
     self.my_authenticated = "test_user"
     self.configuration = DefaultConfig()
     self.backend = Backend()
     await self.backend.setup(self.configuration)
     self.my_threads = []
Ejemplo n.º 6
0
    async def test_do_auth(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)
        self.store_credentials = Mock(return_value=None)

        authenticated_user = await do_auth(self, "test_user")
        self.assertEqual(Authentication('importer_user', "test_user"),
                         authenticated_user)
        self.assertEqual(self.backend.my_authenticated, True)
        user_data = {}
        user_data['username'] = "******"
        self.store_credentials.assert_called_with(user_data)
Ejemplo n.º 7
0
    async def test_prepare_to_send_my_updates(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        systems = await setup_folders_for_testing(self, "TestDirectory3")
        insert_file_into_folder(self, systems, "gbc0", "mygame.gb", "")
        insert_file_into_folder(self, systems, "gbc0", "game.gb", "")
        insert_file_into_folder(self, systems, "dos0", "game.exe", "mygame")
        new_local = await systems.list_all_recursively("test_user")
        for entry in new_local:
            logging.debug("Check")
            if ("local_game_state" not in entry):
                logging.debug("should")
                entry["local_game_state"] = LocalGameState.Installed
        await prepare_to_send_my_updates(self, new_local, [])
Ejemplo n.º 8
0
    def __init__(self, reader, writer, token):
        self.configuration = DefaultConfig()

        super().__init__(
            Platform(self.configuration.my_platform_to_gog
                     ),  # choose platform from available list
            "0.1",  # version
            reader,
            writer,
            token)
        self.backend = Backend()
        self.my_library_thread = None
        self.my_library_started = False
        self.my_threads = []
        self.my_tasks = []
        self.started_async_tick = False
        self.keep_ticking = True
        if (self.configuration.minimize_logging):
            logging.getLogger().setLevel(logging.WARNING)
        else:
            logging.getLogger().setLevel(logging.DEBUG)
Ejemplo n.º 9
0
    async def test_created_time_update(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        systems = await setup_folders_for_testing(self, "TestDirectory8")
        insert_file_into_folder(self, systems, "gbc0", "mygame.gb", "")
        new_local = await systems.list_all_recursively("test_user")
        my_time = datetime.now()
        for entry in new_local:
            logging.debug("Check")
            if ("local_game_state" not in entry):
                logging.debug("should")
                entry["local_game_state"] = LocalGameState.Installed
        updated_Time = await created_update(new_local[0], 1, my_time)
        #New
        self.assertEqual(math.floor(my_time.timestamp()),
                         updated_Time["last_time_played"])
        self.assertEqual(1, updated_Time["run_time_total"])
        updated_Time = await created_update(updated_Time, 1, my_time)
        #Updated
        self.assertEqual(math.floor(my_time.timestamp()),
                         updated_Time["last_time_played"])
        self.assertEqual(2, updated_Time["run_time_total"])
Ejemplo n.º 10
0
    async def test_changed_backend(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        systems = await setup_folders_for_testing(self, "TestDirectory12")
        insert_file_into_folder(self, systems, "gbc0", "mygame.gb", "")
        insert_file_into_folder(self, systems, "gbc0", "game.gb", "")
        insert_file_into_folder(self, systems, "dos0", "game.exe", "mygame")
        new_local = await systems.list_all_recursively("test_user")
        for entry in new_local:
            logging.debug("Check")
            if ("local_game_state" not in entry):
                logging.debug("should")
                entry["local_game_state"] = LocalGameState.Installed
        myresult = await get_state_changes(new_local, new_local)
        myresult["old"][list(
            myresult["old"].keys())[0]] = LocalGameState.Running
        await state_changed(self, myresult["old"], myresult["new"])

        self.assertEqual(
            False, self.backend.my_queue_update_local_game_status.empty())
        self.assertEqual(
            1, self.backend.my_queue_update_local_game_status._qsize())
    async def generatePage(self):
        self.configuration = DefaultConfig()
        self.backend = Backend()
        await self.backend.setup(self.configuration)

        logger.info("Loading data:")
        systems = ListGames()
        data_read = await systems.read_from_cache()
        if (len(data_read) > 0):
            outputFile = open("cache.html", "w")
            outputFile.write(
                str("<html>\n\
                <head>\n\
                <meta charset='UTF-8'>\n\
                <title>Cache</title>\n\
                \n\
                <style>\n\
                .axes {\n\
                  padding: 1em;\n\
                }\n\
                \n\
                .buttons {\n\
                  margin-left: 1em;\n\
                }\n\
                \n\
                /*meter*/.axis {\n\
                  min-width: 200px;\n\
                  margin: 1em;\n\
                }\n\
                \n\
                .button {\n\
                  display: inline-block;\n\
                  width: 1em;\n\
                  text-align: center;\n\
                  padding: 1em;\n\
                  border-radius: 20px;\n\
                  border: 1px solid black;\n\
                  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAxJREFUCNdjYPjPAAACAgEAqiqeJwAAAABJRU5ErkJggg==);\n\
                  background-size: 0% 0%;\n\
                  background-position: 50% 50%;\n\
                  background-repeat: no-repeat;\n\
                }\n\
                \n\
                .pressed {\n\
                  border: 1px solid red;\n\
                }\n\
                \n\
                .touched::after {\n\
                  content: 'touch';\n\
                  display: block;\n\
                  position: absolute;\n\
                  margin-top: -0.2em;\n\
                  margin-left: -0.5em;\n\
                  font-size: 0.8em;\n\
                  opacity: 0.7;\n\
                }\n\
                </style>\n\
                </head>\n\
                <body>\n\
                <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>\n\
                <link rel='stylesheet' type='text/css' href='https://cdn.datatables.net/1.11.0/css/jquery.dataTables.css'>\n\
                <script type='text/javascript' charset='utf8' src='https://cdn.datatables.net/1.11.0/js/jquery.dataTables.js'></script>\n\
                <script type='text/javascript' charset='utf8' src='https://cdn.datatables.net/select/1.3.3/js/dataTables.select.js'></script>\n\
                <link rel='stylesheet' type='text/css' href='https://cdn.datatables.net/select/1.3.3/css/select.dataTables.css'>\n\
                <script>\n\
                  function myOpenGalaxyFunction() {\n\
                    window.open('goggalaxy://openGameView/test_'+$('#mytable').DataTable().row({ selected: true }).data()[11],'_self');\n\
                  }\n\
                </script>\n\
                \n\
                <script>\n\
                function myTableUpdatesFunction(){\n\
                    //Update table changes of stuff\n\
                    //if (controllers[0].axes[0].toFixed(4)==1)//right\n\
                    if (controllers!=null && controllers[0]!=undefined && myStartTime +175 < Date.now()) {\n\
                        if (controllers[0].axes[1].toFixed(4)==1)//down\n\
                        {\n\
                            var nextval = $('#mytable').DataTable().row({ selected: true }).next();\n\
                            if (null!= nextval){\n\
                                nextval.select()\n\
                                var myNodeLocation = $('#mytable').DataTable().rows({order: 'current'}).nodes().indexOf($('#mytable').DataTable().row({ selected: true }).node());\n\
                                var myPage = Math.floor(myNodeLocation/$('#mytable').DataTable().page.len());\n\
                                $('#mytable').DataTable().page(myPage).draw(false);\n\
                                //$('#mytable').DataTable().page( 'next' ).draw( 'page' );\n\
                                myStartTime = Date.now();\n\
                            }\n\
                        }\n\
                        if (controllers[0].axes[1].toFixed(4)==-1)//up\n\
                        {\n\
                            var prevval = $('#mytable').DataTable().row({ selected: true }).prev()\n\
                            if (null!= prevval){\n\
                                prevval.select()\n\
                                var myNodeLocation = $('#mytable').DataTable().rows({order: 'current'}).nodes().indexOf($('#mytable').DataTable().row({ selected: true }).node());\n\
                                var myPage = Math.floor(myNodeLocation/$('#mytable').DataTable().page.len());\n\
                                $('#mytable').DataTable().page(myPage).draw(false);\n\
                                //$('#mytable').DataTable().page( 'previous' ).draw( 'page' );\n\
                                myStartTime = Date.now();\n\
                            }\n\
                        }\n\
                        //Copy to clipboard (x)\n\
                        if (controllers[0].buttons[2].touched)\n\
                        {\n\
                            navigator.clipboard.writeText($('#mytable').DataTable().row({ selected: true }).data()[17]);\n\
                            myStartTime = Date.now();\n\
                        }\n\
                        \n\
                        //Open in galaxy (a)\n\
                        if (controllers[0].buttons[0].touched)\n\
                        {\n\
                            //If this doesn't provide the open dialogue you need to click on the page with the mouse again\n\
                            myOpenGalaxyFunction();\n\
                            myStartTime = Date.now();\n\
                        }\n\
                        //alert command to open galaxy page (y)\n\
                        if (controllers[0].buttons[3].touched)\n\
                        {\n\
                            alert('goggalaxy://openGameView/test_'+$('#mytable').DataTable().row({ selected: true }).data()[11]);\n\
                            myStartTime = Date.now();\n\
                        }\n\
                        \n\
                    }\n\
                }\n\
                </script>\n\
                \n\
                <button onclick='myOpenGalaxyFunction()' id ='openGalaxyButton'>Open selected in galaxy</button>\n\
                \n\
                <table id='mytable' class='display'>\n"))
            outputFile.write(str("<thead>\n<tr>\n"))
            for headerKey in data_read[0]:
                outputFile.write(str("<th>" + str(headerKey) + "</th>\n"))
                # Have it a second time for without the link
                if (headerKey == "hash_digest"):
                    outputFile.write(str("<th>" + str(headerKey) + "</th>\n"))
            outputFile.write(str("<th>derived execution</th>\n"))
            outputFile.write(str("</tr>\n</thead>\n<tbody>\n"))
            for entry in data_read:
                logger.info(entry)
                outputFile.write(str("<tr>"))
                myHashId = ""
                for key in entry:
                    if (key == "hash_digest"):
                        outputFile.write(
                            str("<td><a href='https://gamesdb.gog.com/platforms/test/external_releases/"
                                + str(entry[key]) + "'>" + str(entry[key]) +
                                "</td>"))
                        myHashId = entry[key]
                    outputFile.write(str("<td>" + str(entry[key]) + "</td>"))
                outputFile.write(str("<td>"))
                if (myHashId != ""):
                    #logger.info(myHashId)
                    myCommand = await get_exe_command(myHashId, data_read)
                    #logger.info(myCommand)
                    outputFile.write(str(myCommand)[1:-1])
                outputFile.write(str("</td>"))
                outputFile.write(str("</tr>"))
            outputFile.write(
                str("</tbody>\n\
            </table>\n\
            <h2 id='start'>Press a button on your controller to show</h2>\n\
            <script type='text/javascript'>\n\
              $(document).ready( \n\
                function () {\n\
                  var myDataTable =  $('#mytable').DataTable(\n\
                    {\n\
                      select: {style: 'single'},\n\
                      columnDefs: [\n\
                        {visible: false, targets: [11] }\n\
                       ]\n\
                    }\n\
                  );\n\
                }\n\
              );\n\
            </script>\n\
            <script type='text/javascript'>\n\
            $.fn.dataTable.Api.register('row().next()', function() {\n\
                // Current row position\n\
                var nrp = this.table().rows()[0].indexOf( this.index() ) + 1;\n\
                // Exists ?\n\
                if( nrp < 0 ) {\n\
                    return null;\n\
                }\n\
                // Next row index by position\n\
                var nri = this.table().rows()[0][ nrp ];\n\
                // Return next row by its index\n\
                return this.table().row( nri );\n\
            });\n\
            $.fn.dataTable.Api.register('row().prev()', function() {\n\
                // Next row position\n\
                var prp = this.table().rows()[0].indexOf( this.index() ) - 1;\n\
                // Exists ?\n\
                if( prp < 0 ) {\n\
                    return null;\n\
                }\n\
                // Previous row index by position\n\
                var pri = ( this.table().rows()[0][ prp ] );\n\
                // Return previous row by its index\n\
                return this.table().row( pri );\n\
            });\n\
            \
            </script>\n\
            <script type='text/javascript'>\n\
                var haveEvents = 'GamepadEvent' in window;\n\
                var haveWebkitEvents = 'WebKitGamepadEvent' in window;\n\
                var controllers = {};\n\
                var prevTimestamps = [];\n\
                var rAF = window.mozRequestAnimationFrame ||\n\
                  window.webkitRequestAnimationFrame ||\n\
                  window.requestAnimationFrame;\n\
                \n\
                function connecthandler(e) {\n\
                  addgamepad(e.gamepad);\n\
                }\n\
                function addgamepad(gamepad) {\n\
                  controllers[gamepad.index] = gamepad;\n\
                  var d = document.createElement('div');\n\
                  d.setAttribute('id', 'controller' + gamepad.index);\n\
                  var t = document.createElement('h1');\n\
                  t.appendChild(document.createTextNode('gamepad: ' + gamepad.id));\n\
                  d.appendChild(t);\n\
                  var b = document.createElement('div');\n\
                  b.className = 'buttons';\n\
                  for (var i=0; i<gamepad.buttons.length; i++) {\n\
                    var e = document.createElement('span');\n\
                    e.className = 'button';\n\
                    //e.id = 'b' + i;\n\
                    e.innerHTML = i;\n\
                    b.appendChild(e);\n\
                  }\n\
                  d.appendChild(b);\n\
                  var a = document.createElement('div');\n\
                  a.className = 'axes';\n\
                  for (i=0; i<gamepad.axes.length; i++) {\n\
                    e = document.createElement('meter');\n\
                    e.className = 'axis';\n\
                    //e.id = 'a' + i;\n\
                    e.setAttribute('min', '-1');\n\
                    e.setAttribute('max', '1');\n\
                    e.setAttribute('value', '0');\n\
                    e.innerHTML = i;\n\
                    a.appendChild(e);\n\
                  }\n\
                  d.appendChild(a);\n\
                  document.getElementById('start').style.display = 'none';\n\
                  document.body.appendChild(d);\n\
                  rAF(updateStatus);\n\
                }\n\
                \n\
                function disconnecthandler(e) {\n\
                  removegamepad(e.gamepad);\n\
                }\n\
                \n\
                function removegamepad(gamepad) {\n\
                  var d = document.getElementById('controller' + gamepad.index);\n\
                  document.body.removeChild(d);\n\
                  delete controllers[gamepad.index];\n\
                }\n\
                \n\
                function updateStatus() {\n\
                \
                  scangamepads();\n\
                  for (j in controllers) {\n\
                    var controller = controllers[j];\n\
                    var d = document.getElementById('controller' + j);\n\
                    var buttons = d.getElementsByClassName('button');\n\
                    for (var i=0; i<controller.buttons.length; i++) {\n\
                      var b = buttons[i];\n\
                      var val = controller.buttons[i];\n\
                      var pressed = val == 1.0;\n\
                      var touched = false;\n\
                      if (typeof(val) == 'object') {\n\
                        pressed = val.pressed;\n\
                        if ('touched' in val) {\n\
                          touched = val.touched;\n\
                        }\n\
                        val = val.value;\n\
                      }\n\
                      var pct = Math.round(val * 100) + '%';\n\
                      b.style.backgroundSize = pct + ' ' + pct;\n\
                      b.className = 'button';\n\
                      if (pressed) {\n\
                        b.className += ' pressed';\n\
                      }\n\
                      if (touched) {\n\
                        b.className += ' touched';\n\
                      }\n\
                    }\n\
                \n\
                    var axes = d.getElementsByClassName('axis');\n\
                    for (var i=0; i<controller.axes.length; i++) {\n\
                      var a = axes[i];\n\
                      a.innerHTML = i + ': ' + controller.axes[i].toFixed(4);\n\
                      a.setAttribute('value', controller.axes[i]);\n\
                    }\n\
                  }\n\
                  rAF(updateStatus);\n\
                }\n\
                \n\
                function scangamepads() {\n\
                  var gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);\n\
                  for (var i = 0; i < gamepads.length; i++) {\n\
                    if (gamepads[i] && (gamepads[i].index in controllers)) {\n\
                      controllers[gamepads[i].index] = gamepads[i];\n\
                    }\n\
                  }\n\
                  if (gamepads[0]){\n\
                      if(!( gamepads[0].timestamp && \n\
                          (gamepads[0].timestamp === prevTimestamps[i]))) {\n\
                            prevTimestamps[0] = gamepads[0].timestamp;\n\
                            myTableUpdatesFunction();\n\
                      }\n\
                  }\n\
                }\n\
                \n\
                var myStartTime = Date.now();\n\
                if (haveEvents) {\n\
                  window.addEventListener('gamepadconnected', connecthandler);\n\
                  window.addEventListener('gamepaddisconnected', disconnecthandler);\n\
                } else if (haveWebkitEvents) {\n\
                  window.addEventListener('webkitgamepadconnected', connecthandler);\n\
                  window.addEventListener('webkitgamepaddisconnected', disconnecthandler);\n\
                } else {\n\
                  setInterval(scangamepads, 500);\n\
                }\n\
                </script>\n\
            </body>\n\
            </html>"))
Ejemplo n.º 12
0
 async def test_no_updates_send(self):
     self.configuration = DefaultConfig()
     self.backend = Backend()
     await self.backend.setup(self.configuration)
     self.backend.my_handshook = True
     await send_events(self)