Skip to content

Instantly share code, notes, and snippets.

@jacebrowning
Last active August 29, 2015 13:57
Show Gist options
  • Save jacebrowning/9754157 to your computer and use it in GitHub Desktop.
Save jacebrowning/9754157 to your computer and use it in GitHub Desktop.
iPython Notebook portion of GRDevDay presentation on Doorstop.
{
"metadata": {
"name": "",
"signature": "sha256:ec9792295d515a0c75fe14b1a7b72f536dad998a3da1f0a00bfddee68c54e762"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Doorstop: Requirements Management Using Python and Version Control"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Installation"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"!pip uninstall doorstop --yes\n",
"!pip install doorstop==0.8.1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import doorstop"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Functions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree = doorstop.build()\n",
"\n",
"print(tree)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"SYS <- [ HLR <- [ HLT, LLR <- [ LLT ] ] ]\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document = doorstop.find_document('sys')\n",
"\n",
"print(document)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"SYS\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item = doorstop.find_item('sys1')\n",
"\n",
"print(item)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"SYS001\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exceptions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"doorstop.find_item('fake99') # raises exception"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "DoorstopError",
"evalue": "no item with UID: fake99",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mDoorstopError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-2395171557ca>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdoorstop\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind_item\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'fake99'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# raises exception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/Users/Browning/Drive/Profession/BarCamp/Doorstop/doorstop/core/builder.py\u001b[0m in \u001b[0;36mfind_item\u001b[0;34m(uid)\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0;34m\"\"\"Find an item without an explicitly building a tree.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[0mtree\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_get_tree\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 86\u001b[0;31m \u001b[0mitem\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtree\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind_item\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 87\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/Users/Browning/Drive/Profession/BarCamp/Doorstop/doorstop/core/tree.py\u001b[0m in \u001b[0;36mfind_item\u001b[0;34m(self, value, _kind)\u001b[0m\n\u001b[1;32m 412\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cached unknown: {}\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0muid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 414\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mDoorstopError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mUID\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mUNKNOWN_MESSAGE\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0m_kind\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mu\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0muid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 415\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 416\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_issues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdocument_hook\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem_hook\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDoorstopError\u001b[0m: no item with UID: fake99"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Items"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item = doorstop.find_item('hlr003')\n",
"\n",
"print(repr(item))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/reqs/hlr/HLR003.yml')\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with open(item.path) as infile:\n",
" print(infile.read())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"active: true\n",
"derived: false\n",
"level: 1.2\n",
"links:\n",
"- SYS002: d880b59c0bc5a060d41922110b833f3f\n",
"- SYS008: 6a2015090c976f3aebaa431a7fdeda60\n",
"- SYS028: 5530ac30d996ebc2841d663698f0756a\n",
"normative: true\n",
"ref: test_tutorial.py\n",
"reviewed: 6fc06b5807481efef80ab361d1f196f1\n",
"text: |\n",
" Foo SHALL bar.\n",
"\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Properties"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"path:\", item.path)\n",
"print(\"relpath:\", item.relpath)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"path: /Users/Browning/Drive/Programs/Desktop/DoorstopDemo/reqs/hlr/HLR003.yml\n",
"relpath: @/reqs/hlr/HLR003.yml\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"id:\", item.uid)\n",
"print(\"prefix:\", item.prefix)\n",
"print(\"number:\", item.number)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"id: HLR003\n",
"prefix: HLR\n",
"number: 3\n"
]
}
],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.level = \"1.2\"\n",
"\n",
"print(\"level:\", item.level)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"level: 1.2\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.active = True\n",
"item.derived = False\n",
"\n",
"print(\"active:\", item.active)\n",
"print(\"derived:\", item.derived)\n",
"print(\"normative:\", item.normative)\n",
"print(\"heading:\", item.heading)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"active: True\n",
"derived: False\n",
"normative: True\n",
"heading: False\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.text = \"Foo SHALL bar.\"\n",
"\n",
"print(\"text:\", item.text)\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"text: Foo SHALL bar.\n"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.ref = \"test_tutorial.py\"\n",
"\n",
"print(\"ref:\", item.ref)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"ref: test_tutorial.py\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for identifier in item.links:\n",
" print(\"id:\", identifier)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"id: SYS002\n",
"id: SYS008\n",
"id: SYS028\n"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Actions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.link('SYS999')\n",
"\n",
"for identifier in item.links:\n",
" print(\"id:\", identifier)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"id: SYS002\n",
"id: SYS008\n",
"id: SYS028\n",
"id: SYS999\n"
]
}
],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.unlink('SYS999')\n",
"\n",
"for identifier in item.links:\n",
" print(\"id:\", identifier)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"id: SYS002\n",
"id: SYS008\n",
"id: SYS028\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.ref = \"Represents an item file with linkable text.\"\n",
"\n",
"path, line = item.find_ref()\n",
"\n",
"print(\"path:\", path)\n",
"print(\"line:\", line)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"path: demo/core/item.py\n",
"line: 16\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.ref = \"test_tutorial.py\"\n",
"\n",
"path, line = item.find_ref()\n",
"\n",
"print(\"path:\", path)\n",
"print(\"line:\", line)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"path: demo/cli/test/test_tutorial.py\n",
"line: None\n"
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document = tree.find_document(item.prefix)\n",
"\n",
"identifiers = item.find_child_links() # reverse links\n",
"\n",
"for identifier in identifiers:\n",
" print(\"id:\", identifier)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"id: LLR007\n",
"id: LLR031\n",
"id: LLR036\n",
"id: HLT031\n",
"id: HLT172\n",
"id: HLT142\n",
"id: HLT196\n",
"id: HLT107\n",
"id: HLT057\n",
"id: HLT103\n",
"id: LLR119\n",
"id: LLR156\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.text = \"Another change.\"\n",
"item.reviewed"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"text": [
"False"
]
}
],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.review()\n",
"item.reviewed"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"text": [
"True"
]
}
],
"prompt_number": 21
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.link('SYS042')\n",
"item.cleared"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"text": [
"False"
]
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item.clear()\n",
"item.cleared"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 23,
"text": [
"True"
]
}
],
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Documents"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document = doorstop.find_document('hlt')\n",
"\n",
"print(repr(document))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Document('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/cli/test/docs')\n"
]
}
],
"prompt_number": 24
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with open(document.config) as infile:\n",
" print(infile.read())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"settings:\n",
" digits: 3\n",
" parent: HLR\n",
" prefix: HLT\n",
" sep: ''\n",
"\n"
]
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Properties"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"path:\", document.path)\n",
"print(\"relpath:\", document.relpath)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"path: /Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/cli/test/docs\n",
"relpath: @/demo/cli/test/docs\n"
]
}
],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"prefix:\", document.prefix)\n",
"print(\"sep:\", document.sep)\n",
"print(\"digits:\", document.digits)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"prefix: HLT\n",
"sep: \n",
"digits: 3\n"
]
}
],
"prompt_number": 27
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"parent:\", document.parent)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"parent: HLR\n"
]
}
],
"prompt_number": 28
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"count = 0\n",
"\n",
"for item in document:\n",
" print(item)\n",
" \n",
" count += 1\n",
" if count > 10:\n",
" print('...')\n",
" break"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"HLT001\n",
"HLT002\n",
"HLT003\n",
"HLT004\n",
"HLT005\n",
"HLT006\n",
"HLT007\n",
"HLT008\n",
"HLT009\n",
"HLT010\n",
"HLT011\n",
"...\n"
]
}
],
"prompt_number": 29
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Actions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item = document.add_item()\n",
"\n",
"print(item)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"HLT201\n"
]
}
],
"prompt_number": 30
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document.find_item(item.uid)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 31,
"text": [
"Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/cli/test/docs/HLT201.yml')"
]
}
],
"prompt_number": 31
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document.remove_item(item.uid)\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 32,
"text": [
"Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/cli/test/docs/HLT201.yml')"
]
}
],
"prompt_number": 32
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"document.find_item(item.uid) # raises exception"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "DoorstopError",
"evalue": "no matching UID: HLT201",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mDoorstopError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-33-3d1767e1ed93>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdocument\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind_item\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0muid\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# raises exception\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/Users/Browning/Drive/Profession/BarCamp/Doorstop/doorstop/core/document.py\u001b[0m in \u001b[0;36mfind_item\u001b[0;34m(self, value, _kind)\u001b[0m\n\u001b[1;32m 576\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mitem\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 577\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 578\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mDoorstopError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"no matching{} UID: {}\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_kind\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 579\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 580\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget_issues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem_hook\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDoorstopError\u001b[0m: no matching UID: HLT201"
]
}
],
"prompt_number": 33
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Trees"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree = doorstop.build()\n",
"\n",
"print(repr(tree))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"<Tree SYS <- [ HLR <- [ HLT, LLR <- [ LLT ] ] ]>\n"
]
}
],
"prompt_number": 34
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Properites"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(\"vcs:\", tree.vcs)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"vcs: <doorstop.core.vcs.git.WorkingCopy object at 0x107f0e400>\n"
]
}
],
"prompt_number": 35
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Actions"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import os\n",
"\n",
"path = os.path.join(tree.root, 'a', 'temporaty', 'directory')\n",
"document = tree.create_document(path, 'TMP', parent='SYS')\n",
"\n",
"print(document.relpath)\n",
"\n",
"document.delete()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"@/a/temporaty/directory\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 36,
"text": [
"Document('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/a/temporaty/directory')"
]
}
],
"prompt_number": 36
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item = tree.add_item('sys')\n",
"\n",
"print(item.relpath)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"@/reqs/sys/SYS051.yml\n"
]
}
],
"prompt_number": 37
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree.remove_item(item.uid)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 38,
"text": [
"Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/reqs/sys/SYS051.yml')"
]
}
],
"prompt_number": 38
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree.link_items('llt42', 'hlr2')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 39,
"text": [
"(Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/core/test/docs/LLT042.yml'),\n",
" Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/reqs/hlr/HLR002.yml'))"
]
}
],
"prompt_number": 39
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree.unlink_items('llt42', 'hlr2')"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 40,
"text": [
"(Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/demo/core/test/docs/LLT042.yml'),\n",
" Item('/Users/Browning/Drive/Programs/Desktop/DoorstopDemo/reqs/hlr/HLR002.yml'))"
]
}
],
"prompt_number": 40
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Validation"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tree = doorstop.build()\n",
"\n",
"for issue in tree.issues:\n",
" print(issue)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"HLR: HLR003: unreviewed changes\n",
"HLT: HLT031: suspect link: HLR003\n",
"HLT: HLT172: suspect link: HLR003\n",
"HLT: HLT142: suspect link: HLR003\n",
"HLT: HLT196: suspect link: HLR003\n",
"HLT: HLT107: suspect link: HLR003\n",
"HLT: HLT057: suspect link: HLR003\n",
"HLT: HLT103: suspect link: HLR003\n",
"LLR: LLR007: suspect link: HLR003\n",
"LLR: LLR031: suspect link: HLR003\n",
"LLR: LLR036: suspect link: HLR003\n",
"LLR: LLR119: suspect link: HLR003\n",
"LLR: LLR156: suspect link: HLR003\n"
]
}
],
"prompt_number": 41
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"item = tree.find_item('hlr2')\n",
"item.links = []\n",
"\n",
"item = tree.find_item('llr2')\n",
"item.link('fake99')\n",
"\n",
"for issue in tree.issues:\n",
" print(issue)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"HLR: HLR002: no links to parent document: SYS\n",
"HLR: HLR002: unreviewed changes\n",
"HLR: HLR003: unreviewed changes\n",
"HLT: HLT031: suspect link: HLR003\n",
"HLT: HLT172: suspect link: HLR003\n",
"HLT: HLT142: suspect link: HLR003\n",
"HLT: HLT196: suspect link: HLR003\n",
"HLT: HLT107: suspect link: HLR003\n",
"HLT: HLT057: suspect link: HLR003\n",
"HLT: HLT103: suspect link: HLR003\n",
"LLR: LLR002: parent is 'HLR', but linked to: fake99\n",
"LLR: LLR002: linked to unknown item: fake99\n",
"LLR: LLR002: unreviewed changes\n",
"LLR: LLR007: suspect link: HLR003\n",
"LLR: LLR031: suspect link: HLR003\n",
"LLR: LLR036: suspect link: HLR003\n",
"LLR: LLR119: suspect link: HLR003\n",
"LLR: LLR156: suspect link: HLR003\n"
]
}
],
"prompt_number": 42
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from doorstop.common import DoorstopWarning, DoorstopInfo\n",
"\n",
"def document_hook(document, tree):\n",
" if len(document.items) <= 50:\n",
" yield DoorstopInfo(\"50 or fewer items\")\n",
"\n",
"def item_hook(item, document, tree):\n",
" if 'mater tales' in item.text:\n",
" yield DoorstopWarning(\"'mater tales' in text\")\n",
"\n",
"for issue in tree.get_issues(document_hook=document_hook, item_hook=item_hook):\n",
" print(issue)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"SYS: 50 or fewer items\n",
"HLR: HLR002: no links to parent document: SYS"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLR: HLR002: unreviewed changes"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLR: HLR003: unreviewed changes"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLR: HLR023: 'mater tales' in text"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT031: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT172: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT142: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT196: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT107: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT057: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"HLT: HLT103: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR002: parent is 'HLR', but linked to: fake99"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR002: linked to unknown item: fake99\n",
"LLR: LLR002: unreviewed changes"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR007: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR031: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR036: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR119: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"LLR: LLR156: suspect link: HLR003"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 43
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment