63 |
bs = b['date'].split('-') |
bs = b['date'].split('-') |
64 |
if not len(as) == 3 or not len(bs) == 3: |
if not len(as) == 3 or not len(bs) == 3: |
65 |
return len(as) < len(bs) or (len(bs) < len(as)) * -1 or 0 |
return len(as) < len(bs) or (len(bs) < len(as)) * -1 or 0 |
66 |
ac = as[0]*356 + as[1]*30 + as[2] |
ac = int(as[0])*10000 + int(as[1])*100 + int(as[2]) |
67 |
bc = bs[0]*356 + bs[1]*30 + bs[2] |
bc = int(bs[0])*10000 + int(bs[1])*100 + int(bs[2]) |
68 |
return ac < bc or (bc < ac) * -1 or 0 |
return ac < bc or (bc < ac) * -1 or 0 |
69 |
|
|
70 |
#returns the value of the first occurrense or all of the occurrences |
#returns the value of the first occurrense or all of the occurrences |
71 |
#of given tagName in docutils' document tree |
#of given tagName in docutils' document tree |
72 |
def getTagValue(document, tagName, all=0): |
def getTagValue(document, tagName, all=0, always_raw=0): |
73 |
values = [] |
values = [] |
74 |
if document.tagname.lower() == tagName.lower(): |
if document.tagname.lower() == tagName.lower(): |
75 |
if hasattr(document.children[0], 'data'): |
if hasattr(document.children[0], 'data') and not always_raw: |
76 |
return document.children[0].data |
return document.children[0].data |
77 |
else: |
else: |
78 |
return document.rawsource |
return document.rawsource |
79 |
if hasattr(document, 'children'): |
if hasattr(document, 'children'): |
80 |
for child in document.children: |
for child in document.children: |
81 |
value = getTagValue(child, tagName, all) |
value = getTagValue(child, tagName, all=all, always_raw=always_raw) |
82 |
if value and not all: |
if value and not all: |
83 |
return value |
return value |
84 |
elif value: |
elif value: |
146 |
#conversion have succeeded so far, parsing peg's metadata |
#conversion have succeeded so far, parsing peg's metadata |
147 |
#from its document tree |
#from its document tree |
148 |
if rstfile == peg['rst']: |
if rstfile == peg['rst']: |
149 |
peg['topic'] = getTagValue(document, 'title') |
peg['topic'] = getTagValue(document, 'title', always_raw=1) |
150 |
peg['topic'] = peg['topic'].replace('`', '') |
peg['topic'] = peg['topic'].replace('`', '') |
151 |
peg['date'] = getTagValue(document, 'date') |
peg['date'] = getTagValue(document, 'date') |
152 |
#we may have got 'rawsource', which need some tidying |
#we may have got 'rawsource', which needs some tidying |
153 |
if peg['date'].startswith('$Date'): |
if peg['date'].startswith('$Date'): |
154 |
peg['date'] = peg['date'][7:len(peg['date'])-11].replace('/', '-') |
peg['date'] = peg['date'][7:len(peg['date'])-11].replace('/', '-') |
155 |
peg['status'] = getTagValue(document, 'status') or undefined |
peg['status'] = getTagValue(document, 'status') or undefined |