# -*- coding: UTF-8 -*- import sys import os for path in [os.getcwd(), "SchemaExamples"]: sys.path.insert(1, path) #Pickup libs from shipped lib directory import logging logging.basicConfig(level=logging.INFO) # dev_appserver.py --log_level debug . log = logging.getLogger(__name__) from schemaexamples import Example, SchemaExamples """ Load examples from file write back to another file """ SchemaExamples.loadExamplesFile("data/ext/pending/issue-894-examples.txt") #print(SchemaExamples.examplesForTerm("Event")) #filename = "out" + term.id +".html" filename = "SchemaExamples/example-code/out" exes = sorted(SchemaExamples.allExamples(), key=lambda x: (x.exmeta['file'], x.exmeta['filepos'])) f = open(filename, "w") for ex in exes: f.write(ex.serialize()) f.write("\n") f.close()
log = logging.getLogger(__name__) from schemaexamples import SchemaExamples, Example exfiles = [] import glob globpatterns = ["data/*examples.txt", "data/ext/*/*examples.txt"] files = [] for g in globpatterns: files.extend(glob.glob(g)) log.info("Loading %d files" % len(files)) for f in files: #log.info("Loading: %s" % f) SchemaExamples.loadExamplesFile(f) log.info("Loaded %s examples" % SchemaExamples.count()) log.info("Processing") #Example.nextIdReset() changedFiles = [] changedCount = 0 for ex in SchemaExamples.allExamples(sort=True): if not ex.hasValidId(): ex.setKey(Example.nextId()) changedCount += 1 if not ex.getMeta('file') in changedFiles: changedFiles.append(ex.getMeta('file'))