tanketorsken.dk/python-snas-til-at-nummerere-user-stories-i-wikiformat/

Feeds

Python snas til at nummerere user-stories i wikiformat

Skal bruge det i morgen til textmate:

# -*- coding: utf-8 -*-

import re
import sys

cat_re = re.compile(
    r'(=+\s+)([a-z]+(\s[a-z]+)?)\s\(([a-z]{2})\)(\s+=+)',
    re.I
)
us_re = re.compile(
    u'(=+\s+)(US(\s[-a-z]{,3}[0-9]+)?:\s)([-\/\w]+(\s[-\/\w]+)*)(\s+=+)',
    re.I|re.U
)

cur_cat = 'No'
cat_cnt = 0

for line in sys.stdin:
    mo_cat = cat_re.match(line)
    if mo_cat:
        cur_cat = mo_cat.group(4)
        cat_cnt = 0
    else:
        mo_us = us_re.match(line.decode('utf-8'))
        if mo_us:
            cat_cnt += 1
            line = '%sUS %s-%s: %s%s' % (
                mo_us.group(1), cur_cat, cat_cnt,
                mo_us.group(4), mo_us.group(6)
            )