Permalink
Browse files

glossary related files; object ID 62952

  • Loading branch information...
1 parent e4f5e0e commit 2c5d63c1ebcac9e1eb10633cb3a831e83098d5a8 straup committed Jul 10, 2012
Showing with 402 additions and 0 deletions.
  1. +112 −0 bin/generate-glossary.py
  2. +70 −0 bin/publish-glossary.py
  3. +137 −0 glossary.json
  4. +83 −0 glossary.md
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import os.path
+import json
+import types
+import utils
+
+def crawl(root) :
+
+ glossary = {}
+
+ for root, dirs, files in os.walk(root):
+
+ for f in files:
+
+ if not f.endswith(".json") :
+ continue
+
+ path = os.path.join(root, f)
+ path = os.path.abspath(path)
+
+ fh = open(path, 'r')
+ data = json.load(fh)
+
+ munge(glossary, data)
+
+ return glossary
+
+def munge(glossary, thing, prefix=None):
+
+ if type(thing) == types.DictType:
+
+ for k, v in thing.items():
+
+ label = k
+
+ if prefix:
+ label = "%s.%s" % (prefix, label)
+
+ if type(v) == types.DictType:
+
+ add_key(glossary, label)
+ munge(glossary, v, label)
+
+ elif type(v) == types.ListType:
+
+ add_key(glossary, label)
+ munge(glossary, v, label)
+
+ else:
+
+ add_key(glossary, label)
+
+ elif type(thing) == types.ListType:
+
+ for stuff in thing:
+ munge(glossary, stuff, prefix)
+
+ else:
+ pass
+
+def add_key(glossary, key):
+
+ if glossary.get(key, False):
+ return
+
+ glossary[key] = {
+ "description": "",
+ "notes": [],
+ "sameas": []
+ }
+
+if __name__ == '__main__':
+
+ import optparse
+
+ parser = optparse.OptionParser(usage="python generate-glossary.py --options")
+
+ parser.add_option('--objects', dest='objects',
+ help='The path to your collection objects',
+ action='store')
+
+ parser.add_option('--glossary', dest='glossary',
+ help='The path where your new glossary file should be written',
+ action='store')
+
+ options, args = parser.parse_args()
+
+ #
+
+ old_glossary = None
+
+ if os.path.exists(options.glossary):
+ fh = open(options.glossary, 'r')
+ old_glossary = json.load(fh)
+ fh.close()
+
+ #
+
+ new_glossary = crawl(options.objects)
+
+ if old_glossary:
+ new_glossary = dict(new_glossary.items() + old_glossary.items())
+
+ #
+
+ fh = open(options.glossary, 'w')
+ json.dump(new_glossary, fh, indent=2)
+ fh.close()
+
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import sys
+import json
+
+if __name__ == '__main__':
+
+ import optparse
+
+ parser = optparse.OptionParser(usage="python generate-glossary.py --options")
+
+ parser.add_option('--glossary', dest='glossary',
+ help='The path where your new glossary file should be written',
+ action='store')
+
+ parser.add_option('--markdown', dest='markdown',
+ help='The path to your collection objects',
+ action='store', default=None)
+
+ options, args = parser.parse_args()
+
+ fh = open(options.glossary, 'r')
+ glossary = json.load(fh)
+ fh.close()
+
+ keys = glossary.keys()
+ keys.sort()
+
+ if options.markdown:
+ fh = open(options.markdown, 'w')
+ else:
+ fh = sys.stdout
+
+ fh.write("_This file was generated programmatically using the `%s` document._\n" % options.glossary)
+ fh.write("\n")
+
+ for k in keys:
+
+ details = glossary[k]
+
+ fh.write("%s\n" % k)
+ fh.write("==\n")
+ fh.write("\n")
+
+ if details['description'] != '':
+ fh.write("_%s_\n" % details['description'])
+ fh.write("\n")
+
+ if len(details['notes']):
+
+ fh.write("notes\n")
+ fh.write("--\n")
+
+ for n in details['notes']:
+ fh.write("* %s\n" % n)
+ fh.write("\n")
+
+ if len(details['sameas']):
+
+ fh.write("same as\n")
+ fh.write("--\n")
+
+ for other in details['sameas']:
+ fh.write("* %s\n" % other)
+ fh.write("\n")
+
+ if options.markdown:
+ fh.close()
+
+ sys.exit()
View
@@ -0,0 +1,137 @@
+{
+ "display_date": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "credit_line": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "date_end": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "period": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "dynasty": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "culture": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "id": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "style": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "date_begin": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "dimensions": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "copyright": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "title": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "provenance": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "credit_line_repro": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "invno": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "thumbnail": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "movement": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "medium": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "media_id": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "description": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "classification_id": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "restrictions": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "school": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "name": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "region": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "caption": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ },
+ "department_id": {
+ "sameas": [],
+ "notes": [],
+ "description": ""
+ }
+}
Oops, something went wrong. Retry.

0 comments on commit 2c5d63c

Please sign in to comment.