In [ ]:
!pip uninstall doorstop --yes
!pip install doorstop==0.8.1
In [1]:
import doorstop
In [2]:
tree = doorstop.build()
print(tree)
In [3]:
document = doorstop.find_document('sys')
print(document)
In [4]:
item = doorstop.find_item('sys1')
print(item)
In [5]:
doorstop.find_item('fake99') # raises exception
In [6]:
item = doorstop.find_item('hlr003')
print(repr(item))
In [7]:
with open(item.path) as infile:
print(infile.read())
In [8]:
print("path:", item.path)
print("relpath:", item.relpath)
In [9]:
print("id:", item.uid)
print("prefix:", item.prefix)
print("number:", item.number)
In [10]:
item.level = "1.2"
print("level:", item.level)
In [11]:
item.active = True
item.derived = False
print("active:", item.active)
print("derived:", item.derived)
print("normative:", item.normative)
print("heading:", item.heading)
In [12]:
item.text = "Foo SHALL bar."
print("text:", item.text)
In [13]:
item.ref = "test_tutorial.py"
print("ref:", item.ref)
In [14]:
for identifier in item.links:
print("id:", identifier)
In [15]:
item.link('SYS999')
for identifier in item.links:
print("id:", identifier)
In [16]:
item.unlink('SYS999')
for identifier in item.links:
print("id:", identifier)
In [17]:
item.ref = "Represents an item file with linkable text."
path, line = item.find_ref()
print("path:", path)
print("line:", line)
In [18]:
item.ref = "test_tutorial.py"
path, line = item.find_ref()
print("path:", path)
print("line:", line)
In [19]:
document = tree.find_document(item.prefix)
identifiers = item.find_child_links() # reverse links
for identifier in identifiers:
print("id:", identifier)
In [20]:
item.text = "Another change."
item.reviewed
Out[20]:
In [21]:
item.review()
item.reviewed
Out[21]:
In [22]:
item.link('SYS042')
item.cleared
Out[22]:
In [23]:
item.clear()
item.cleared
Out[23]:
In [24]:
document = doorstop.find_document('hlt')
print(repr(document))
In [25]:
with open(document.config) as infile:
print(infile.read())
In [26]:
print("path:", document.path)
print("relpath:", document.relpath)
In [27]:
print("prefix:", document.prefix)
print("sep:", document.sep)
print("digits:", document.digits)
In [28]:
print("parent:", document.parent)
In [29]:
count = 0
for item in document:
print(item)
count += 1
if count > 10:
print('...')
break
In [30]:
item = document.add_item()
print(item)
In [31]:
document.find_item(item.uid)
Out[31]:
In [32]:
document.remove_item(item.uid)
Out[32]:
In [33]:
document.find_item(item.uid) # raises exception
In [34]:
tree = doorstop.build()
print(repr(tree))
In [35]:
print("vcs:", tree.vcs)
In [36]:
import os
path = os.path.join(tree.root, 'a', 'temporaty', 'directory')
document = tree.create_document(path, 'TMP', parent='SYS')
print(document.relpath)
document.delete()
Out[36]:
In [37]:
item = tree.add_item('sys')
print(item.relpath)
In [38]:
tree.remove_item(item.uid)
Out[38]:
In [39]:
tree.link_items('llt42', 'hlr2')
Out[39]:
In [40]:
tree.unlink_items('llt42', 'hlr2')
Out[40]:
In [41]:
tree = doorstop.build()
for issue in tree.issues:
print(issue)
In [42]:
item = tree.find_item('hlr2')
item.links = []
item = tree.find_item('llr2')
item.link('fake99')
for issue in tree.issues:
print(issue)
In [43]:
from doorstop.common import DoorstopWarning, DoorstopInfo
def document_hook(document, tree):
if len(document.items) <= 50:
yield DoorstopInfo("50 or fewer items")
def item_hook(item, document, tree):
if 'mater tales' in item.text:
yield DoorstopWarning("'mater tales' in text")
for issue in tree.get_issues(document_hook=document_hook, item_hook=item_hook):
print(issue)