Example #1
0
def run_export(args, cwd, error, catch=True, auto=False, _tree=None):
    """Process arguments and run the `doorstop export` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    :param auto: include placeholders for new items on import

    """
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, error, '.yml', '.csv', whole_tree=whole_tree)

    # Get the tree or document
    with utilities.capture(catch=catch) as success:

        exporter.check(ext)
        tree = _tree or _get_tree(args, cwd, load=whole_tree)
        if not whole_tree:
            document = tree.find_document(args.prefix)

    if not success:
        return False

    # Write to output file(s)
    if args.path:
        if whole_tree:
            msg = "exporting tree to '{}'...".format(args.path)
            utilities.show(msg, flush=True)
            path = exporter.export(tree, args.path, ext, auto=auto)
        else:
            msg = "exporting document {} to '{}'...".format(
                document, args.path)
            utilities.show(msg, flush=True)
            path = exporter.export(document, args.path, ext, auto=auto)
        if path:
            utilities.show("exported: {}".format(path))

    # Or, display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in exporter.export_lines(document, ext):
            utilities.show(line)

    return True
Example #2
0
def run_export(args, cwd, error, catch=True, auto=False, _tree=None):
    """Process arguments and run the `doorstop export` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    :param auto: include placeholders for new items on import

    """
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, error, '.yml', '.csv', whole_tree=whole_tree)

    # Get the tree or document
    with utilities.capture(catch=catch) as success:

        exporter.check(ext)
        tree = _tree or _get_tree(args, cwd, load=whole_tree)
        if not whole_tree:
            document = tree.find_document(args.prefix)

    if not success:
        return False

    # Write to output file(s)
    if args.path:
        if whole_tree:
            msg = "exporting tree to '{}'...".format(args.path)
            utilities.show(msg, flush=True)
            path = exporter.export(tree, args.path, ext, auto=auto)
        else:
            msg = "exporting document {} to '{}'...".format(document,
                                                            args.path)
            utilities.show(msg, flush=True)
            path = exporter.export(document, args.path, ext, auto=auto)
        if path:
            utilities.show("exported: {}".format(path))

    # Or, display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in exporter.export_lines(document, ext):
            utilities.show(line)

    return True
Example #3
0
 def test_lines(self):
     """Verify an item can be exported as lines."""
     expected = ("req3:" + '\n'
                 "  active: true" + '\n'
                 "  derived: false" + '\n'
                 "  level: 1.1.0" + '\n'
                 "  links:" + '\n'
                 "  - sys3: null" + '\n'
                 "  normative: false" + '\n'
                 "  ref: ''" + '\n'
                 "  reviewed: null" + '\n'
                 "  text: |" + '\n' + "    Heading" + '\n\n')
     # Act
     lines = exporter.export_lines(self.item)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Example #4
0
 def test_lines(self):
     """Verify an item can be exported as lines."""
     expected = ("req3:" + '\n'
                 "  active: true" + '\n'
                 "  derived: false" + '\n'
                 "  level: 1.1.0" + '\n'
                 "  links:" + '\n'
                 "  - sys3: null" + '\n'
                 "  normative: false" + '\n'
                 "  ref: ''" + '\n'
                 "  reviewed: null" + '\n'
                 "  text: |" + '\n' +
                 "    Heading" + '\n\n')
     # Act
     lines = exporter.export_lines(self.item)
     text = ''.join(line + '\n' for line in lines)
     # Assert
     self.assertEqual(expected, text)
Example #5
0
def run_export(args, cwd, error, catch=True):
    """Process arguments and run the `doorstop export` subcommand.

    :param args: Namespace of CLI arguments
    :param cwd: current working directory
    :param error: function to call for CLI errors
    :param catch: catch and log :class:`~doorstop.common.DoorstopError`

    """
    # Parse arguments
    whole_tree = args.prefix == 'all'
    ext = utilities.get_ext(args, '.yml', '.csv', whole_tree, error)

    # Export documents
    with utilities.capture(catch=catch) as success:
        exporter.check(ext)
        tree = build(cwd=cwd, root=args.project)
        if not whole_tree:
            document = tree.find_document(args.prefix)
    if not success:
        return False

    # Write to output file(s)
    if args.path:
        if whole_tree:
            show("exporting tree to '{}'...".format(args.path), flush=True)
            path = exporter.export(tree, args.path, ext)
        else:
            msg = "exporting document {} to '{}'...".format(document,
                                                            args.path)
            show(msg, flush=True)
            path = exporter.export(document, args.path, ext)
        if path:
            show("exported: {}".format(path))

    # Display to standard output
    else:
        if whole_tree:
            error("only single documents can be displayed")
        for line in exporter.export_lines(document, ext):
            show(line)

    return True
Example #6
0
 def test_lines_unknown(self):
     """Verify an exception is raised when iterating an unknown format."""
     # Act
     gen = exporter.export_lines(self.document, '.a')
     # Assert
     self.assertRaises(DoorstopError, list, gen)
Example #7
0
 def test_lines_unknown(self):
     """Verify an exception is raised when iterating an unknown format."""
     # Act
     gen = exporter.export_lines(self.document, '.a')
     # Assert
     self.assertRaises(DoorstopError, list, gen)