Exemple #1
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = args.host
    port = args.port or settings.SERVER_PORT
    bottle.TEMPLATE_PATH.insert(
        0, os.path.join(os.path.dirname(__file__), '..', 'views')
    )

    # If you started without WSGI, the base will be '/'.
    if args.baseurl == '' and not args.wsgi:
        args.baseurl = '/'

    # If you specified a base URL, make sure it ends with '/'.
    if args.baseurl != '' and not args.baseurl.endswith('/'):
        args.baseurl += '/'

    bottle.SimpleTemplate.defaults['baseurl'] = args.baseurl
    bottle.SimpleTemplate.defaults['navigation'] = True

    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    if not args.wsgi:
        bottle.run(app=app, host=host, port=port, debug=args.debug, reloader=args.debug)
Exemple #2
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = args.host
    port = args.port or settings.SERVER_PORT
    bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__),
                                                '..', 'views'))

    # If you started without WSGI, the base will be '/'.
    if args.baseurl == '' and not args.wsgi:
        args.baseurl = '/'

    # If you specified a base URL, make sure it ends with '/'.
    if args.baseurl != '' and not args.baseurl.endswith('/'):
        args.baseurl += '/'

    bottle.SimpleTemplate.defaults['baseurl'] = args.baseurl
    bottle.SimpleTemplate.defaults['navigation'] = True

    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    if not args.wsgi:
        bottle.run(app=app, host=host, port=port,
                   debug=args.debug, reloader=args.debug)
Exemple #3
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setWindowTitle('Doorhole - doorstop requirements editor')

        global reqtree
        reqtree = doorstop.build()

        self.tabs = QTabWidget()
        self.setCentralWidget(self.tabs)

        # One tab for each document
        for document in reqtree:
            # container widget
            container = QTabWidget()

            # widgets
            reqsW = QWidget()
            reqsView = RequirementManager(document.prefix)

            reqsLy = QVBoxLayout()
            reqsLy.addWidget(reqsView)
            reqsW.setLayout(reqsLy)

            container.addTab(reqsW, 'Requirements')

            title = document.parent + ' -> ' + document.prefix if document.parent else document.prefix
            self.tabs.addTab(container, title)
    def __init__(self, config):
        """Set config and tree."""
        self.config = config
        self.tree = doorstop.build(root=config.option.doorstop_path)

        # Check that there is at least one document in the tree
        if not self.tree.documents:
            # Try to build a tree using each first-level child of the path
            children = list(
                pathlib.Path(config.option.doorstop_path).glob("*"))
            while children:
                path = children.pop()
                self.tree = doorstop.build(root=path)
                if self.tree.documents:
                    break
            else:
                raise RuntimeError(
                    f"Could not find a Doorstop document in the path "
                    f"{config.option.doorstop_path} or its children.")
Exemple #5
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = "localhost"
    port = args.port or settings.SERVER_PORT
    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    bottle.run(app=app, host=host, port=port, debug=args.debug, reloader=args.debug)
Exemple #6
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603,C0103
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = 'localhost'
    port = args.port or settings.SERVER_PORT
    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    bottle.run(host=host, port=port, debug=args.debug, reloader=args.debug)
def main():
    """Create new random requirements if none exist."""

    # Parse arguments
    delete_items = '--items' in sys.argv
    delete_links = '--links' in sys.argv

    # Configure logging
    logging.basicConfig(format="%(message)s", level=logging.INFO)

    # Get current requirements
    logging.info("loading the current requirements...")
    tree = doorstop.build()
    tree.load()

    # Delete old requirements
    if delete_items:
        logging.info("deleting the current requirements...")
        tree.delete()

    # Delete old links
    if delete_links and not delete_items:
        logging.info("deleting the current links...")
        for document in tree:
            for item in document:
                item.links = []

    # Generate random requirements if needed
    _randomize_items(tree)
    _randomize_links(tree)

    # Fix levels
    for document in tree:
        items = document.items
        for index in range(1, len(items)):
            level = list(items[index].level)
            level_prev = list(items[index - 1].level)
            logging.info("checking {} level {}...".format(document.prefix, level))
            while level <= level_prev:
                logging.info("fixing {} level {}...".format(items[index], level))
                level[-1] += 1
            items[index].level = level
