mirror of
https://github.com/thegeeklab/ansible-later.git
synced 2024-11-26 23:00:36 +00:00
36 lines
893 B
Python
36 lines
893 B
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# Copyright (c) Simula Research Laboratory.
|
|
# Distributed under the terms of the Modified BSD License.
|
|
|
|
"""Path manipulation utilities."""
|
|
|
|
import os
|
|
|
|
SEPARATORS = os.sep if os.altsep is None else os.sep + os.altsep
|
|
|
|
|
|
# FIXME: For our purposes, these should avoid splitting in the middle of [] parts
|
|
|
|
def iexplode_path(path):
|
|
"""Iterate over all the parts of a path.
|
|
|
|
Splits path recursively with os.path.split().
|
|
"""
|
|
(head, tail) = os.path.split(path)
|
|
if not head or (not tail and head == path):
|
|
if head:
|
|
yield head
|
|
if tail or not head:
|
|
yield tail
|
|
return
|
|
for p in explode_path(head):
|
|
yield p
|
|
yield tail
|
|
|
|
|
|
def explode_path(path):
|
|
"""Splits path recursively into pieces with os.path.split()"""
|
|
return tuple(iexplode_path(path))
|