예제 #1
0
 def show_model_info(self, model_info_file):
     model_info = yaml_parser.parse(model_info_file)
     if utils.is_windows():
         placeholders = [15, 40]
     else:
         placeholders = [15, 50]
     tp = TablePrinter(titles=["ModelName", model_info['name']],
                       placeholders=placeholders,
                       title_colors=["yellow", None],
                       title_aligns=["^", "<"])
     tp.add_line(contents=["Type", model_info['type']],
                 colors=["yellow", None],
                 aligns=["^", "<"])
     tp.add_line(contents=["Version", model_info['version']],
                 colors=["yellow", None],
                 aligns=["^", "<"])
     tp.add_line(contents=["Summary", model_info['description']],
                 colors=["yellow", None],
                 aligns=["^", "<"])
     tp.add_line(contents=["Author", model_info['author']],
                 colors=["yellow", None],
                 aligns=["^", "<"])
     tp.add_line(contents=["Author-Email", model_info['author_email']],
                 colors=["yellow", None],
                 aligns=["^", "<"])
     print(tp.get_text())
     return True
예제 #2
0
 def get_config(self):
     yaml_config = {}
     if self.args.config:
         yaml_config = yaml_parser.parse(self.args.config)
     module_config = yaml_config.get("config", {})
     for _config in self.module.processor.configs():
         key = _config['dest']
         module_config[key] = self.args.__dict__[key]
     return module_config
예제 #3
0
 def _generate_module_info(self, module_info=None):
     if not module_info:
         self.module_info = {}
     else:
         if not utils.is_yaml_file(module_info):
             logger.critical("Module info file should be yaml format")
             exit(1)
         self.module_info = yaml_parser.parse(module_info)
     self.author = self.module_info.get('author', 'UNKNOWN')
     self.author_email = self.module_info.get('author_email', 'UNKNOWN')
     self.summary = self.module_info.get('summary', 'UNKNOWN')
     self.type = self.module_info.get('type', 'UNKNOWN')
     self.version = self.module_info.get('version', 'UNKNOWN')
     self.name = self.module_info.get('name', 'UNKNOWN')
예제 #4
0
    def _load_resource_list_file_if_valid(self):
        self.resource_list_file = {}
        if not os.path.exists(self.resource_list_file_path()):
            return False
        file_create_time = os.path.getctime(self.resource_list_file_path())
        now_time = time.time()

        # if file is out of date, remove it
        if now_time - file_create_time >= CACHE_TIME:
            os.remove(self.resource_list_file_path())
            return False
        for resource in yaml_parser.parse(
                self.resource_list_file_path())['resource_list']:
            for key in resource:
                if key not in self.resource_list_file:
                    self.resource_list_file[key] = []
                self.resource_list_file[key].append(resource[key])

        # if file format is invalid, remove it
        if "version" not in self.resource_list_file or "name" not in self.resource_list_file:
            self.resource_list_file = {}
            os.remove(self.resource_list_file_path())
            return False
        return True