Skip to content

Commit

Permalink
reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Piotr Przeradowski committed Aug 11, 2013
1 parent 39c5565 commit b6e3683
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pystacia.egg-info/
.coverage

tool/downloads
tool/data.py
55 changes: 51 additions & 4 deletions tool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from os.path import dirname, abspath, join, basename, splitext, exists
from subprocess import check_call, check_output
from re import compile
from pprint import pprint


here = dirname(abspath(__file__))
typedef_tmpl = 'typedef\s+enum\s*\{([^\}]+)\}\s*'
Expand Down Expand Up @@ -74,25 +76,70 @@ def filled():
return result


def reduce_(data):
for key, values in data.items():
print(key.upper() + '---------------------------')
seen = {}
for i, value in enumerate(values):
copied = value.copy()
version = copied.pop('_version')
if copied == seen:
values[i] = None
else:
print(' version ' + str(version))
copied_set = set(copied.items())
seen_set = set(seen.items())
added = dict(copied_set - seen_set)
removed = dict(seen_set - copied_set)

if added:
print(' + ' + str(added))
if removed:
print(' - ' + str(removed))

seen = copied

data[key] = filter(None, values)


min_version = (6, 5)


def main():
downloads = join(here, 'downloads')
archives = glob(join(downloads, '*.tar.bz2'))

directories = []
for archive in archives:
directory, _ = splitext(splitext(archive)[0])
directories.append(directory)

version_str = basename(directory).split('-', 1)[1].replace('-', '.')
version = tuple(int(v) for v in version_str.split('.'))
if version < min_version:
continue

directories.append((version, directory))

if exists(directory):
continue

print('Unpacking ' + basename(archive))
check_call(['tar', '-C', downloads, '-xf', archive])

for directory in directories:
process(directory)
data = dict((k, []) for k in enums)
for version, directory in sorted(directories):
result = process(directory)

for name, values in result.items():
values['_version'] = version[:-1]
data[name].append(values)

reduce_(data)

with open(join(here, 'data.py'), 'w') as f:
pprint(data, f)

return directories
return data


if __name__ == '__main__':
Expand Down

0 comments on commit b6e3683

Please sign in to comment.