def resolve_paths(self, src_root_dir="."): variables = copy.copy(self._path_variables) variables.update(self._variables) variables["_srcrootdir"] = src_root_dir destdir = subst_vars("$destdir", variables) file_sections = {} for category in self.files: file_sections[category] = {} for name, section in self.files[category].items(): srcdir = subst_vars(section.source_dir, variables) target = subst_vars(section.target_dir, variables) if target: tail = explode_path(target)[1:] if not tail: raise ValueError( "Invalid target directory in section %r (not absolute: %r)" % (name, section.target_dir) ) else: raise ValueError("Invalid target directory in section %r: %r" % (name, section.target_dir)) target = os.path.join(destdir, os.path.join(*tail)) file_sections[category][name] = [ (os.path.join(srcdir, f), os.path.join(target, g)) for f, g in section.files ] return file_sections
def _prefix_destdir(path): destdir = subst_vars("$destdir", variables) if path: tail = explode_path(path)[1:] if not tail: raise ValueError("Invalid target directory in section %r " "(not absolute: %r)" % (name, path)) return os.path.join(destdir, os.path.join(*tail)) else: raise ValueError("Invalid target directory in section " "%r: %r" % (name, path))
def test_empty(self): path = "" self.assertEqual(explode_path(path), [])
def test_ends_with_sep(self): path = "/home/joe/" self.assertEqual(explode_path(path), ["/", "home", "joe"])
def test_simple(self): path = "/home/joe" self.assertEqual(explode_path(path), ["/", "home", "joe"]) path = "home/joe" self.assertEqual(explode_path(path), ["home", "joe"])
def test_empty(self): path = "" assert_equal(explode_path(path), [])