|
20 | 20 | READER_PLUGIN = "pyexcel-io reader"
|
21 | 21 | NEW_READER_PLUGIN = "pyexcel-io new reader"
|
22 | 22 | WRITER_PLUGIN = "pyexcel-io writer"
|
| 23 | +NEW_WRITER_PLUGIN = "pyexcel-io new writer" |
23 | 24 |
|
24 | 25 |
|
25 | 26 | class IOPluginInfo(PluginInfo):
|
@@ -83,6 +84,26 @@ def add_a_reader(
|
83 | 84 | )
|
84 | 85 | return self.add_a_plugin_instance(a_plugin_info)
|
85 | 86 |
|
| 87 | + def add_a_writer( |
| 88 | + self, |
| 89 | + relative_plugin_class_path=None, |
| 90 | + locations=(), |
| 91 | + file_types=(), |
| 92 | + stream_type=None, |
| 93 | + ): |
| 94 | + """ add pyexcle-io writer plugin info """ |
| 95 | + a_plugin_info = IOPluginInfo( |
| 96 | + NEW_WRITER_PLUGIN, |
| 97 | + self._get_abs_path(relative_plugin_class_path), |
| 98 | + file_types=[ |
| 99 | + f"{location}-{file_type}" |
| 100 | + for file_type in file_types |
| 101 | + for location in locations |
| 102 | + ], |
| 103 | + stream_type=stream_type, |
| 104 | + ) |
| 105 | + return self.add_a_plugin_instance(a_plugin_info) |
| 106 | + |
86 | 107 |
|
87 | 108 | class IOManager(PluginManager):
|
88 | 109 | """Manage pyexcel-io plugins"""
|
@@ -143,20 +164,19 @@ def get_all_formats(self):
|
143 | 164 | class NewIOManager(IOManager):
|
144 | 165 | def load_me_later(self, plugin_info):
|
145 | 166 | PluginManager.load_me_later(self, plugin_info)
|
146 |
| - _do_additional_registration(plugin_info) |
| 167 | + _do_additional_registration_for_new_plugins(plugin_info) |
147 | 168 |
|
148 | 169 | def register_a_plugin(self, cls, plugin_info):
|
149 | 170 | """ for dynamically loaded plugin """
|
150 | 171 | PluginManager.register_a_plugin(self, cls, plugin_info)
|
151 |
| - _do_additional_registration(plugin_info) |
| 172 | + _do_additional_registration_for_new_plugins(plugin_info) |
152 | 173 |
|
153 | 174 | def get_a_plugin(
|
154 | 175 | self, file_type=None, location=None, library=None, **keywords
|
155 | 176 | ):
|
156 | 177 | __file_type = file_type.lower()
|
157 | 178 | plugin = self.load_me_now(f"{location}-{__file_type}", library=library)
|
158 | 179 | handler = plugin()
|
159 |
| - handler.set_type(__file_type) |
160 | 180 | return handler
|
161 | 181 |
|
162 | 182 | def raise_exception(self, file_type):
|
@@ -194,17 +214,36 @@ def _do_additional_registration(plugin_info):
|
194 | 214 | manager.register_a_file_type(file_type, plugin_info.stream_type, None)
|
195 | 215 |
|
196 | 216 |
|
| 217 | +def _do_additional_registration_for_new_plugins(plugin_info): |
| 218 | + for file_type in plugin_info.tags(): |
| 219 | + manager.register_stream_type( |
| 220 | + file_type.split("-")[1], plugin_info.stream_type |
| 221 | + ) |
| 222 | + manager.register_a_file_type( |
| 223 | + file_type.split("-")[1], plugin_info.stream_type, None |
| 224 | + ) |
| 225 | + |
| 226 | + |
197 | 227 | class FakeReaders:
|
198 | 228 | def get_all_formats(self):
|
199 | 229 | return OLD_READERS.get_all_formats().union(
|
200 | 230 | NEW_READERS.get_all_formats()
|
201 | 231 | )
|
202 | 232 |
|
203 | 233 |
|
| 234 | +class FakeWriters: |
| 235 | + def get_all_formats(self): |
| 236 | + return OLD_WRITERS.get_all_formats().union( |
| 237 | + NEW_WRITERS.get_all_formats() |
| 238 | + ) |
| 239 | + |
| 240 | + |
204 | 241 | OLD_READERS = IOManager(READER_PLUGIN, ioutils.AVAILABLE_READERS)
|
205 |
| -WRITERS = IOManager(WRITER_PLUGIN, ioutils.AVAILABLE_WRITERS) |
| 242 | +OLD_WRITERS = IOManager(WRITER_PLUGIN, ioutils.AVAILABLE_WRITERS) |
| 243 | +NEW_WRITERS = NewIOManager(NEW_WRITER_PLUGIN, ioutils.AVAILABLE_WRITERS) |
206 | 244 | NEW_READERS = NewIOManager(NEW_READER_PLUGIN, ioutils.AVAILABLE_READERS)
|
207 | 245 | READERS = FakeReaders()
|
| 246 | +WRITERS = FakeWriters() |
208 | 247 |
|
209 | 248 |
|
210 | 249 | def load_plugins(plugin_name_patterns, path, black_list, white_list):
|
|
0 commit comments