def _get_win_favorites(): """Returns a list of paths for commonly used directories. e.g. My Music, Desktop etc. """ assert os.name == "nt" folders = [] funcs = [windows.get_desktop_dir, windows.get_personal_dir, windows.get_music_dir] for func in funcs: path = func() if path is not None: folders.append(path) # try to extract the favorites listed in explorer and add them # if not already present links = windows.get_links_dir() if links is not None: for entry in os.listdir(links): if entry.endswith(".lnk"): target = windows.get_link_target(os.path.join(links, entry)) if target is not None: folders.append(target) # remove duplicated entries filtered = [] for path in folders: if path not in filtered: filtered.append(path) return filtered
def test_get_link_target_unicode(self): path = os.path.join(DATA_DIR, "test2.lnk") d = windows.get_link_target(path) self.assertTrue(isinstance(d, unicode)) if is_wine(): # wine doesn't support unicode paths here.. self.assertEqual(os.path.basename(d), u"\xe1??.txt") else: self.assertEqual(os.path.basename(d), u"\xe1\U00016826.txt")
def test_get_link_target_non_exist(self): with self.assertRaises(WindowsError): windows.get_link_target(u"nopenope.lnk")
def test_get_link_target(self): path = os.path.join(DATA_DIR, "test.lnk") d = windows.get_link_target(path) self.assertTrue(isinstance(d, unicode)) self.assertEqual( normalize_path(d), normalize_path(u"C:\Windows\explorer.exe"))
def test_get_link_target(self): path = os.path.join(DATA_DIR, "test.lnk") d = windows.get_link_target(path) self.assertTrue(isinstance(d, unicode)) self.assertEqual(normalize_path(d), normalize_path(u"C:\Windows\explorer.exe"))
def test_get_link_target_latin1(self): path = os.path.join(DATA_DIR, "test2.lnk") d = windows.get_link_target(path) # the second char is only not in latin-1 self.assertEqual(os.path.basename(d), u"\xe1??.txt") self.assertTrue(isinstance(d, unicode))