1
0
Fork 0
forked from github/pelican

Merge pull request #2758 from MinchinWeb/settings-pathlib-2

This commit is contained in:
Justin Mayer 2023-10-28 21:56:34 +02:00 committed by GitHub
commit e14f20bb99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 44 deletions

View file

@ -3,6 +3,7 @@ import fnmatch
import locale
import logging
import os
import pathlib
import re
import shutil
import sys
@ -942,17 +943,28 @@ def split_all(path):
>>> split_all(os.path.join('a', 'b', 'c'))
['a', 'b', 'c']
"""
components = []
path = path.lstrip('/')
while path:
head, tail = os.path.split(path)
if tail:
components.insert(0, tail)
elif head == path:
components.insert(0, head)
break
path = head
return components
if isinstance(path, str):
components = []
path = path.lstrip('/')
while path:
head, tail = os.path.split(path)
if tail:
components.insert(0, tail)
elif head == path:
components.insert(0, head)
break
path = head
return components
elif isinstance(path, pathlib.Path):
return path.parts
elif path is None:
return None
else:
raise TypeError(
'"path" was {}, must be string, None, or pathlib.Path'.format(
type(path)
)
)
def is_selected_for_writing(settings, path):