Ejemplo n.º 1
0
 def on_close(self):
     super(WSConnectionHandler, self).on_close()
     if self._connected_client.ID.lower() == "bitbloq":
         log.info("Bitbloq disconnected, closing web2board...")
         time.sleep(0.5)
         if utils.are_we_frozen():
             libs.MainApp.force_quit()
Ejemplo n.º 2
0
    def set_all_constants(cls):
        cls.EXECUTABLE_PATH = os.getcwd()
        cls.EXECUTABLE_FILE = join(cls.EXECUTABLE_PATH, "web2board" + utils.get_executable_extension())
        cls.MAIN_PATH = cls.get_main_path()
        cls.CONFIG_PATH = os.path.normpath(join(cls.MAIN_PATH, os.pardir, '.web2board-config.json'))
        cls.COPY_PATH = cls.get_copy_path_for_update()

        cls.RES_PATH = join(cls.MAIN_PATH, 'res')
        cls.VERSION_PATH = join(cls.RES_PATH, 'web2board.version')
        cls.RES_ICO_PATH = join(cls.RES_PATH, 'Web2board.ico')
        cls.RES_ICONS_PATH = join(cls.RES_PATH, 'icons')
        cls.TEST_RES_PATH = join(cls.MAIN_PATH, 'Test', 'resources')
        cls.RES_BOARDS_PATH = join(cls.RES_PATH, 'boards.txt')
        cls.RES_PLATFORMIO_PATH = os.path.abspath(join(cls.RES_PATH, os.pardir, 'platformio'))
        cls.RES_LOGGING_CONFIG_PATH = join(cls.RES_PATH, 'logging.json')
        cls.RES_SCONS_ZIP_PATH = join(cls.MAIN_PATH, "res", "sconsRes.zip")

        if utils.are_we_frozen():
            cls.PROGRAM_PATH = cls.MAIN_PATH
        else:
            cls.PROGRAM_PATH = cls.get_external_data_folder()
        cls.PLATFORMIO_WORKSPACE_SKELETON = join(cls.RES_PATH, 'platformioWorkSpace')
        cls.PLATFORMIO_WORKSPACE_PATH = cls.PLATFORMIO_WORKSPACE_SKELETON
        cls.PLATFORMIO_INI_PATH = join(cls.PLATFORMIO_WORKSPACE_SKELETON, 'platformio.ini')
        cls.TEST_SETTINGS_PATH = join(cls.RES_PATH, 'TestSettings', 'resources')
        cls.SCONS_EXECUTABLE_PATH = cls.get_sons_executable_path()

        cls.PLATFORMIO_PACKAGES_PATH = cls.get_platformio_packages_path()
Ejemplo n.º 3
0
 def get_base_path():
     if utils.are_we_frozen():
         if utils.is_mac():
             return os.getcwd()
         return os.getcwd()
     else:
         return os.getcwd()
Ejemplo n.º 4
0
 def on_close(self):
     super(WSConnectionHandler, self).on_close()
     if self._connected_client.ID.lower() == "bitbloq":
         log.info("Bitbloq disconnected, closing web2board...")
         time.sleep(0.5)
         if utils.are_we_frozen():
             libs.MainApp.force_quit()
Ejemplo n.º 5
0
 def __construct_api_files():
     if not utils.are_we_frozen():
         HubsInspector.construct_js_file(path=os.path.join(
             "libs", "WSCommunication", "Clients", "hubsApi.js"))
         HubsInspector.construct_js_file(
             path=os.path.join(os.pardir, "demo", "_static", "hubsApi.js"))
         HubsInspector.construct_python_file(path=os.path.join(
             "libs", "WSCommunication", "Clients", "hubs_api.py"))
Ejemplo n.º 6
0
 def __construct_api_files():
     if not utils.are_we_frozen():
         HubsInspector.construct_js_file(path=os.path.join("libs", "WSCommunication", "Clients", "hubsApi.js"))
         HubsInspector.construct_js_file(path=os.path.join(os.pardir, "demo", "_static", "hubsApi.js"))
         HubsInspector.construct_python_file(path=os.path.join("libs", "WSCommunication", "Clients", "hubs_api.py"))
Ejemplo n.º 7
0
        if utils.are_we_frozen():
            cls.PROGRAM_PATH = cls.MAIN_PATH
        else:
            cls.PROGRAM_PATH = cls.get_external_data_folder()
        cls.PLATFORMIO_WORKSPACE_SKELETON = join(cls.RES_PATH, 'platformioWorkSpace')
        cls.PLATFORMIO_WORKSPACE_PATH = cls.PLATFORMIO_WORKSPACE_SKELETON
        cls.PLATFORMIO_INI_PATH = join(cls.PLATFORMIO_WORKSPACE_SKELETON, 'platformio.ini')
        cls.TEST_SETTINGS_PATH = join(cls.RES_PATH, 'TestSettings', 'resources')
        cls.SCONS_EXECUTABLE_PATH = cls.get_sons_executable_path()

        cls.PLATFORMIO_PACKAGES_PATH = cls.get_platformio_packages_path()

    @classmethod
    def get_icon_path(cls, iconName):
        return join(PathsManager.RES_ICONS_PATH, iconName)

    @classmethod
    def clean_pio_envs(cls):
        path = join(cls.PLATFORMIO_WORKSPACE_PATH, ".pioenvs")
        if os.path.exists(path):
            shutil.rmtree(path)