Exemple #8
0
def rtm_builder(prefix: str,
                root: str = None,
                sort_key: str = None,
                csv_path: str = None) -> str:
    """Generate a traceability matrix, and output to either stdout or csv.

    Args:
        prefix: The prefix for Doorstop requirements.
        root: The root path to search for Doorstop documents.
        sort_key: If the RTM should be sorted, sort by this key.
            Should be one of 'UID', 'Has Test', 'Tests', or None. Defaults to None.
        csv_path: If the RTM should be written to file, write to this path.
            If omitted, the RTM will be returned. Defaults to None.
    """
    tree = doorstop.build(root=root)
    reqs_doc = tree.find_document(prefix)
    table_data = [{
        "UID":
        str(item),
        "Has Test":
        bool(item.child_links),
        "Need Test":
        bool(item.normative),
        "Tests":
        " ".join([str(child) for child in item.child_links]),
    } for item in reqs_doc.items]

    if sort_key:
        table_data = sorted(table_data, key=lambda x: x[sort_key])

    table = rapidtables.make_table(table_data, tablefmt="md")

    if csv_path:
        with open(csv_path, "w", newline="") as csvfile:
            fieldnames = ["UID", "Has Test", "Need Test", "Tests"]
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            for row in table_data:
                writer.writerow(row)
        return f"Successfully wrote traceability matrix to {csv_path}"
    else:
        return table
async def sync_labels():
    tree = doorstop.build()
    print(f"Document tree structure: {tree}")

    async with get_api(project_url) as api:
        for doc_name in tree.documents:
            print(f"Parsing document: {doc_name}")
            document = tree.find_document(doc_name)
            count = sum(1 for item in document if item.active)
            print(f"{count} active items in {document}")
            # sync all items
            for item in document.items:
                if item.normative:
                    try:
                        label = await api.projects.labels.create(
                            project_url.path.strip('/'),
                            data={
                                'name': f'{item.uid}',
                                'color': color
                            },
                            model=True)
                        print(f"Created label {item.uid}")
                    except ClientResponseError as err:
                        print(f"ClientResponseError: {err.message}")
Exemple #10
0
            doc.remove_item(uid)
            print('delete requirement')


if __name__ == '__main__':
    PARSER = argparse.ArgumentParser(
        description='Parse .docx documents into Doorstop files')
    PARSER.add_argument('repopath',
                        type=str,
                        help='path to the requirement tree')
    ARGS = PARSER.parse_args()

    readline.parse_and_bind('tab: complete')
    readline.parse_and_bind('set editing-mode vi')

    REQTREE = doorstop.build(root=ARGS.repopath)
    print('On tree {}'.format(ARGS.repopath))
    print(REQTREE)

    while True:
        try:
            print('1. Add document')
            print('2. Update document')
            print('3. Analyze requirement tree')
            print('4. Quit')
            SEL = int(input('> '))

            if SEL == 1:
                DOCPATH = input('Document path: ')
                DOCTREE = get_xml_tree(DOCPATH)
                process_document(ARGS.repopath, REQTREE, DOCTREE, _create)
Exemple #11
0
#!/usr/bin/env python
"""Example Doorstop API usage to extract all normative items."""

import sys
import doorstop

tree = doorstop.build()
print(f"Document tree structure: {tree}")

for doc_name in tree.documents:
    print(f"Parsing document: {doc_name}")
    document = tree.find_document(doc_name)
    count = sum(1 for item in document if item.active)
    print(f"{count} active items in {document}")
    # list all items
    for item in document.items:
        if item.normative:
            print(f"{item.uid}")