def test_splitpath(self): alltests = { False: { '/usr/bin/smewt': ['/', 'usr', 'bin', 'smewt'], 'relative_path/to/my_folder/': ['relative_path', 'to', 'my_folder'], '//some/path': ['//', 'some', 'path'], '//some//path': ['//', 'some', 'path'], '///some////path': ['///', 'some', 'path'] }, True: { 'C:\\Program Files\\Smewt\\smewt.exe': ['C:\\', 'Program Files', 'Smewt', 'smewt.exe'], 'Documents and Settings\\User\\config': ['Documents and Settings', 'User', 'config'], 'C:\\Documents and Settings\\User\\config': ['C:\\', 'Documents and Settings', 'User', 'config'], # http://bugs.python.org/issue19945 '\\\\netdrive\\share': ['\\\\', 'netdrive', 'share'] if PY2 else ['\\\\netdrive\\share'], '\\\\netdrive\\share\\folder': ['\\\\', 'netdrive', 'share', 'folder'] if PY2 else ['\\\\netdrive\\share\\', 'folder'], } } tests = alltests[sys.platform == 'win32'] for path, split in tests.items(): self.assertEqual(split, split_path(path))
def process(mtree): """Returns the filename split into [ dir*, basename, ext ].""" components = fileutils.split_path(mtree.value) basename = components.pop(-1) components += list(os.path.splitext(basename)) components[-1] = components[-1][1:] # remove the '.' from the extension mtree.split_on_components(components)
def commonRoot(pathlist): if not pathlist: return [] root = split_path(pathlist[0]) for path in pathlist[1:]: for i, dir in enumerate(split_path(path)): try: if root[i] != dir: root = root[:i] break except IndexError: break else: root = root[:len(split_path(path))] return os.path.join(*root)
def process(self, mtree, options=None): """first split our path into dirs + basename + ext :return: the filename split into [ dir*, basename, ext ] """ if not options.get('name_only'): components = fileutils.split_path(mtree.value) basename = components.pop(-1) components += list(splitext(basename)) components[-1] = components[-1][1:] # remove the '.' from the extension mtree.split_on_components(components, category='path') else: mtree.split_on_components([mtree.value, ''], category='path')
def process(self, mtree, options=None): """first split our path into dirs + basename + ext :return: the filename split into [ dir*, basename, ext ] """ if not options.get('name_only'): components = fileutils.split_path(mtree.value) basename = components.pop(-1) components += list(splitext(basename)) components[-1] = components[-1][ 1:] # remove the '.' from the extension mtree.split_on_components(components) else: mtree.split_on_components([mtree.value, ''])
def test_splitpath(self): alltests = { ('linux2', 'darwin'): { '/usr/bin/smewt': ['/', 'usr', 'bin', 'smewt'], 'relative_path/to/my_folder/': ['relative_path', 'to', 'my_folder'] }, ('win32',): { r'C:\Program Files\Smewt\smewt.exe': ['C:\\', 'Program Files', 'Smewt', 'smewt.exe'], r'Documents and Settings\User\config\\': ['Documents and Settings', 'User', 'config'], r'C:\Documents and Settings\User\config\\': ['C:\\', 'Documents and Settings', 'User', 'config'], r'\\netdrive\share': [r'\\', 'netdrive', 'share'], r'\\netdrive\share\folder': [r'\\', 'netdrive', 'share', 'folder'] } } for platforms, tests in alltests.items(): if sys.platform in platforms: for path, split in tests.items(): self.assertEqual(split, split_path(path))
def test_splitpath(self): alltests = { ('linux2', 'darwin'): { '/usr/bin/smewt': ['/', 'usr', 'bin', 'smewt'], 'relative_path/to/my_folder/': ['relative_path', 'to', 'my_folder'], '//some/path': ['/', 'some', 'path'], '//some//path': ['/', 'some', 'path'], '///some////path': ['/', 'some', 'path'] }, ('win32',): { r'C:\Program Files\Smewt\smewt.exe': ['C:\\', 'Program Files', 'Smewt', 'smewt.exe'], r'Documents and Settings\User\config\\': ['Documents and Settings', 'User', 'config'], r'C:\Documents and Settings\User\config\\': ['C:\\', 'Documents and Settings', 'User', 'config'], r'\\netdrive\share': [r'\\', 'netdrive', 'share'], r'\\netdrive\share\folder': [r'\\', 'netdrive', 'share', 'folder'] } } for platforms, tests in alltests.items(): if sys.platform in platforms: for path, split in tests.items(): self.assertEqual(split, split_path(path))
def test_splitpath(self): alltests = {False: {'/usr/bin/smewt': ['/', 'usr', 'bin', 'smewt'], 'relative_path/to/my_folder/': ['relative_path', 'to', 'my_folder'], '//some/path': ['//', 'some', 'path'], '//some//path': ['//', 'some', 'path'], '///some////path': ['///', 'some', 'path'] }, True: {'C:\\Program Files\\Smewt\\smewt.exe': ['C:\\', 'Program Files', 'Smewt', 'smewt.exe'], 'Documents and Settings\\User\\config': ['Documents and Settings', 'User', 'config'], 'C:\\Documents and Settings\\User\\config': ['C:\\', 'Documents and Settings', 'User', 'config'], # http://bugs.python.org/issue19945 '\\\\netdrive\\share': ['\\\\', 'netdrive', 'share'] if PY2 else ['\\\\netdrive\\share'], '\\\\netdrive\\share\\folder': ['\\\\', 'netdrive', 'share', 'folder'] if PY2 else ['\\\\netdrive\\share\\', 'folder'], } } tests = alltests[sys.platform == 'win32'] for path, split in tests.items(): self.assertEqual(split, split_path(path))
def parentDirectory(path): parentDir = split_path(path)[:-1] return os.path.join(*parentDir)
def expandPathNode(self, fullpath): spath = split_path(fullpath) for i in range(len(spath)): self.tree.expand(self.model.index(os.path.join(*spath[:i+1])))