-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19da982
commit 16b3c90
Showing
14 changed files
with
464 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
''' Reusable generator using plugin pattern ''' | ||
|
||
import os | ||
|
||
import age.templates.template as template | ||
import age.generator.internal as internal_plugin | ||
|
||
def generate(fields, outpath = '', strip_prefix = '', plugins = [internal_plugin]): | ||
includepath = outpath | ||
if includepath and includepath.startswith(strip_prefix): | ||
includepath = includepath[len(strip_prefix):].strip("/") | ||
|
||
directory = {} | ||
for plugin in plugins: | ||
assert('process' in dir(plugin)) | ||
directory = plugin.process(directory, includepath, fields) | ||
|
||
for akey in directory: | ||
afile = directory[akey] | ||
assert(isinstance(afile, template.AGE_FILE)) | ||
if outpath: | ||
print(os.path.join(outpath, afile.fpath)) | ||
with open(os.path.join(outpath, afile.fpath), 'w') as out: | ||
out.write(str(afile)) | ||
else: | ||
print("============== %s ==============" % afile.fpath) | ||
print(str(afile)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
''' Internal plugin process ''' | ||
|
||
import os | ||
|
||
import age.templates.api_tmpl as api | ||
import age.templates.codes_tmpl as codes | ||
import age.templates.grader_tmpl as grader | ||
import age.templates.opera_tmpl as opera | ||
|
||
def process(directory, relpath, fields): | ||
|
||
api_hdr_path = os.path.join(relpath, api.header.fpath) | ||
codes_hdr_path = os.path.join(relpath, codes.header.fpath) | ||
grader_hdr_path = os.path.join(relpath, grader.header.fpath) | ||
opera_hdr_path = os.path.join(relpath, opera.header.fpath) | ||
|
||
# manitory headers | ||
api.header.includes = [ | ||
'"bwd/grader.hpp"' | ||
] | ||
api.source.includes = [ | ||
'"' + codes_hdr_path + '"', | ||
'"' + api_hdr_path + '"', | ||
] | ||
|
||
codes.header.includes = [ | ||
'<string>' | ||
] | ||
codes.source.includes = [ | ||
'<unordered_map>', | ||
'"logs/logs.hpp"', | ||
'"' + codes_hdr_path + '"', | ||
] | ||
|
||
grader.header.includes = [ | ||
'"bwd/grader.hpp"', | ||
'"' + codes_hdr_path + '"', | ||
] | ||
grader.source.includes = [ | ||
'"' + codes_hdr_path + '"', | ||
'"' + api_hdr_path + '"', | ||
'"' + grader_hdr_path + '"', | ||
] | ||
|
||
opera.header.includes = [ | ||
'"ade/functor.hpp"', | ||
'"' + codes_hdr_path + '"', | ||
] | ||
opera.source.includes = [ | ||
'"' + opera_hdr_path + '"' | ||
] | ||
|
||
directory = { | ||
'api_hpp': api.header, | ||
'api_src': api.source, | ||
'codes_hpp': codes.header, | ||
'codes_src': codes.source, | ||
'grader_hpp': grader.header, | ||
'grader_src': grader.source, | ||
'opera_hpp': opera.header, | ||
'opera_src': opera.source, | ||
} | ||
|
||
for akey in directory: | ||
afile = directory[akey] | ||
if 'includes' in fields and afile.fpath in fields['includes']: | ||
afile.includes += fields['includes'][afile.fpath] | ||
afile.process(fields) | ||
|
||
return directory |
Oops, something went wrong.