Skip to content

Instantly share code, notes, and snippets.

@starius
Created December 18, 2016 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starius/9f5c315e5d0cf113d41dc454b7a0eb41 to your computer and use it in GitHub Desktop.
Save starius/9f5c315e5d0cf113d41dc454b7a0eb41 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
with open('docs/index.html', 'rb') as f:
index_html = f.read()
sep1 = ' <table id="package-list" class="old">'
sep2 = ' </table>'
(prefix, other) = index_html.split(sep1, 1)
(packages_html, suffix) = other.split(sep2, 1)
# find existing packages
pkg_re = r'''
<tr>
<td class="package">(?P<name>.*)</td>
<td class="website"><a href="(?P<website>.*)">(?P<description>.*)</a></td>
</tr>
'''.strip()
for group in re.finditer(pkg_re, packages_html):
pkg = group.group('name')
description = group.group('description')
website = group.group('website')
mk_file = 'src/%s.mk' % pkg
with open(mk_file) as f:
lines = list(f)
pkg_lines = [
(i, line) for i, line in enumerate(lines)
if line.startswith('PKG ')
]
assert len(pkg_lines) == 1
pkg_i, pkg_line = pkg_lines[0]
website_line = pkg_line.replace('PKG ', '$(PKG)_WEBSITE').split(':=')[0] + ':= ' + website + '\n'
description_line = pkg_line.replace('PKG ', '$(PKG)_DESCR').split(':=')[0] + ':= ' + description + '\n'
if description != pkg:
lines.insert(pkg_i + 1, description_line)
lines.insert(pkg_i + 1, website_line)
with open(mk_file, 'wb') as f:
t = ''.join(lines)
f.write(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment