general_tools package

Submodules

general_tools.file_utils module

general_tools.file_utils.add_contents_to_zip(zip_file, path, include_root=False)[source]

Zip the contents of <path> into <zip_file>.

Parameters:
  • zip_file (str|unicode) – The file name of the zip file
  • path (str|unicode) – Full path of the directory to zip up
  • include_root (bool) – If true, the zip file will start with the directory of the path parameter
general_tools.file_utils.add_file_to_zip(zip_file, file_name, arc_name=None, compress_type=None)[source]

Zip <file_name> into <zip_file> as <arc_name>.

Parameters:
  • zip_file (str|unicode) – The file name of the zip file
  • file_name (str|unicode) – The name of the file to add, including the path
  • arc_name (str|unicode) – The new name, with directories, of the file, the same as filename if not given
  • compress_type (str|unicode) –
general_tools.file_utils.copy_tree(src, dst, symlinks=False, ignore=None)[source]

Recursively copy a directory and all subdirectories.

Parameters same as shutil.copytree

Parameters:
  • src
  • dst
  • symlinks
  • ignore
Returns:

general_tools.file_utils.get_files(directory, relative_paths=False, include_directories=False, topdown=False, extensions=None, exclude=None)[source]
general_tools.file_utils.get_mime_type(path)[source]
general_tools.file_utils.get_subdirs(dir, relative_paths=False, topdown=False)[source]
general_tools.file_utils.load_json_object(file_name, default=None)[source]

Deserialized JSON file <file_name> into a Python dict. :param str|unicode file_name: The name of the file to read :param default: The value to return if the file is not found

general_tools.file_utils.load_yaml_object(file_name, default=None)[source]

Deserialized YAML file <file_name> into a Python dict. :param str|unicode file_name: The name of the file to read :param default: The value to return if the file is not found

general_tools.file_utils.make_dir(dir_name, linux_mode=493, error_if_not_writable=False)[source]

Creates a directory, if it doesn’t exist already.

If the directory does exist, and <error_if_not_writable> is True, the directory will be checked for writability.

Parameters:
  • dir_name (str|unicode) – The name of the directory to create
  • linux_mode (int) – The mode/permissions to set for the new directory expressed as an octal integer (ex. 0o755)
  • error_if_not_writable (bool) – The name of the file to read
general_tools.file_utils.read_file(file_name, encoding=u'utf-8-sig')[source]
general_tools.file_utils.remove(file_path, ignore_errors=True)[source]
general_tools.file_utils.remove_tree(dir_path, ignore_errors=True)[source]
general_tools.file_utils.unzip(source_file, destination_dir)[source]

Unzips <source_file> into <destination_dir>.

Parameters:
  • source_file (str|unicode) – The name of the file to read
  • destination_dir (str|unicode) – The name of the directory to write the unzipped files
general_tools.file_utils.write_file(file_name, file_contents, indent=None)[source]

Writes the <file_contents> to <file_name>.

If <file_contents> is not a string, it is serialized as JSON.

Parameters:
  • file_name (str|unicode) – The name of the file to write
  • file_contents (str|unicode|object) – The string to write or the object to serialize
  • indent (int) – Specify a value if you want the output formatted to be more easily readable

general_tools.print_utils module

general_tools.print_utils.print_error(error_msg, indent=0)[source]
general_tools.print_utils.print_notice(notice_msg, indent=0)[source]
general_tools.print_utils.print_ok(ok_header, ok_message, indent=0)[source]
general_tools.print_utils.print_warning(warning_msg, indent=0)[source]
general_tools.print_utils.print_with_header(header, message, color, indent=0)[source]

Use one of the functions below for printing, not this one.

general_tools.smartquotes module

general_tools.smartquotes.smartquotes(text)[source]

Runs text through pandoc for smartquote correction.

This script accepts a paragraph of input and outputs typographically correct text using pandoc. Note line breaks are not retained.

general_tools.url_utils module

general_tools.url_utils.clean_url_segment(segment)[source]
general_tools.url_utils.download_file(url, outfile)[source]

Downloads a file and saves it.

general_tools.url_utils.get_languages()[source]

Returns an array of over 7000 dictionaries.

Structure: [

{
cc: [“DJ”, “US”, “CA”], pk: 2, lr: “Africa”, ln: “Afaraf”, ang: “Afar”, gw: false, ld: “ltr”, alt: [“Afaraf”, “Danakil”], lc: aa

]

general_tools.url_utils.get_url(url, catch_exception=False)[source]
Parameters:
  • url (str|unicode) – URL to open
  • catch_exception (bool) – If <True> catches all exceptions and returns <False>
general_tools.url_utils.join_url_parts(*args)[source]

Joins a list of segments into a URL-like string.

Module contents