예제 #1
0
 def fetch_meta(self) -> MetaInfo:
     metadata_json = self.get_repos_json('mcdreforged.plugin.json')
     metadata = Metadata(metadata_json)
     assert metadata.id == self.id
     self.meta_info = MetaInfo()
     self.meta_info.id = metadata.id
     self.meta_info.name = metadata.name
     self.meta_info.version = str(metadata.version)
     self.meta_info.repository = self.repository
     self.meta_info.labels = list(map(lambda l: l.id, self.labels))
     self.meta_info.authors = list(map(lambda a: a.name, self.authors))
     self.meta_info.dependencies = dict(
         map(lambda t: (str(t[0]), str(t[1])),
             metadata.dependencies.items()))
     self.meta_info.requirements = list(
         filter(
             lambda l: len(l) > 0,
             map(
                 lambda l: l.split('#', 1)[0].strip(),
                 self.get_repos_text('requirements.txt',
                                     default='').splitlines())))
     if isinstance(metadata.description, str):
         self.meta_info.description = {
             DEFAULT_LANGUAGE: metadata.description
         }
     elif isinstance(metadata.description, dict):
         self.meta_info.description = metadata.description
     else:
         self.meta_info.description = {}
     if isinstance(self.meta_info.description, str):
         self.meta_info.description = {
             DEFAULT_LANGUAGE: self.meta_info.description
         }
     print('Fetched meta info of {}'.format(self.id))
     return self.meta_info
예제 #2
0
 def _on_load(self):
     super()._on_load()
     self._load_entry_instance()
     self._set_metadata(
         Metadata(getattr(self.entry_module_instance, 'PLUGIN_METADATA',
                          None),
                  plugin=self))
예제 #3
0
def make_packed_plugin(input_dir: str, output_dir: str, file_name: Optional[str], *, quiet: bool = False):
	writeln = print if not quiet else lambda *args, **kwargs: None

	if not os.path.isdir(input_dir):
		writeln('Invalid input directory {}'.format(input_dir))
		return
	if not os.path.isdir(output_dir):
		os.makedirs(output_dir)

	meta_file_path = os.path.join(input_dir, plugin_constant.PLUGIN_META_FILE)
	req_file_path = os.path.join(input_dir, plugin_constant.PLUGIN_REQUIREMENTS_FILE)
	if not os.path.isfile(meta_file_path):
		writeln('Plugin metadata file {} not found'.format(meta_file_path))
		return
	try:
		with open(meta_file_path, encoding='utf8') as meta_file:
			meta_dict = json.load(meta_file)  # type: dict
		assert isinstance(meta_dict, dict)
		meta = Metadata(meta_dict)
	except Exception as e:
		writeln('Fail to load plugin metadata from {}: {}'.format(meta_file_path, e))
		return
	writeln('Plugin ID: {}'.format(meta.id))
	writeln('Plugin version: {}'.format(meta.version))
	if file_name is None:
		file_name = meta.archive_name
	if file_name is None:
		file_name = '{}-v{}'.format(meta.name.replace(' ', '') or meta.id, meta.version)
	file_name = file_name.format(id=meta.id, version=meta.version) + plugin_constant.PACKED_PLUGIN_FILE_SUFFIX

	def write(base_path: str, *, directory_only: bool):
		if os.path.isdir(base_path):
			dir_arc = os.path.basename(base_path)
			zip_file.write(base_path, arcname=dir_arc)
			writeln('Creating directory: {} -> {}'.format(base_path, dir_arc))
			for dir_path, dir_names, file_names in os.walk(base_path):
				if os.path.basename(dir_path) == '__pycache__':
					continue
				for file_name_ in file_names + dir_names:
					full_path = os.path.join(dir_path, file_name_)
					if os.path.isdir(full_path) and os.path.basename(full_path) == '__pycache__':
						continue
					arc_name = os.path.join(os.path.basename(base_path), full_path.replace(base_path, '', 1).lstrip(os.sep))
					zip_file.write(full_path, arcname=arc_name)
					writeln('  Writing: {} -> {}'.format(full_path, arc_name))
		elif os.path.isfile(base_path) and not directory_only:
			arc_name = os.path.basename(base_path)
			zip_file.write(base_path, arcname=arc_name)
			writeln('Writing single file: {} -> {}'.format(base_path, arc_name))

	writeln('Packing plugin "{}" into "{}" ...'.format(meta.id, file_name))
	with ZipFile(os.path.join(output_dir, file_name), 'w', ZIP_DEFLATED) as zip_file:
		write(meta_file_path, directory_only=False)  # metadata
		write(req_file_path, directory_only=False)  # requirement
		write(os.path.join(input_dir, meta.id), directory_only=True)  # source module
		for resource_path in meta.resources:  # resources
			write(os.path.join(input_dir, resource_path), directory_only=False)

	writeln('Done')
예제 #4
0
 def __init__(self, plugin_manager):
     super().__init__(plugin_manager)
     self._set_metadata(Metadata(METADATA, plugin=self))
     self.command_help = HelpCommand(self)
     self.command_status = StatusCommand(self)
     self.command_reload = ReloadCommand(self)
     self.command_permission = PermissionCommand(self)
     self.command_plugin = PluginCommand(self)
     self.command_check_update = CheckUpdateCommand(self)
     self.command_preference = PreferenceCommand(self)
 def _on_load(self):
     super()._on_load()
     try:
         meta_file = self.open_file(plugin_constant.PLUGIN_META_FILE)
     except:
         raise IllegalPluginStructure('Metadata file {} not found'.format(
             plugin_constant.PLUGIN_META_FILE)) from None
     with meta_file:
         self._set_metadata(Metadata(json.load(meta_file), plugin=self))
     self.__check_requirements()
     self._check_subdir_legality()
예제 #6
0
 def __load_instance(self):
     self.file_hash = self.get_file_hash()
     with GLOBAL_LOAD_LOCK:
         previous_modules = sys.modules.copy()
         self.old_module_instance = self.module_instance
         try:
             self.module_instance = misc_util.load_source(self.file_path)
         finally:
             self.newly_loaded_module = [
                 module for module in sys.modules
                 if module not in previous_modules
             ]
             self.mcdr_server.logger.debug(
                 'Newly loaded modules of {}: {}'.format(
                     self, self.newly_loaded_module),
                 option=DebugOption.PLUGIN)
     self.__metadata = Metadata(
         self, getattr(self.module_instance, 'PLUGIN_METADATA', None))
     self.plugin_registry.clear()
예제 #7
0
 def __init__(self, plugin_manager):
     super().__init__(plugin_manager)
     self._set_metadata(Metadata(METADATA, plugin=self))
     self.__mcdr_server = plugin_manager.mcdr_server
     self.tr = self.__mcdr_server.tr
예제 #8
0
 def __init__(self, plugin_manager):
     super().__init__(plugin_manager)
     self.metadata = Metadata(self, METADATA)
     self.tr = plugin_manager.mcdr_server.tr