def test_dir_node_iter(self): nodes = [ DirNode('docs'), DirNode('tests'), FileNode('bar'), FileNode('foo'), FileNode('readme.txt'), FileNode('setup.py'), ] dirnode = DirNode('', nodes=nodes) for node in dirnode: assert node == dirnode.get_node(node.path)
def test_dir_node_iter(self): nodes = [ DirNode('docs'), DirNode('tests'), FileNode('bar'), FileNode('foo'), FileNode('readme.txt'), FileNode('setup.py'), ] dirnode = DirNode('', nodes=nodes) for node in dirnode: node == dirnode.get_node(node.path)
def get_nodes(self, path): """ Returns combined ``DirNode`` and ``FileNode`` objects list representing state of changeset at the given ``path``. If node at the given ``path`` is not instance of ``DirNode``, ChangesetError would be raised. """ if self._get_kind(path) != NodeKind.DIR: raise ChangesetError("Directory does not exist for revision %r at " " %r" % (self.revision, path)) path = self._fix_path(path) filenodes = [FileNode(f, changeset=self) for f in self._file_paths if os.path.dirname(f) == path] dirs = path == '' and '' or [d for d in self._dir_paths if d and posixpath.dirname(d) == path] dirnodes = [DirNode(d, changeset=self) for d in dirs if os.path.dirname(d) == path] als = self.repository.alias for k, vals in self._extract_submodules().iteritems(): #vals = url,rev,type loc = vals[0] cs = vals[1] dirnodes.append(SubModuleNode(k, url=loc, changeset=cs, alias=als)) nodes = dirnodes + filenodes # cache nodes for node in nodes: self.nodes[node.path] = node nodes.sort() return nodes
def get_node(self, path): if isinstance(path, unicode): path = path.encode('utf-8') path = self._fix_path(path) if path not in self.nodes: try: id_, type_ = self._get_id_for_path(path) except CommitError: raise NodeDoesNotExistError( "Cannot find one of parents' directories for a given " "path: %s" % path) if type_ == 'link': url = self._get_submodule_url(path) node = SubModuleNode(path, url=url, commit=id_, alias=self.repository.alias) elif type_ == 'tree': if path == '': node = RootNode(commit=self) else: node = DirNode(path, commit=self) elif type_ == 'blob': node = FileNode(path, commit=self) else: raise self.no_node_at_path(path) # cache node self.nodes[path] = node return self.nodes[path]
def test_is_dir(self): node = Node('any_dir', NodeKind.DIR) self.assertTrue(node.is_dir()) node = DirNode('any_dir') self.assertTrue(node.is_dir()) self.assertRaises(NodeError, getattr, node, 'content')
def test_node_state(self): """ Without link to changeset nodes should raise NodeError. """ node = FileNode('anything') self.assertRaises(NodeError, getattr, node, 'state') node = DirNode('anything') self.assertRaises(NodeError, getattr, node, 'state')
def test_is_dir(self): node = Node('any_dir', NodeKind.DIR) assert node.is_dir() node = DirNode('any_dir') assert node.is_dir() with pytest.raises(NodeError): node.content
def test_node_state(self): """ Without link to commit nodes should raise NodeError. """ node = FileNode('anything') with pytest.raises(NodeError): node.state node = DirNode('anything') with pytest.raises(NodeError): node.state
def get_node(self, path): """ Returns `Node` object from the given `path`. If there is no node at the given `path`, `NodeDoesNotExistError` would be raised. """ path = self._fix_path(path) if path not in self.nodes: if path in self._file_paths: node = FileNode(path, commit=self) elif path in self._dir_paths: if path == '': node = RootNode(commit=self) else: node = DirNode(path, commit=self) else: raise self.no_node_at_path(path) # cache node self.nodes[path] = node return self.nodes[path]
def get_nodes(self, path): if self._get_kind(path) != NodeKind.DIR: raise CommitError("Directory does not exist for commit %s at " " '%s'" % (self.raw_id, path)) path = self._fix_path(path) id_, _ = self._get_id_for_path(path) tree_id = self._remote[id_]['id'] dirnodes = [] filenodes = [] alias = self.repository.alias for name, stat_, id_, type_ in self._remote.tree_items(tree_id): if type_ == 'link': url = self._get_submodule_url('/'.join((path, name))) dirnodes.append( SubModuleNode(name, url=url, commit=id_, alias=alias)) continue if path != '': obj_path = '/'.join((path, name)) else: obj_path = name if obj_path not in self._stat_modes: self._stat_modes[obj_path] = stat_ if type_ == 'tree': dirnodes.append(DirNode(obj_path, commit=self)) elif type_ == 'blob': filenodes.append(FileNode(obj_path, commit=self, mode=stat_)) else: raise CommitError( "Requested object should be Tree or Blob, is %s", type_) nodes = dirnodes + filenodes for node in nodes: if node.path not in self.nodes: self.nodes[node.path] = node nodes.sort() return nodes
def get_node(self, path): if isinstance(path, unicode): path = path.encode('utf-8') path = self._fix_path(path) if not path in self.nodes: try: id_ = self._get_id_for_path(path) except ChangesetError: raise NodeDoesNotExistError( "Cannot find one of parents' " "directories for a given path: %s" % path) _GL = lambda m: m and objects.S_ISGITLINK(m) if _GL(self._stat_modes.get(path)): node = SubModuleNode(path, url=None, changeset=id_, alias=self.repository.alias) else: obj = self.repository._repo.get_object(id_) if isinstance(obj, objects.Tree): if path == '': node = RootNode(changeset=self) else: node = DirNode(path, changeset=self) node._tree = obj elif isinstance(obj, objects.Blob): node = FileNode(path, changeset=self) node._blob = obj else: raise NodeDoesNotExistError( "There is no file nor directory " "at the given path '%s' at revision %s" % (path, self.short_id)) # cache node self.nodes[path] = node return self.nodes[path]
def get_node(self, path): """ Returns ``Node`` object from the given ``path``. If there is no node at the given ``path``, ``ChangesetError`` would be raised. """ path = self._fix_path(path) if not path in self.nodes: if path in self._file_paths: node = FileNode(path, changeset=self) elif path in self._dir_paths or path in self._dir_paths: if path == '': node = RootNode(changeset=self) else: node = DirNode(path, changeset=self) else: raise NodeDoesNotExistError("There is no file nor directory " "at the given path: %r at revision %r" % (path, self.short_id)) # cache node self.nodes[path] = node return self.nodes[path]
def get_nodes(self, path): """ Returns combined ``DirNode`` and ``FileNode`` objects list representing state of commit at the given ``path``. If node at the given ``path`` is not instance of ``DirNode``, CommitError would be raised. """ if self._get_kind(path) != NodeKind.DIR: raise CommitError("Directory does not exist for idx %s at '%s'" % (self.idx, path)) path = self._fix_path(path) filenodes = [ FileNode(f, commit=self) for f in self._file_paths if os.path.dirname(f) == path ] # TODO: johbo: Check if this can be done in a more obvious way dirs = path == '' and '' or [ d for d in self._dir_paths if d and vcspath.dirname(d) == path ] dirnodes = [ DirNode(d, commit=self) for d in dirs if os.path.dirname(d) == path ] alias = self.repository.alias for k, vals in self._submodules.iteritems(): loc = vals[0] commit = vals[1] dirnodes.append( SubModuleNode(k, url=loc, commit=commit, alias=alias)) nodes = dirnodes + filenodes # cache nodes for node in nodes: self.nodes[node.path] = node nodes.sort() return nodes
def get_nodes(self, path): if self._get_kind(path) != NodeKind.DIR: raise ChangesetError("Directory does not exist for revision %r at " " %r" % (self.revision, path)) path = self._fix_path(path) id = self._get_id_for_path(path) tree = self.repository._repo[id] dirnodes = [] filenodes = [] als = self.repository.alias for name, stat, id in tree.iteritems(): if objects.S_ISGITLINK(stat): dirnodes.append( SubModuleNode(name, url=None, changeset=id, alias=als)) continue obj = self.repository._repo.get_object(id) if path != '': obj_path = '/'.join((path, name)) else: obj_path = name if obj_path not in self._stat_modes: self._stat_modes[obj_path] = stat if isinstance(obj, objects.Tree): dirnodes.append(DirNode(obj_path, changeset=self)) elif isinstance(obj, objects.Blob): filenodes.append(FileNode(obj_path, changeset=self, mode=stat)) else: raise ChangesetError("Requested object should be Tree " "or Blob, is %r" % type(obj)) nodes = dirnodes + filenodes for node in nodes: if not node.path in self.nodes: self.nodes[node.path] = node nodes.sort() return nodes