forked from OpenNaja/cobra-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.py
28 lines (22 loc) · 1.02 KB
/
Module.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
from .BaseClass import BaseClass
class Module:
def __init__(self, parser, element, gen_dir):
self.parser = parser
self.element = element
self.gen_dir = gen_dir
self.read(element)
self.write(parser.path_dict[element.attrib["name"]])
def read(self, element):
self.comment_str = element.text
self.priority = int(element.attrib.get("priority", "0"))
self.depends = [module for module in element.attrib.get("depends", "").split()]
self.custom = element.attrib.get("custom", "False")
def write(self, module_path):
init_path = BaseClass.get_out_path(os.path.join(module_path, "__init__"), gen_dir=self.gen_dir)
with open(init_path, "w", encoding=self.parser.encoding) as file:
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__ = {self.custom}')
file.write(f'\n')