Created
May 26, 2012 20:52
-
-
Save o11c/2795259 to your computer and use it in GitHub Desktop.
quick hack replacement for analyze.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import re | |
import git | |
import zipfile | |
# contains resources.xml and .zip files | |
updates_path = os.path.join(os.getenv('HOME'), '.local/share/mana/updates/tmw-test.dyndns.org') | |
# submodule repository | |
client_data = 'client-data' | |
current = set(git.Git(client_data).ls_files().split('\n')) | |
# with apologies to xml and Jon Postel | |
zips = [zip for zip in re.sub('".*', '', re.sub('.*file="', '', open(os.path.join(updates_path, 'resources.xml')).read())).split() if zip.endswith('.zip')] | |
deleted = {} | |
outdated = {} | |
needed = {} | |
def out_date(filename): | |
for key in needed: | |
n = needed[key] | |
if filename in n: | |
n.remove(filename) | |
outdated[key].add(filename) | |
for zipname in zips: | |
contents = set(name for name in zipfile.ZipFile(os.path.join(updates_path, zipname)).namelist() if not name.endswith('/')) | |
deleted[zipname] = contents - current | |
for filename in contents: | |
out_date(filename) | |
outdated[zipname] = set() | |
needed[zipname] = contents & current | |
for zipname in zips: | |
print '%s: %d deleted, %d outdated, %d needed' % (zipname, len(deleted[zipname]), len(outdated[zipname]), len(needed[zipname])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment