class DarwinTest(unittest.TestCase): if AbstractOSIntegration.is_mac() and not AbstractOSIntegration.os_version_below("10.10"): def test_folder_registration(self): name = "TestCazz" # Unregister first; to ensure favorite bar is cleaned. os = AbstractOSIntegration.get(None) os.unregister_folder_link(name) self.assertFalse(self._is_folder_registered(name)) os.register_folder_link(".", name) self.assertTrue(self._is_folder_registered(name)) os.unregister_folder_link(name) self.assertFalse(self._is_folder_registered(name)) assert 1 # Others test can be written here. # Utils methods def _is_folder_registered(self, name): os = AbstractOSIntegration.get(None) lst = os._get_favorite_list() return os._find_item_in_list(lst, name) is not None else: @unittest.skip('Skipped test suite on another system than OSX.') def test_darwin(self): assert 0
def get_local_client(self, path): if AbstractOSIntegration.is_mac() and ( self._testMethodName == 'test_local_delete_readonly_folder' or self._testMethodName == 'test_local_rename_readonly_folder'): return LocalClient(path) # Old mac dont handle case rename if AbstractOSIntegration.is_mac() and AbstractOSIntegration.os_version_below("10.10") and ( self._testMethodName == 'test_local_rename_file_uppercase_stopped' or self._testMethodName == 'test_local_rename_file_uppercase'): return LocalClient(path) return super(TestLocalMoveAndRename, self).get_local_client(path)
def _set_root_icon(self): local_client = self.get_local_client() if local_client.has_folder_icon('/'): return if AbstractOSIntegration.is_mac(): if AbstractOSIntegration.os_version_below("10.10"): icon = find_icon("NuxeoDrive_Mac_Folder.dat") else: icon = find_icon("NuxeoDrive_Mac_Yosemite_Folder.dat") elif AbstractOSIntegration.is_windows(): if AbstractOSIntegration.os_version_below("5.2"): icon = find_icon("NuxeoDrive_Windows_Xp_Folder.ico") else: icon = find_icon("NuxeoDrive_Windows_Folder.ico") else: # No implementation on Linux return locker = local_client.unlock_ref('/', unlock_parent=False) try: local_client.set_folder_icon('/', icon) finally: local_client.lock_ref('/', locker)
def get_local_client(self, path): if AbstractOSIntegration.is_mac() and ( self._testMethodName == 'test_local_delete_readonly_folder' or self._testMethodName == 'test_local_rename_readonly_folder'): return LocalClient(path) # Old mac dont handle case rename if AbstractOSIntegration.is_mac( ) and AbstractOSIntegration.os_version_below("10.10") and ( self._testMethodName == 'test_local_rename_file_uppercase_stopped' or self._testMethodName == 'test_local_rename_file_uppercase'): return LocalClient(path) return super(TestLocalMoveAndRename, self).get_local_client(path)
def set_folder_icon_win32(self, ref, icon): import win32con import win32api ''' Configure red color icon for a folder Windows / Mac ''' # Desktop.ini file content for Windows 7 and later. ini_file_content = """ [.ShellClassInfo] IconResource=icon_file_path,0 [ViewState] Mode= Vid= FolderType=Generic """ # Desktop.ini file content for Windows XP. ini_file_content_xp = """ [.ShellClassInfo] IconFile=icon_file_path IconIndex=0 """ if AbstractOSIntegration.os_version_below("5.2"): desktop_ini_content = ini_file_content_xp.replace( "icon_file_path", icon) else: desktop_ini_content = ini_file_content.replace( "icon_file_path", icon) # Create the desktop.ini file inside the ReadOnly shared folder. created_ini_file_path = os.path.join(self._abspath(ref), 'desktop.ini') attrib_command_path = self._abspath(ref) if not os.path.exists(created_ini_file_path): try: create_file = open(created_ini_file_path, 'w') create_file.write(desktop_ini_content) create_file.close() win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM) win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN) except Exception as e: log.error("Exception when setting folder icon : %r", e) else: win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM) win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN) # Windows folder use READ_ONLY flag as a customization flag ... # https://support.microsoft.com/en-us/kb/326549 win32api.SetFileAttributes(attrib_command_path, win32con.FILE_ATTRIBUTE_READONLY)
def set_folder_icon_win32(self, ref, icon): import win32con import win32api """ Configure red color icon for a folder Windows / Mac """ # Desktop.ini file content for Windows 7 and later. ini_file_content = """ [.ShellClassInfo] IconResource=icon_file_path,0 [ViewState] Mode= Vid= FolderType=Generic """ # Desktop.ini file content for Windows XP. ini_file_content_xp = """ [.ShellClassInfo] IconFile=icon_file_path IconIndex=0 """ if AbstractOSIntegration.os_version_below("5.2"): desktop_ini_content = ini_file_content_xp.replace("icon_file_path", icon) else: desktop_ini_content = ini_file_content.replace("icon_file_path", icon) # Create the desktop.ini file inside the ReadOnly shared folder. created_ini_file_path = os.path.join(self._abspath(ref), "desktop.ini") attrib_command_path = self._abspath(ref) if not os.path.exists(created_ini_file_path): try: create_file = open(created_ini_file_path, "w") create_file.write(desktop_ini_content) create_file.close() win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM) win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN) except Exception as e: log.error("Exception when setting folder icon : %r", e) else: win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_SYSTEM) win32api.SetFileAttributes(created_ini_file_path, win32con.FILE_ATTRIBUTE_HIDDEN) # Windows folder use READ_ONLY flag as a customization flag ... # https://support.microsoft.com/en-us/kb/326549 win32api.SetFileAttributes(attrib_command_path, win32con.FILE_ATTRIBUTE_READONLY)
def get_zoom_factor(self): try: if AbstractOSIntegration.os_version_below("6.0.6000"): # API added on Vista return 1.00 from ctypes import windll from win32con import LOGPIXELSX # Enable DPI detection windll.user32.SetProcessDPIAware() # Get Desktop DC hDC = windll.user32.GetDC(None) dpiX = windll.gdi32.GetDeviceCaps( hDC, LOGPIXELSX) windll.user32.ReleaseDC(None, hDC) # Based on https://technet.microsoft.com/en-us/library/dn528846.aspx return dpiX / 96.0 except Exception as e: log.debug("Can't get zoom factor: %r", e) return 1.00
def get_zoom_factor(self): try: if AbstractOSIntegration.os_version_below("6.0.6000"): # API added on Vista return 1.00 from ctypes import windll from win32con import LOGPIXELSX # Enable DPI detection windll.user32.SetProcessDPIAware() # Get Desktop DC hDC = windll.user32.GetDC(None) dpiX = windll.gdi32.GetDeviceCaps(hDC, LOGPIXELSX) windll.user32.ReleaseDC(None, hDC) # Based on https://technet.microsoft.com/en-us/library/dn528846.aspx return dpiX / 96.0 except Exception as e: log.debug("Can't get zoom factor: %r", e) return 1.00