jfscripts package¶
Submodules¶
jfscripts._utils module¶
-
class
jfscripts._utils.
FilePath
(path, absolute=False)[source]¶ Bases:
object
-
absolute
= None¶ Boolean, indicates wheter the path is an absolute path or an relative path.
-
base
= None¶ The path without an extension, e. g. /home/document/file.
-
basename
= None¶ The basename of the file, e. g. file.
-
extension
= None¶ The extension of the file, e. g. ext.
-
filename
= None¶ The filename is the combination of the basename and the extension, e. g. file.ext.
-
new
(extension=None, append='', del_substring='')[source]¶ Parameters: Returns: A new file path object.
Return type:
-
path
= None¶ The absolute (/home/document/file.ext) or the relative path (document/file.ext) of the file.
-
-
class
jfscripts._utils.
Run
(*args, **kwargs)[source]¶ Bases:
object
-
PIPE
= -1¶
-
run
(*args, **kwargs)[source]¶ Returns: A CompletedProcess object. Return type: subprocess.CompletedProcess
-
-
jfscripts._utils.
argparser_to_readme
(argparser, template='README-template.md', destination='README.md', indentation=0, placeholder='{{ argparse }}')[source]¶ Add the formatted help output of a command line utility using the Python module argparse to a README file. Make sure to set the name of the program (prop) or you get strange program names.
Parameters: - argparser (object) – The argparse parser object.
- template (str) – The path of a template text file containing the placeholder. Default: README-template.md
- destination (str) – The path of the destination file. Default: README.me
- indentation (int) – Indent the formatted help output by X spaces. Default: 0
- placeholder (str) – Placeholder string that gets replaced by the formatted help output. Default: {{ argparse }}
-
jfscripts._utils.
check_dependencies
(*executables, raise_error=True)[source]¶ Check if the given executables are existing in $PATH.
Parameters: - executables (tuple) – A tuple of executables to check for their existence in $PATH. Each element of the tuple can be either a string (e. g. pdfimages) or a itself a tuple (‘pdfimages’, ‘poppler’). The first entry of this tuple is the name of the executable the second entry is a description text which is displayed in the raised exception.
- raise_error (bool) – Raise an error if an executable doesn’t exist.
Returns: True or False. True if all executables exist. False if one or more executables not exist.
Return type:
jfscripts.dns_ipv6_prefix module¶
-
jfscripts.dns_ipv6_prefix.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
jfscripts.extract_pdftext module¶
-
jfscripts.extract_pdftext.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
jfscripts.find_dupes_by_size module¶
-
jfscripts.find_dupes_by_size.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
jfscripts.list_files module¶
-
jfscripts.list_files.
_split_glob
(glob_path)[source]¶ Split a file path (e. g.: /data/(asterisk).txt) containing glob wildcard characters in a glob free path prefix (e. g.: /data) and a glob pattern (e. g. (asterisk).txt).
Parameters: glob_path (str) – A file path containing glob wildcard characters.
-
jfscripts.list_files.
doc_examples
(command_name='', extension='txt', indent_spaces=0, inline=False)[source]¶
-
jfscripts.list_files.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
-
jfscripts.list_files.
list_files
(files, default_glob=None)[source]¶ Parameters: - files (list) – A list of file paths or a single element list containing a glob string.
- default_glob (string) – A default glob pattern like “(asterisk).txt”. This argument is only taken into account, if “element” is a list with only one entry and this entry is a path to a directory.
jfscripts.mac_to_eui64 module¶
-
jfscripts.mac_to_eui64.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
jfscripts.pdf_compress module¶
-
class
jfscripts.pdf_compress.
State
(args)[source]¶ Bases:
object
This object holds runtime data for the multiprocessing environment.
-
args
= None¶ argparse arguments
-
common_path
= None¶ The common path prefix of all input files.
-
cwd
= None¶ The current working directory
-
first_input_file
= None¶ The first input file.
-
input_files
= None¶ A list of all input files.
-
input_is_pdf
= None¶ Boolean that indicates if the first file is a pdf.
-
-
class
jfscripts.pdf_compress.
Timer
[source]¶ Bases:
object
Class to calculate the execution time. Mainly to test the speed improvements of the multiprocessing implementation.
-
begin
= None¶ UNIX timestamp the execution began.
-
end
= None¶ UNIX timestamp the execution ended.
-
-
jfscripts.pdf_compress.
_do_magick_command
(command)[source]¶ ImageMagick version 7 introduces a new top level command named magick. Use this newer command if present.
Returns: A list of command segments
-
jfscripts.pdf_compress.
_do_magick_convert_enlighten_border
(width, height)[source]¶ Build the command line arguments to enlighten the border in four regions.
Parameters: Returns: Command line arguments for imagemagicks’ convert.
Return type:
-
jfscripts.pdf_compress.
args
= None¶ The argparse object.
-
jfscripts.pdf_compress.
check_threshold
(value)[source]¶ Check if value is a valid threshold value.
Parameters: value (integer or string) – Returns: A normalized threshold string (90%) Return type: string
-
jfscripts.pdf_compress.
cleanup
(state)[source]¶ Delete all images using the temporary identifier in a common path.
Parameters: state (jfscripts.pdf_compress.State) – The state object. Returns: None
-
jfscripts.pdf_compress.
collect_images
(state)[source]¶ Collection all images using the temporary identifier in a common path.
Parameters: state (jfscripts.pdf_compress.State) – The state object. Returns: A sorted list of image paths. Return type: list
-
jfscripts.pdf_compress.
convert_file_paths
(files)[source]¶ Convert a list of file paths in a list of
jfscripts._utils.FilePath
objects.Parameters: files (list) – A list of file paths Returns: a list of jfscripts._utils.FilePath
objects.
-
jfscripts.pdf_compress.
do_magick_convert
(input_file, output_file, threshold=None, enlighten_border=False, border=False, resize=False, deskew=False, trim=False, color=False, quality=75, blur=False)[source]¶ Convert a input image file using the subcommand convert of the imagemagick suite.
Returns: The output image file. Return type: jfscripts._utils.FilePath
-
jfscripts.pdf_compress.
do_magick_identify
(input_file)[source]¶ The different informations of an image.
Parameters: input_file (jfscripts._utils.FilePath) – The input file. Returns: A directory with the keys width, height and colors. Return type: dict
-
jfscripts.pdf_compress.
do_pdfimages
(pdf_file, state, page_number=None, use_tmp_identifier=True)[source]¶ Convert a PDF file to images in the TIFF format.
Parameters: - pdf_file (jfscripts._utils.FilePath) – The input file.
- state (jfscripts.pdf_compress.State) – The state object.
- page_number (int) – Extract only the page with a specific page number.
Returns: The return value of subprocess.run.
Return type:
-
jfscripts.pdf_compress.
do_pdfinfo_page_count
(pdf_file)[source]¶ Get the amount of pages a PDF files have.
Parameters: pdf_file (str) – Path of the PDF file. Returns: Page count Return type: int
-
jfscripts.pdf_compress.
do_pdftk_cat
(pdf_files, state)[source]¶ Join a list of PDF files into a single PDF file using the tool pdftk.
Parameters: - pdf_files (list) – a list of PDF files
- state (jfscripts.pdf_compress.State) – The state object.
Returns: None
-
jfscripts.pdf_compress.
get_parser
()[source]¶ The argument parser for the command line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser
-
jfscripts.pdf_compress.
identifier
= 'magick'¶ To allow better assignment of the output files.
-
jfscripts.pdf_compress.
subcommand_convert_file
(arguments)[source]¶ Manipulate one input file
Parameters: arguments (tuple) – A tuple containing two elements: The first element is the input_file file object and the second element is the state object.
-
jfscripts.pdf_compress.
subcommand_samples
(input_file, state)[source]¶ Generate a list of example files with different threshold values.
Parameters: - input_file (jfscripts._utils.FilePath) – The input file.
- state (jfscripts.pdf_compress.State) – The state object.
Returns: None
-
jfscripts.pdf_compress.
tmp_identifier
= 'magick_12572228-b582-11ea-8f6f-0242ac110002'¶ Used for the identification of temporary files.
jfscripts.image_into_pdf module¶
-
jfscripts.image_into_pdf.
assemble_pdf
(main_pdf, insert_pdf, page_count, page_number, mode='add', position='before')[source]¶ Parameters: - main_pdf (str) – Path of the main PDF file.
- insert_pdf (str) – Path of the PDF file to insert into the main PDF file.
- page_count (int) – Page count of the main PDF file.
- page_number (int) – Page number in the main PDF file to add / to replace the insert PDF file.
- mode (string) – Mode how the PDF to insert is treated. Possible choices are: add or replace.
- position (str) – Possible choices: before and after
-
jfscripts.image_into_pdf.
convert_image_to_pdf_page
(image, image_width, pdf_width, pdf_density_x)[source]¶
-
jfscripts.image_into_pdf.
do_pdftk_cat_first_page
(pdf_file)[source]¶ The cmd_args magick identify is very slow on page pages hence it examines every page. We extract the first page to get some informations about the dimensions of the PDF file.
-
jfscripts.image_into_pdf.
get_parser
()[source]¶ The argument parser for the cmd_args line interface.
Returns: A ArgumentParser object. Return type: argparse.ArgumentParser