示例#1
0
def build(cwd=None, root=None):
    """Build a tree from the current working directory or explicit root.

    @param cwd: current working directory
    @param root: path to root of the working copy

    @return: new Tree

    @raise DemoError: when the tree cannot be built

    """
    documents = []

    # Find the root of the working copy
    cwd = cwd or os.getcwd()
    root = root or vcs.find_root(cwd)

    # Find all documents in the working copy
    logging.info("looking for documents in {}...".format(root))
    _document_from_path(root, root, documents)
    for dirpath, dirnames, _ in os.walk(root):
        for dirname in dirnames:
            path = os.path.join(dirpath, dirname)
            _document_from_path(path, root, documents)

    # Build the tree
    if not documents:
        logging.info("no documents found in: {}".format(root))
    logging.info("building tree...")
    tree = Tree.from_list(documents, root=root)
    logging.info("built tree: {}".format(tree))
    return tree
示例#2
0
 def find(self):
     """Find the root of the project."""
     if not self.stringvar_project.get():
         try:
             path = vcs.find_root(self.cwd)
         except DemoError as exc:
             logging.error(exc)
         else:
             self.stringvar_project.set(path)
示例#3
0
 def test_find_root(self):
     """Verify a root VCS directory can be found."""
     path = vcs.find_root('fake/path')
     self.assertEqual('fake/path', path)