unidown.plugin¶
- exception PluginError(msg='')[source]¶
Bases:
Exception
Base class for exceptions in a plugin. If catching this, it is implicit that the plugin is unable to work further.
- Parameters
msg (
str
) – message
- class APlugin(settings, options=None)[source]¶
Bases:
ABC
Abstract class of a plugin. Provides all needed variables and methods.
- Parameters
- Raises
PluginError – Can not create default plugin paths.
- abstract _create_download_data()[source]¶
Get the download links in a specific format.
Note
Has to be implemented inside Plugins.
- Raises
NotImplementedError – Abstract method.
- Return type
- abstract _create_last_update_time()[source]¶
Get the newest update time from the referencing data.
Note
Has to be implemented inside Plugin.
- Raises
NotImplementedError – Abstract method.
- Return type
- _load_default_options()[source]¶
Load default options if they were not passed at creation.
- Return type
- check_download(link_item_dict, folder, log=False)[source]¶
Check if the download of the given dict was successful. No proving if the content of the file is correct too.
- Parameters
link_item_dict (
LinkItemDict
) – Items to check.folder (
Path
) – Folder where the downloads are saved.log (
bool
) – Log lost items.
- Return type
- Returns
Succeed.
- download(link_items, folder, desc, unit)[source]¶
Download the given LinkItem dict from the plugins host, to the given path. Proceeded with multiple connections.
_simul_downloads
. Aftercheck_download()
is recommended.This function don’t use an internal link_item_dict, delay or folder directly set in options or instance vars, because it can be used aside of the normal download routine inside the plugin itself for own things. As of this it still needs access to the logger, so a staticmethod is not possible.
Warning
The parameters may change in future versions. (e.g. change order and accept another host)
- Parameters
link_items (
LinkItemDict
) – Data which gets downloaded.folder (
Path
) – Target download folder.desc (
str
) – Description of the progressbar.unit (
str
) – Unit of the download, shown in the progressbar.
- Return type
- download_as_file(url, target_file, delay=0)[source]¶
Download the given url to the given target folder.
- load_savestate()[source]¶
Load the save of the plugin.
- Raises
PluginError – Broken savestate json.
PluginError – Different savestate versions.
PluginError – Different plugin versions.
PluginError – Different plugin names.
PluginError – Could not parse the json.
- Return type
- save_savestate()[source]¶
Save meta data about the downloaded things and the plugin to a file.
- Return type
- update_download_data()[source]¶
Update the download links. Calls
_create_download_data()
.- Return type
- update_last_update()[source]¶
Call this to update the latest update time. Calls
_create_last_update_time()
.- Return type
- update_savestate(new_items)[source]¶
Update savestate.
- Parameters
new_items (
LinkItemDict
) – New items.- Return type
- _INFO: PluginInfo = <unidown.plugin.plugin_info.PluginInfo object>¶
Meta information about the plugin.
- _abc_impl = <_abc._abc_data object>¶
- _download_data: LinkItemDict¶
Referencing data.
- _downloader: HTTPSConnectionPool¶
Downloader which will download the data.
- _options: dict[str, Any]¶
Options which the plugin uses internally, should be used for the given options at initialization.
- property download_data: LinkItemDict¶
Plain getter.
- Return type
- property info: PluginInfo¶
Plain getter.
- Return type
- class LinkItem(name, time)[source]¶
Bases:
object
Item which represents the data, who need to be downloaded. Has a name and an update time.
- Parameters
- Raises
ValueError – name cannot be empty or None
ValueError – time cannot be empty or None
- classmethod from_json(data)[source]¶
Construct from json dict.
- Parameters
data (
dict
) – Json data as dict.- Return type
- Returns
LinkItem.
- Raises
ValueError – Missing parameter.
- class LinkItemDict[source]¶
Bases:
dict
LinkItem dictionary, acts as a wrapper for special methods and functions.
- actualize(new_data, log=None)[source]¶
Actualize dictionary like ~dict.update does. If a logger is passed it will log updated items, not new one.
- Parameters
new_data (
LinkItemDict
) – Data used for updating.
- Return type
- static get_new_items(old_data, new_data, disable_tqdm=False)[source]¶
Get the new items which are not existing or are newer as in the old data set.
- Parameters
old_data (
LinkItemDict
) – Old data.new_data (
LinkItemDict
) – New data.disable_tqdm (
bool
) – Disable tqdm progressbar.
- Return type
- Returns
New and updated link items.
- class PluginInfo(name, version, host)[source]¶
Bases:
object
Information about the module. This information will be saved into the save files as well.
- Parameters
- Raises
ValueError – Name is empty.
ValueError – Host is empty.
InvalidVersion – Version is not PEP440 conform.
- classmethod from_json(data)[source]¶
Construct from json dict.
- Parameters
data (
dict
) – Json data as dict.- Return type
- Returns
Plugin info.
- Raises
ValueError – Name is missing.
ValueError – Version is missing.
ValueError – Host is missing.
- class SaveState(plugin_info, last_update, link_items, version=<Version('1')>)[source]¶
Bases:
object
Savestate of a plugin.
- Parameters
version (
Version
) – Savestate version.plugin_info (
PluginInfo
) – Plugin info.last_update (
datetime
) – Last udpate time of the referenced data.link_items (
LinkItemDict
) – Data.version – Savestate version.
- classmethod from_json(data)[source]¶
- Parameters
data (
dict
) – Json data as dict.- Return type
- Returns
SaveState.
- Raises
ValueError – Version of SaveState does not exist or is empty.
InvalidVersion – Version is not PEP440 conform.
- upgrade()[source]¶
Upgrading current savestate to the latest savestate version.
- Return type
- Returns
Upgraded savestate.
- link_items: LinkItemDict¶
Data.
- plugin_info: PluginInfo¶
Plugin info.
Modules
Default exceptions of plugins. |
|