[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#840094: blends-dev: Does not recognize multiline dependencies



Hi Andreas, Petter, and all

I updated all tasks of debian-edu to be RFC834 compliant: continuation
with indentation, no backslashes, no duplicated keywords. The diff looks
OK for me; you should however double check.

If you don't like it, revert and discuss it.

I wrote a small Python script for that - nothing I would be proud of,
but it did the job here. I attach it since it may help for other tasks
as well, but don't blame me :-)

I takes all files from the tasks/ subdir, reformats them and writes them
back. No security or so. Check with "git diff" afterwards that
everything is OK.

Cheers

Ole
#!/usr/bin/env python3

from __future__ import print_function

from glob import glob
from collections import OrderedDict
import re

def format_section(s):
    return "\n".join(l[1] for l in s.values()) + "\n"

def format_task(sections):
    return "\n".join(format_section(s) for s in sections)
        
def get_task(f):
    key = ""
    items = OrderedDict()
    sections = []
    for l in f.readlines():
        backslash = "\\" in l
        l = l.replace("\\","").strip()
        if not l and not backslash:
            if items:
                sections.append(items)
            items = OrderedDict()
            key = ""
            continue
        m = re.match(r"^(\S+):(\s*)(.*)", l)
        if m is not None:
            key = m.group(1)
            if key in items:
                items[key][1] += "\n " + " " * items[key][0] + m.group(3).strip()
            else:
                if key in ("Depends", "Ignore", "Avoid",
                               "Recommends", "Suggests", "Why"):
                    indent = len(key) + len(m.group(2))
                else:
                    indent = 0
                items[key] = [indent, m.group(0).strip()]
        else:
            items[key][1] += "\n " + " " * items[key][0] + l
    if items:
        sections.append(items)
    return sections

for taskname in glob("tasks/*"):
    with open(taskname) as taskfile:
        s = format_task(get_task(taskfile))
    with open(taskname, "w") as taskfile:
        taskfile.write(s)

Reply to: