-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pulled module paths up (i.e. module/enum and module/struct instead of…
… struct/module) and applied them to all tags. Codegen adds __init__.py file to this path where the module attributes are set.
- Loading branch information
Showing
3 changed files
with
56 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
from codegen.naming_conventions import clean_comment_str, name_module | ||
|
||
class Module: | ||
|
||
def __init__(self, parser, element): | ||
self.parser = parser | ||
self.element = element | ||
self.read(element) | ||
self.write(parser.path_dict[name_module(element.attrib["name"])]) | ||
|
||
def read(self, element): | ||
self.comment_str = clean_comment_str(element.text, indent="", class_comment='"""')[2:] | ||
self.priority = int(element.attrib.get("priority","")) | ||
self.depends = [name_module(module) for module in element.attrib.get("depends","").split(" ")] | ||
self.custom = bool(eval(element.attrib.get("custom","true").replace("true","True").replace("false","False"),{})) | ||
|
||
def write(self, rel_path): | ||
file = open(os.path.join(os.getcwd(), "generated", rel_path, "__init__.py"), "w", encoding=self.parser.encoding) | ||
file.write(self.comment_str) | ||
file.write(f'\n\n__priority__ = {repr(self.priority)}') | ||
file.write(f'\n__depends__ = {repr(self.depends)}') | ||
file.write(f'\n__custom__ = {repr(self.custom)}') | ||
file.write(f'\n') |
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