|
|
@@ -84,7 +84,13 @@ class IndexField: |
|
|
|
class Index(list[tuple[str, str]]): |
|
|
|
'''An index (key-value mapping, possibly with repeated keys) of a file produced by a module''' |
|
|
|
|
|
|
|
fields: tuple[IndexField] = () |
|
|
|
fields: tuple[IndexField] = ( |
|
|
|
IndexField('codearchiver version', required = True, repeatable = False), |
|
|
|
IndexField('Module', required = True, repeatable = False), |
|
|
|
IndexField('ID', required = True, repeatable = False), |
|
|
|
IndexField('Input URL', required = True, repeatable = False), |
|
|
|
IndexField('Filename', required = True, repeatable = False), |
|
|
|
) |
|
|
|
'''The fields for this index''' |
|
|
|
|
|
|
|
_allFieldsCache: typing.Optional[tuple[IndexField]] = None |
|
|
@@ -348,6 +354,9 @@ class Module(metaclass = ModuleMeta): |
|
|
|
name: typing.Optional[str] = None |
|
|
|
'''The name of the module. Modules without a name are ignored. Names must be unique and may only contain a-z and hyphens.''' |
|
|
|
|
|
|
|
IndexClass: typing.Optional[typing.Type[Index]] = None |
|
|
|
'''The Index class corresponding to this module, if any.''' |
|
|
|
|
|
|
|
@staticmethod |
|
|
|
def matches(inputUrl: InputURL) -> bool: |
|
|
|
'''Whether or not this module is for handling `inputUrl`.''' |
|
|
@@ -364,6 +373,19 @@ class Module(metaclass = ModuleMeta): |
|
|
|
def process(self) -> Result: |
|
|
|
'''Perform the relevant retrieval(s)''' |
|
|
|
|
|
|
|
def create_index(self, filename: str) -> Index: |
|
|
|
'''Create a basic Index instance appropriate for this module''' |
|
|
|
|
|
|
|
if type(self).IndexClass is None or type(self).name is None: |
|
|
|
raise RuntimeError('Module lacks an IndexClass or a name; cannot create index') |
|
|
|
idx = type(self).IndexClass() |
|
|
|
idx.append('codearchiver version', codearchiver.version.__version__) |
|
|
|
idx.append('Module', type(self).name) |
|
|
|
idx.append('ID', self._id) |
|
|
|
idx.append('Input URL', self._url) |
|
|
|
idx.append('Filename', filename) |
|
|
|
return idx |
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
return f'{type(self).__module__}.{type(self).__name__}({self._inputUrl!r})' |
|
|
|
|
|
|
|