Commits

Jonathan Fine committed cbc9f11

Add add_formulas_to_aos and md5_key_formulas.

  • Participants
  • Parent commits 643ec4b
  • Branches populate

Comments (0)

Files changed (2)

 
 if __name__ == '__main__':
 
-    import shutil
-
     # Create a clean local aos.
     # TODO: Find the true home for this code.
+    # TODO: Appears in both ao.py and populate.py
+    import shutil
     try:
         shutil.rmtree(os.path.join('local', 'aos'))
         print 'ok'

File aos/populate.py

     return png_bytes
 
 
+def add_formulas_to_aos(aos_path, formula_path_pairs):
+
+    for formula, path in formula_path_pairs:
+
+        ao = create_ao(formula)
+        ao.write(aos_path, path)
+
+
+def md5_key_formulas(formulas):
+    '''Convert formulas into key-value pairs.'''
+
+    # TODO: Key to come first?
+    import hashlib
+    formula_path_pairs = tuple(
+        (formula, hashlib.md5(formula).hexdigest())
+        for formula in formulas
+        )
+    return formula_path_pairs
+
+
 if __name__ == '__main__':
 
     ao = create_ao('2 + 2 = 4')
     print repr(ao)
+
+    formulas = (
+        '1 + 1 = 2',
+        'x^2 + y^2 = z^2',
+        'E = mc^2',
+        )
+
+    # Create a clean local aos.
+    # TODO: Find the true home for this code.
+    # TODO: Appears in both ao.py and populate.py
+    import shutil
+    try:
+        shutil.rmtree(os.path.join('local', 'aos'))
+        print 'ok'
+    except OSError:
+        pass
+    os.makedirs(os.path.join('local', 'aos/-1/'))
+
+    formula_path_pairs = md5_key_formulas(formulas)
+    add_formulas_to_aos('./local/aos/-1/c/amsmath', formula_path_pairs)
+
+