Commit 0465c749 authored by David Spencer's avatar David Spencer

changelog-parser: Tidyups.

Improve the docstring, tidy code layout, and remove debug code.
parent 945e39c6
#!/usr/bin/python3
"""
Parse Slackware (and friends) ChangeLog.txt.
Requires: python3, and ply (built with python3 support)
This proof-of-concept parses into a Python structure and then
writes it as JSON, which should end up looking like this:
This proof-of-concept reads a ChangeLog on standard input and creates a
Python list of dicts. Each dict is a changelog entry comprising "date"
(as a string), "motd" (the entry's optional message of the day, or a
null string), and "itemlist" (a list of dicts comprising "itemname",
"description" and "securityfix"). This is then written to standard
output as JSON.
[
{
date: "string",
motd: "string",
itemlist: [
{ itemname:"string", description:"string", securityfix:BOOL },
{ itemname:"string", description:"string", securityfix:BOOL },
...
]
},
{
date: "string",
motd: "string",
itemlist: [
{ itemname:"string", description:"string", securityfix:BOOL },
{ itemname:"string", description:"string", securityfix:BOOL },
...
]
date: "string",
motd: "string",
itemlist:
[
{ itemname:"string", description:"string", securityfix:BOOL },
...
]
},
...
]
Whitespace and newlines are preserved in "motd" and "description",
except that the description's required one- or two-space indentation is
removed.
"""
#-----------------------------------------------------------------------
......@@ -38,9 +39,9 @@ from ply import *
#-----------------------------------------------------------------------
states = (
('header', 'exclusive'),
('itemdesc', 'exclusive')
)
('header', 'exclusive'),
('itemdesc', 'exclusive')
)
tokens = (
'SEPARATOR',
......@@ -134,12 +135,6 @@ lexer = lex.lex()
#-----------------------------------------------------------------------
def pdbg(str,p):
if False:
print(str)
for pp in p[1:]:
print(" ",pp)
def p_entrylist(p):
"""
entrylist : entry entrylist
......@@ -218,10 +213,10 @@ def p_item(p):
securityfix = False
if len(p) == 5:
description = description + p[4]
securityfix=True
securityfix = True
elif len(p) == 4:
securityfix=True
p[0]={"itemname":p[1], "description":description, "securityfix":securityfix}
securityfix = True
p[0] = {"itemname":p[1], "description":description, "securityfix":securityfix}
def p_descseq(p):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment