def _relpath(self, path): try: global _main_cwd return relpath(_main_cwd, path) except: pass return path
def get_tree_files(file_list): """ Get a tree, and the file_ids from that tree, from the inputs. This returns the tree (a working tree or basis tree), a list of the file_ids belonging to that tree, and a list of remaining files (that presumably belong to another tree). """ file_id_list = [] try: (tree, rel_path) = workingtree.WorkingTree.open_containing(file_list[0]) branch1 = tree.branch base_path = osutils.normpath(tree.id2abspath(tree.get_root_id())) except errors.NoWorkingTree: (branch1, rel_path) = branch.Branch.open_containing(file_list[0]) tree = branch1.basis_tree() base_path = osutils.normpath(branch1.base) except errors.NotLocalUrl: (branch1, rel_path) = branch.Branch.open_containing(file_list[0]) tree = branch1.basis_tree() base_path = None tree.lock_read() try: i = 0 for file_name in file_list: try: if i > 0: if base_path: rpath = osutils.relpath(base_path, file_name) else: (branch2, rpath) = branch.Branch.open_containing(file_name) if branch2.base != branch1.base: raise errors.PathNotChild(file_name, branch1.base) else: rpath = rel_path file_id = tree.inventory.path2id(rpath) if file_id: file_id_list.append(file_id) else: if (not isinstance(transport.get_transport(file_name), transport.local.LocalTransport)): raise errors.PathNotChild(file_name, branch1.base) else: raise errors.NotVersionedError(file_name) i += 1 except errors.PathNotChild: break finally: tree.unlock() return (branch1, tree, file_id_list, file_list[i:len(file_list)])
def add_path(self, label, path): """Add a path, converting it to a relative path if possible""" try: path = osutils.relpath(self.base_path, path) except errors.PathNotChild: pass else: if path == '': path = '.' if path != '/': path = path.rstrip('/') self.locs.append((label, path))
def rp(p): return relpath(dtmp, p)
def friendly_location(url): path = urlutils.unescape_for_display(url, 'ascii') try: return osutils.relpath(osutils.getcwd(), path) except errors.PathNotChild: return path
def _relpath(self, path): try: return relpath(self.cwd, path) except: pass return path