Documentation for pdfebc¶
core¶
This module contains the core functions of the pdfebc program. These consist mostly of functions that manipulate PDF files and the file system.
-
pdfebc.core.compress_multiple_pdfs(source_directory, output_directory, ghostscript_binary, status_callback=None)[source]¶ Compress all PDF files in the current directory and place the output in the given output directory.
Parameters: Returns: paths to outputs.
Return type: list(str)
cli¶
This module contains the argument parser for the pdfebc program.
-
pdfebc.cli.create_argparser()[source]¶ Returns: The argument parser for pdfebc. Return type: argparse.ArgumentParser
utils¶
Module containing util functions for the pdfebc program.
The SMTP server and port are configured in the config.cnf file.
Requires a config file called ‘email.cnf’ in the user conf directory specified by appdirs. In the case of Arch Linux, this is ‘$HOME/.config/pdfebc/config.cnf’, but this may vary with distributions. The config file should have the following format:
-
pdfebc.utils.attach_files(filepaths, email_)[source]¶ Take a list of filepaths and attach the files to a MIMEMultipart.
Parameters:
-
pdfebc.utils.check_config(config)[source]¶ Check that all sections of the config contain the keys that they should.
Parameters: config (defaultdict) – A defaultdict. Raises: ConfigurationError
-
pdfebc.utils.config_parser_to_defaultdict(config_parser)[source]¶ Convert a ConfigParser to a defaultdict.
Parameters: config_parser (ConfigParser) – A ConfigParser.
-
pdfebc.utils.config_to_string(config)[source]¶ Nice output string for the config, which is a nested defaultdict.
Parameters: config (defaultdict(defaultdict)) – The configuration information. Returns: A human-readable output string detailing the contents of the config. Return type: str
-
pdfebc.utils.create_config(sections, section_contents)[source]¶ Create a config file from the provided sections and key value pairs.
Parameters: Returns: A ConfigParser.
Return type: configparser.ConfigParser
Raises: ValueError
-
pdfebc.utils.if_callable_call_with_formatted_string(callback, formattable_string, *args)[source]¶ If the callback is callable, format the string with the args and make a call. Otherwise, do nothing.
Parameters: - callback (function) – May or may not be callable.
- formattable_string (str) – A string with ‘{}’s inserted.
- *args – A variable amount of arguments for the string formatting. Must correspond to the
- of '{}'s in 'formattable_string'. (amount) –
Raises: ValueError
-
pdfebc.utils.read_config(config_path='/home/docs/.config/pdfebc/config.cnf')[source]¶ Read the config information from the config file.
Parameters: config_path (str) – Relative path to the email config file. Returns: A defaultdict with the config information. Return type: defaultdict Raises: IOError
-
pdfebc.utils.run_config_diagnostics(config_path='/home/docs/.config/pdfebc/config.cnf')[source]¶ Run diagnostics on the configuration file.
Parameters: config_path (str) – Path to the configuration file. Returns: The path to the configuration file, a set of missing sections and a dict that maps each section to the entries that have either missing or empty options. Return type: str, Set[str], dict(str, Set[str])
-
pdfebc.utils.section_is_healthy(section, expected_keys)[source]¶ Check that the section contains all keys it should.
Parameters: - section (defaultdict) – A defaultdict.
- expected_keys (Iterable) – A Set of keys that should be contained in the section.
Returns: True if the section is healthy, false if not.
Return type: boolean
-
pdfebc.utils.send_email(email_, config)[source]¶ Send an email.
Parameters: - email (email.MIMEMultipart) – The email to send.
- config (defaultdict) – A defaultdict.
-
pdfebc.utils.send_files_preconf(filepaths, config_path='/home/docs/.config/pdfebc/config.cnf', status_callback=None)[source]¶ Send files using the config.ini settings.
Parameters: filepaths (list(str)) – A list of filepaths.
-
pdfebc.utils.send_with_attachments(subject, message, filepaths, config)[source]¶ Send an email from the user (a gmail) to the receiver.
Parameters:
-
pdfebc.utils.try_get_conf(config, section, attribute)[source]¶ Try to parse an attribute of the config file.
Parameters: Returns: The string corresponding to the section and attribute.
Return type: Raises: ConfigurationError