path_rel :
def path_rel(target, base=os.curdir, check_presence=False):
‘'’ Return a relative path to the target from either the current dir or an optional base dir,
check_presence=True to check directiries presence ‘'’
if check_presence :
if not os.path.exists(target): raise OSError, ‘Target does not exist: ’ + target
if not os.path.isdir(base): raise OSError, ‘Base is not a directory or does not exist: ’ + base
if os.path.abspath(base) == os.path.abspath(target) : rel_list =
else :
base_list = (os.path.abspath(base)).split(os.sep)
target_list = (os.path.abspath(target)).split(os.sep)
# On the windows platform the target may be on a completely different drive from the base.
if os.name in and base_list <> target_list:
raise OSError, ‘Target is on a different drive to base. Target: ’ + target_list.upper() + ‘, base: ’ + base_list.upper()
# Starting from the filepath root, work out how much of the filepath is shared by base and target.
for i in range(min(len(base_list), len(target_list))) :
if base_list
<> target_list: break
else : i += 1 # If we broke out of the loop, i is pointing to the first differing path elements.
rel_list = * (len(base_list)-i) + target_list
return os.path.join(*rel_list)
То бишь, что в формате tar.bz2, что в tar.gz
с tar.gz были проблемы в 7zip или total commander