# set working directory to src
if utils.are_we_frozen():
    os.chdir(utils.get_module_path())
else:
    os.chdir(join(utils.get_module_path(), os.path.pardir))


PathsManager.set_all_constants()
Ejemplo n.º 8
0
class TestUtils(unittest.TestCase):
    def setUp(self):
        self.my_test_folder = os.path.join(PathsManager.TEST_SETTINGS_PATH,
                                           "testUtils")
        self.copy_tree_old = os.path.join(self.my_test_folder, "copytree_old")
        self.copy_tree_new = os.path.join(self.my_test_folder, "copytree_new")
        self.zip_path = os.path.join(self.my_test_folder, "zip.zip")
        self.zip_folder = os.path.join(self.my_test_folder, "zip")

        self.original_list_ports_comports = serial.tools.list_ports.comports
        restore_test_resources()

    def tearDown(self):
        serial.tools.list_ports.comports = self.original_list_ports_comports

        if os.path.exists(self.copy_tree_new):
            shutil.rmtree(self.copy_tree_new)
        if os.path.exists(self.zip_folder):
            shutil.rmtree(self.zip_folder)

    @unittest.skipIf(utils.are_we_frozen(),
                     "module path returns exe path and can not be tested")
    def test_getModulePath_returnsThisModulePath(self):
        module_path = utils.get_module_path()

        self.assertIn(os.path.join("src", "Test"), module_path)

    @unittest.skipIf(utils.are_we_frozen(),
                     "module path returns exe path and can not be tested")
    def test_getModulePath_getsUnittestPathWithPreviousFrame(self):
        import inspect
        module_path = utils.get_module_path(inspect.currentframe().f_back)

        self.assertIn("unittest", module_path)

    def __assertCopyTreeNewHasAllFiles(self):
        self.assertTrue(os.path.exists(self.copy_tree_new))
        self.assertTrue(
            os.path.exists(self.copy_tree_new + os.path.sep + "01.txt"))
        self.assertTrue(
            os.path.exists(self.copy_tree_new + os.path.sep + "02.txt"))

    def test_copytree_createsNewFolderIfNotExists(self):
        utils.copytree(self.copy_tree_old, self.copy_tree_new)

        self.__assertCopyTreeNewHasAllFiles()

    def test_copytree_worksEvenWithExistingFolder(self):
        os.mkdir(self.copy_tree_new)

        utils.copytree(self.copy_tree_old, self.copy_tree_new)

        self.__assertCopyTreeNewHasAllFiles()

    def test_copytree_doNotOverwriteExistingFiles(self):
        os.mkdir(self.copy_tree_new)
        txt_file_path = self.copy_tree_new + os.path.sep + "01.txt"
        with open(txt_file_path, "w") as f:
            f.write("01")

        utils.copytree(self.copy_tree_old, self.copy_tree_new)
        with open(txt_file_path, "r") as f:
            file_data = f.read()

        self.__assertCopyTreeNewHasAllFiles()
        self.assertEqual(file_data, "01")

    def test_listDirectoriesInPath(self):
        print self.my_test_folder
        directories = utils.list_directories_in_path(self.my_test_folder)
        directories = map(lambda x: x.lower(), directories)
        self.assertEqual(set(directories), {"copytree_old", "otherdir"})

    def test_extractZip(self):
        utils.extract_zip(self.zip_path, self.my_test_folder)

        self.assertTrue(os.path.exists(self.zip_folder))
        self.assertTrue(os.path.exists(self.zip_folder + os.sep + "zip.txt"))

    def test_listSerialPorts_useSerialLib(self):
        ports = [(1, 2, 3), (4, 5, 6)]
        flexmock(serial.tools.list_ports).should_receive(
            "comports").and_return(ports).once()

        self.assertEqual(utils.list_serial_ports(), ports)

    def test_listSerialPorts_filterWithFunction(self):
        ports = [(1, 2, 3), (4, 5, 6)]
        flexmock(serial.tools.list_ports).should_receive(
            "comports").and_return(ports).once()

        self.assertEqual(utils.list_serial_ports(lambda x: x[0] == 1),
                         ports[0:1])
Ejemplo n.º 9
0
def move_paths_manager_to_internal_web2board_path():  # any better name will be appreciated ;)
    if utils.are_we_frozen():
        os.chdir(join(pm.MAIN_PATH, "web2board"))
        pm.set_all_constants()