File indexing completed on 2025-01-05 04:00:27

0001 import os
0002 import sys
0003 import shutil
0004 import inspect
0005 import importlib
0006 import subprocess
0007 sys.path.insert(0, os.path.join(
0008     os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
0009     "examples"
0010 ))
0011 sys.path.insert(0, os.path.join(
0012     os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
0013     "lib"
0014 ))
0015 from lottie.objects.animation import Animation
0016 from lottie.exporters.core import HtmlOutput
0017 
0018 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
0019 example_path = os.path.join(root, "examples")
0020 doxpath = os.path.join(root, "docs", "dox", "examples")
0021 
0022 if len(sys.argv) > 1:
0023     examples = sys.argv[1:]
0024 else:
0025     examples = [
0026         fname[:-3]
0027         for fname in sorted(os.listdir(example_path))
0028         if fname.endswith(".py")
0029     ]
0030 
0031     if os.path.exists(doxpath):
0032         shutil.rmtree(doxpath)
0033 
0034 os.makedirs(doxpath, exist_ok=True)
0035 
0036 for example in examples:
0037     example_fn = os.path.join(example_path, example + ".py")
0038     module = importlib.import_module(example)
0039 
0040     with open(os.path.join(doxpath, example + ".dox"), "w") as f:
0041         f.write("""/*!
0042 \example {example}.py
0043 
0044 \htmlonly[block]
0045 """.format(example=example))
0046 
0047         for obj in vars(module).values():
0048             if isinstance(obj, Animation):
0049                 out = HtmlOutput(obj, f)
0050                 out.style()
0051                 out.body_pre()
0052                 out.body_embedded()
0053                 out.body_post()
0054                 break
0055 
0056         f.write("\\endhtmlonly\n\n")
0057         f.write(inspect.getdoc(module) or "")
0058         f.write("\n\n*/\n\n")