Skip to content

Commit

Permalink
provide fallback for os.path.relpath
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenney committed May 3, 2009
1 parent c96a942 commit 9e7507d
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions flashbake/plugins/scrivener.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,34 @@ def find_scrivener_projects(hot_files, config, flush_cache=False):

return config.scrivener_projects

def _relpath(path, start):
path = os.path.realpath(path)
start = os.path.realpath(start)
if not path.startswith(start):
raise Error("unable to calculate paths")
if os.path.samefile(path,start):
return "."

if not start.endswith(os.path.sep):
start += os.path.sep

return path[len(start):]


def find_scrivener_project_contents(hot_files, scrivener_project):
contents=list()
for path, dirs, files in os.walk(os.path.join(hot_files.project_dir,scrivener_project)):
relpath = os.path.relpath(path,hot_files.project_dir)
for path, dirs, files in os.walk(os.path.join(hot_files.project_dir,scrivener_project)):
if hasattr(os.path, "relpath"):
rpath = os.path.relpath(path,hot_files.project_dir)
else:
try:
import pathutils
rpath = pathutils.relative(path, hot_files.project_dir)
except:
rpath = _relpath(path, hot_files.project_dir)

for filename in files:
contents.append(os.path.join(relpath,filename))
contents.append(os.path.join(rpath,filename))

return contents

Expand Down

0 comments on commit 9e7507d

Please sign in to comment.