Commit 81485924 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Make all paths correctly relative

parent d24edca7
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -5,19 +5,21 @@ from importlib import import_module

class Loader(object):

	def __init__(self, project_root):
	def __init__(self, project_root, target_path):
		self.project_root = path.normpath(project_root)
		self.rules = None

	@classmethod
	def at_path(cls, dirpath):
	def at_path(cls, target_path, _project_path=None):
		""" Recursively search upwards for a project root of a class's VCS. """
		if cls.is_project_root(dirpath):
			return cls(dirpath)
		if path.ismount(dirpath):
		if _project_path is None:
			_project_path = target_path
		if cls.is_project_root(_project_path):
			return cls(_project_path, path.relpath(target_path, _project_path))
		if path.ismount(_project_path):
			# Search no further if at the edge of a mounted file-system
			return None
		return cls.at_path(path.join(dirpath, '..'))
		return cls.at_path(target_path, path.join(_project_path, '..'))

	@classmethod
	def is_project_root(cls, path):
+5 −2
Original line number Diff line number Diff line
@@ -10,12 +10,15 @@ GITIGNORE_FILE = '.gitignore'

class GitLoader(loaders.Loader):

	def __init__(self, project_root):
		super(GitLoader, self).__init__(project_root)
	def __init__(self, project_root, target_path):
		super(GitLoader, self).__init__(project_root, target_path)
		pattern = patterns.ExactPattern('.git')
		self.rules = rules.Rule(project_root, '', pattern, with_path=False)
		self.tails = [self.rules, None]

		while target_path:
			target_path = path.dirname(target_path)
			self.load_from_dir(target_path)

	@classmethod
	def is_project_root(cls, dirpath):
+10 −2
Original line number Diff line number Diff line
import errno
from warnings import warn
from os import walk, path

@@ -5,6 +6,9 @@ from . import loaders, rules


def walk_files(start):
	if not path.isdir(start):
		raise OSError(errno.ENOTDIR, "Not a directory: {0}".format(start))

	loader = loaders.load_project_at(start)
	if loader is None:
		warn("No suitable CVS loaders found", RuntimeWarning)
@@ -12,7 +16,11 @@ def walk_files(start):
	else:
		top = loader.project_root

	for walkpath, dirnames, filenames in walk(top):
	if not rules.run_rules(loader.rules, path.relpath(start, top)):
		# The target directory is excluded!
		return

	for walkpath, dirnames, filenames in walk(start):
		relpath = path.relpath(walkpath, top)
		relpath = '' if relpath == '.' else relpath
		if loader:
@@ -24,4 +32,4 @@ def walk_files(start):
		for filename in filenames:
			filepath = path.join(relpath, filename)
			if loader is None or rules.run_rules(loader.rules, filepath):
				yield filepath
				yield path.relpath(path.join(top, filepath))