Commits

inklesspen committed 60d7f77

working script

Comments (0)

Files changed (8)

+output
+{
+    "pyramid": {
+        "file": "tarballs/Pyramid.tgz",
+        "version": "1.5"
+    },
+    "alembic": {
+        "file": "tarballs/Alembic.tgz",
+        "version": "0.6.4"
+    },
+    "sqlalchemy-0.9": {
+        "file": "tarballs/SQLAlchemy-0.9.tgz",
+        "version": "0.9.4"
+    },
+    "sqlalchemy-0.8": {
+        "file": "tarballs/SQLAlchemy-0.8.tgz",
+        "version": "0.8.6"
+    }
+}
+#!/usr/bin/env python3.4
+# -*- coding: utf-8 -*-
+
+import argparse
+import hashlib
+from mako.template import Template
+from lxml.builder import E
+from lxml import etree
+import json
+import pathlib
+from urllib.parse import urljoin, quote
+from shutil import copy
+
+workpath = pathlib.Path(__file__).resolve()
+outputpath = workpath.with_name('output')
+baseurl = 'http://projects.inklesspen.com/dashsets/'
+
+
+def build(args):
+    if not outputpath.is_dir():
+        outputpath.mkdir()
+    # read package, version, and tarball info from json
+    jsonpath = workpath.with_name('dashsets.json')
+    with jsonpath.open() as f:
+        config = json.load(f)
+    # generate sha1 hashes
+    for dashset in config:
+        tgzpath = jsonpath.with_name(config[dashset]['file']).resolve()
+        with tgzpath.open('rb') as tgz:
+            sha1 = hashlib.sha1()
+            sha1.update(tgz.read())
+            config[dashset]['sha1'] = sha1.hexdigest()
+        # render xml feeds
+        feed_filename = "{}.xml".format(dashset)
+        tgz_url = urljoin(baseurl, tgzpath.name)
+        with (outputpath / feed_filename).open('wb') as out:
+            feed = E.entry(
+                E.version(config[dashset]['version']),
+                E.sha1(config[dashset]['sha1']),
+                E.url(tgz_url))
+            with etree.xmlfile(out) as xout:
+                xout.write(feed, pretty_print=True)
+        # copy tarball
+        copy(str(tgzpath), str(outputpath / tgzpath.name))
+        feed_url = quote(urljoin(baseurl, feed_filename), safe='')
+        full_feed_url = 'dash-feed://{}'.format(feed_url)
+        config[dashset]['url'] = full_feed_url
+        
+    # render index page
+    tpl = Template(filename=str(workpath.with_name('index.mako')))
+    with (outputpath / 'index.html').open('w') as out:
+        out.write(tpl.render(config=config))
+
+
+parser = argparse.ArgumentParser(description="Build the dashsets")
+subparsers = parser.add_subparsers()
+
+parser_build = subparsers.add_parser('build')
+parser_build.set_defaults(func=build)
+
+
+def main():
+    args = parser.parse_args()
+    if hasattr(args, 'func'):
+        return args.func(args)
+    parser.print_usage()
+
+
+if __name__ == "__main__":
+    main()
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>Bootstrap 101 Template</title>
+
+    <link href="http://netdna.bootstrapcdn.com/bootswatch/3.1.1/simplex/bootstrap.min.css" rel="stylesheet">
+
+  </head>
+  <body>
+    <div class="container">
+      <h2>Dash Docsets</h2>
+      <p class="lead"><a href="http://kapeli.com/dash">Dash</a> is a great resource for browsing documentation. Here's some docsets for libraries I use.</p>
+
+      <table class="table table-striped table-hover ">
+        <thead>
+          <tr>
+            <th>Package</th>
+            <th>Version</th>
+            <th>Docset Feed</th>
+          </tr>
+        </thead>
+        <tbody>
+          % for docset in config:
+          <tr>
+            <td>${docset}</td>
+            <td>${config[docset]['version']}</td>
+            <td><a href="${config[docset]['url']}">Click Here</a></td>
+          </tr>
+          % endfor
+        </tbody>
+      </table>
+    </div>
+  </body>
+</html>

tarballs/Alembic.tgz

Binary file added.

tarballs/Pyramid.tgz

Binary file added.

tarballs/SQLAlchemy-0.8.tgz

Binary file added.

tarballs/SQLAlchemy-0.9.tgz

Binary file added.