Exemple #1
0
def _run(args, cwd, err):  # pylint: disable=W0613
    """Process arguments and run the `demo` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    # Configure validation settings
    if args.no_reformat is not None:
        settings.REFORMAT = not args.no_reformat
    if args.no_ref_check is not None:
        settings.CHECK_REF = not args.no_ref_check
    if args.no_rlinks_check is not None:
        settings.CHECK_CHILD_LINKS = not args.no_rlinks_check

    # Validate the tree
    try:
        tree = build(cwd, root=args.project)
        tree.load()
        valid = tree.valid()
    except DemoError as error:
        logging.error(error)
        return False
    else:
        if tree and valid:
            print("valid tree: {}".format(tree))
        return valid
Exemple #2
0
    def display_tree(self, *_):
        """Display the currently selected tree."""
        # Set the current tree
        self.tree = tree.build(root=self.stringvar_project.get())
        logging.info("displaying tree...")

        # Display the documents in the tree
        values = [document.prefix_relpath for document in self.tree]
        self.combobox_documents['values'] = values

        # Select the first document
        self.combobox_documents.current(0)
Exemple #3
0
def _run_edit(args, cwd, _):
    """Process arguments and run the `demo edit` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    try:
        tree = build(cwd, root=args.project)
        item = tree.edit(args.id, tool=args.tool, launch=True)
    except DemoError as error:
        logging.error(error)
        return False
    else:
        print("opened item: {}".format(item.id_relpath))
        return True
Exemple #4
0
def _run_unlink(args, cwd, _):
    """Process arguments and run the `demo unlink` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    try:
        tree = build(cwd, root=args.project)
        child, parent = tree.unlink(args.child, args.parent)
    except DemoError as error:
        logging.error(error)
        return False
    else:
        print("unlinked item: {} -> {}".format(child.id_relpath,
                                               parent.id_relpath))
        return True
Exemple #5
0
def _run_new(args, cwd, _):
    """Process arguments and run the `demo new` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    try:
        tree = build(cwd, root=args.project)
        document = tree.new(args.root, args.prefix,
                            parent=args.parent, digits=args.digits)
    except DemoError as error:
        logging.error(error)
        return False
    else:
        print("created document: {}".format(document.prefix_relpath))
        return True
Exemple #6
0
def _run_publish(args, cwd, _):
    """Process arguments and run the `demo report` subcommand.

    @param args: Namespace of CLI arguments
    @param cwd: current working directory
    @param err: function to call for CLI errors

    """
    try:
        tree = build(cwd, root=args.project)
        document = tree.find_document(args.prefix)
    except DemoError as error:
        logging.error(error)
        return False
    else:

        kwargs = {'ignored': tree.vcs.ignored}
        if args.width:
            kwargs['width'] = args.width

        if args.path:
            ext = os.path.splitext(args.path)[-1]
        if args.markdown:
            ext = '.md'
        elif args.html:
            ext = '.html'
        elif not args.path:
            ext = '.txt'

        if args.path:
            print("publishing {} to {}...".format(document, args.path))
            report.publish(document, args.path, ext, **kwargs)
        else:
            for line in report.lines(document, ext, **kwargs):
                print(line)

        return True
 def test_build_with_skips(self):
     """Verify documents can be skipped while building a tree."""
     tree = build(FILES)
     self.assertEqual(0, len(tree))
 def test_build(self):
     """Verify a tree can be built."""
     tree = build(FILES)
     self.assertEqual(3, len(tree))
 def test_run_empty(self):
     """Verify an empty directory is an empty hiearchy."""
     tree = build(EMPTY)
     self.assertEqual(0, len(tree))
 def test_palce_empty_no_parent(self):
     """Verify a document with parent cannot be placed in an empty tree."""
     tree = build(EMPTY)
     doc = MockDocument.new(os.path.join(EMPTY, 'temp'), EMPTY, 'TEMP',
                            parent='REQ')
     self.assertRaises(DemoError, tree._place, doc)  # pylint: disable=W0212
 def test_palce_empty(self):
     """Verify a document can be placed in an empty tree."""
     tree = build(EMPTY)
     doc = MockDocument.new(os.path.join(EMPTY, 'temp'), EMPTY, 'TEMP')
     tree._place(doc)  # pylint: disable=W0212
     self.assertEqual(1, len(tree))