diff options
author | lassulus <Lassulus@googlemail.com> | 2011-11-17 11:25:11 +0100 |
---|---|---|
committer | lassulus <Lassulus@googlemail.com> | 2011-11-17 11:25:11 +0100 |
commit | 241bd1f6971eb15835be161dd9bc28366f9e64a6 (patch) | |
tree | d65e7b9352e3df523ecd8a3f90be2783957846ca /punani/index.py | |
parent | 675efc153714786384bbf84bcd9066c452f6bbbe (diff) | |
parent | d5c9e86506c4a62d75f958a1c82e943b1b33ad81 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'punani/index.py')
-rwxr-xr-x | punani/index.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/punani/index.py b/punani/index.py new file mode 100755 index 00000000..4e6a64a4 --- /dev/null +++ b/punani/index.py @@ -0,0 +1,58 @@ +#!/usr/bin/python + +import web +import json + +urls = ( + '/', 'Index', + '/dump','Dump', + '/reload','Reload', + '/(.+)/(.+)', 'ArchFinder', +) + + +PDB_FILE="tightnani_db" +f = open(PDB_FILE) +pdb= json.load(f) +f.close() + +class Index: + def GET(self): + ret = """Welcome to the Tightnani API<br/> +Retrieve a package name for your distribution with: /PACKER/PKG""" + return ret + +class Reload: + def GET(self): + f = open(PDB_FILE) + pdb= json.load(f) + f.close() + return "DB reloaded" + + +class Dump: + def GET(self): + return json.dumps(pdb,sort_keys=True,indent=4) + +class ArchFinder: + def GET(self,packer,package): + if not packer or not package: web.BadRequest() + else: + packer = pdb['packer-symlinks'].get(packer,packer) #try to resolve similar packers + super_packer = pdb['super-packer'].get(packer,'') + ret = pdb.get(package,{}).get(packer,False) + ret = ret if ret else pdb.get(package,{}).get(super_packer,False) + + if not ret: + web.NotFound() + return "not found. i'm so sorry :(" + else: return ret + + + +if __name__ == "__main__": + import sys + sys.argv.append("9111") + app = web.application(urls,globals()) + app.internalerror = web.debugerror + app.run() |