jfscripts package

Submodules

jfscripts.utils module

class jfscripts.utils.SubprocessKwarg[source]

Bases: TypedDict

stdout: int
stderr: int
cwd: str
class jfscripts.utils.Run(verbose: bool = False, colorize: bool = False)[source]

Bases: object

PIPE
setup(verbose: bool = False, colorize: bool = False) None[source]
run(cmd: List[str], **kwargs: Unpack) CompletedProcess[str][source]
check_output(cmd: List[str], **kwargs: Unpack) bytes[source]
jfscripts.utils.check_dependencies(*executables: Tuple[str, str] | str, raise_error: bool = True) bool[source]

Check if the given executables are existing in $PATH.

Parameters:
  • executables – 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 – Raise an error if an executable doesn’t exist.

Returns:

True if all executables exist. False if one or more executables not exist.

class jfscripts.utils.FilePath(path: str, absolute: bool = False)[source]

Bases: object

absolute: bool

Boolean value indicating whether the path is an absolute or an relative path.

filename: str

The filename is the combination of the basename and the extension, e. g. file.ext.

extension: str

The extension of the file, e. g. ext.

basename: str

The basename of the file, e. g. file.

base: str

The path without an extension, e. g. /home/document/file.

new(extension: str | None = None, append: str = '', del_substring: str = '') FilePath[source]
Parameters:
  • extension – The extension of the new file path.

  • append – String to append on the basename. This string is located before the extension.

  • del_substring – String to delete from the new file path.

Returns:

A new file path object.

remove() None[source]

Remove the file.

jfscripts.utils.argparser_to_readme(argparser: Callable[[], ArgumentParser], template: str = 'README-template.md', destination: str = 'README.md', indentation: int = 0, placeholder: str = '{{ argparse }}') None[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 – A function that returns an object.

  • template – The path of a template text file containing the placeholder. Default: README-template.md

  • destination – The path of the destination file. Default: README.me

  • indentation – Indent the formatted help output by X spaces. Default: 0

  • placeholder – Placeholder string that gets replaced by the formatted help output. Default: {{ argparse }}

jfscripts.dns_ipv6_prefix module

jfscripts.dns_ipv6_prefix.get_ipv6(dns_name: str) str | None[source]
jfscripts.dns_ipv6_prefix.get_parser() ArgumentParser[source]

The argument parser for the command line interface.

Returns:

A ArgumentParser object.

Return type:

argparse.ArgumentParser

jfscripts.dns_ipv6_prefix.main() None[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_text_per_page(pdf, page, txt_file)[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.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.is_glob(path_spec: str) bool[source]
jfscripts.list_files.common_path(paths: List[str]) str[source]
jfscripts.list_files.list_files(files: List[str], default_glob: str | None = 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.doc_examples(command_name: str = '', extension: str = 'txt', indent_spaces: int = 0, inline: bool = 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.main()[source]

jfscripts.mac_to_eui64 module

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.get_parser()[source]

The argument parser for the command line interface.

Returns:

A ArgumentParser object.

Return type:

argparse.ArgumentParser

jfscripts.mac_to_eui64.main()[source]

jfscripts.image_into_pdf module

jfscripts.image_into_pdf.do_pdftk_cat_first_page(pdf_file: str) str[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.do_magick_identify_dimensions(pdf_file: str)[source]
jfscripts.image_into_pdf.get_pdf_info(pdf_file: str)[source]
jfscripts.image_into_pdf.convert_image_to_pdf_page(image, image_width, pdf_width, pdf_density_x)[source]
jfscripts.image_into_pdf.assemble_pdf(main_pdf: str, insert_pdf: str, page_count: int, page_number: int, mode: Literal['add', 'replace'] = 'add', position: Literal['before', 'after'] = 'before')[source]
Parameters:
  • main_pdf – Path of the main PDF file.

  • insert_pdf – Path of the PDF file to insert into the main PDF file.

  • page_count – Page count of the main PDF file.

  • page_number – Page number in the main PDF file to add / to replace the insert PDF file.

  • mode – 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.get_parser()[source]

The argument parser for the cmd_args line interface.

Returns:

A ArgumentParser object.

Return type:

argparse.ArgumentParser

jfscripts.image_into_pdf.main()[source]