jfscripts package

Submodules

jfscripts._utils module

class jfscripts._utils.FilePath(path, absolute=False)[source]

Bases: object

_export(path)[source]
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:
  • extension (str) – The extension of the new file path.
  • append (str) – String to append on the basename. This string is located before the extension.
  • del_substring (str) – String to delete from the new file path.
Returns:

A new file path object.

Return type:

FilePath

path = None

The absolute (/home/document/file.ext) or the relative path (document/file.ext) of the file.

remove()[source]

Remove the file.

class jfscripts._utils.Run(*args, **kwargs)[source]

Bases: object

PIPE = -1
_print_cmd(cmd)[source]
check_output(*args, **kwargs)[source]
run(*args, **kwargs)[source]
Returns:A CompletedProcess object.
Return type:subprocess.CompletedProcess
setup(verbose=False, colorize=False)[source]
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:

bool

jfscripts.dns_ipv6_prefix module

jfscripts.dns_ipv6_prefix.get_ipv6(dns_name)[source]
jfscripts.dns_ipv6_prefix.get_parser()[source]

The argument parser for the command line interface.

Returns:A ArgumentParser object.
Return type:argparse.ArgumentParser
jfscripts.dns_ipv6_prefix.main()[source]

jfscripts.extract_pdftext module

class jfscripts.extract_pdftext.Txt(path)[source]

Bases: object

add_line(line)[source]
jfscripts.extract_pdftext.get_page_count(pdf)[source]
jfscripts.extract_pdftext.get_parser()[source]

The argument parser for the command line interface.

Returns:A ArgumentParser object.
Return type:argparse.ArgumentParser
jfscripts.extract_pdftext.get_text_per_page(pdf, page, txt_file)[source]
jfscripts.extract_pdftext.main()[source]

jfscripts.find_dupes_by_size module

jfscripts.find_dupes_by_size.check_for_duplicates(path)[source]
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.find_dupes_by_size.main()[source]

jfscripts.list_files module

jfscripts.list_files._list_files_all(dir_path)[source]
jfscripts.list_files._list_files_filter(dir_path, glob_pattern)[source]
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.common_path(paths)[source]
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.is_glob(string)[source]
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.list_files.main()[source]

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.mac_to_eui64.mac_to_eui64(mac, prefix=None)[source]

Convert a MAC address to a EUI64 address or, with prefix provided, a full IPv6 address

jfscripts.mac_to_eui64.main()[source]

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.

stop()[source]

Stop the time calculation and return the formated result.

Returns:The result
Return type:str
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:
  • width (int) – The width of the image.
  • height (int) – The height of the image.
Returns:

Command line arguments for imagemagicks’ convert.

Return type:

list

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:
Returns:

The return value of subprocess.run.

Return type:

subprocess.CompletedProcess

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:
Returns:

None

jfscripts.pdf_compress.do_tesseract(input_file, languages=['deu', 'eng'])[source]
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.main()[source]

Main function.

Returns:None
jfscripts.pdf_compress.state = None

The global State object.

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_join_convert_pdf(arguments)[source]
jfscripts.pdf_compress.subcommand_samples(input_file, state)[source]

Generate a list of example files with different threshold values.

Parameters:
Returns:

None

jfscripts.pdf_compress.tmp_identifier = 'magick_12572228-b582-11ea-8f6f-0242ac110002'

Used for the identification of temporary files.

jfscripts.pdf_compress.unify_page_size(input_file, output_file, margin=0)[source]

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_magick_identify_dimensions(pdf_file)[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
jfscripts.image_into_pdf.get_pdf_info(pdf_file)[source]
jfscripts.image_into_pdf.main()[source]