general_tools package

Submodules

general_tools.file_utils module

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

Zip the contents of <path> into <zip_file>. :param str|unicode zip_file: The file name of the zip file :param str|unicode path: Full path of the directory to zip up

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>. :param str|unicode zip_file: The file name of the zip file :param str|unicode file_name: The name of the file to add, including the path :param str|unicode arc_name: The new name, with directories, of the file, the same as filename if not given :param str|unicode compress_type:

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 :param src: :param dst: :param symlinks: :param ignore: :return:

general_tools.file_utils.get_files(dir, relative_paths=False, include_directories=False, topdown=False)[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 <file_name> into a Python object :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. :param str|unicode dir_name: The name of the directory to create :param int linux_mode: The mode/permissions to set for the new directory expressed as an octal integer (ex. 0o755) :param bool error_if_not_writable: 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>. :param str|unicode source_file: The name of the file to read :param str|unicode destination_dir: 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. :param str|unicode file_name: The name of the file to write :param str|unicode|object file_contents: The string to write or the object to serialize :param int indent: 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

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

general_tools.smartquotes.smartquotes(text)[source]

Runs text through pandoc for smartquote correction.

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 :type args: List<string>

Module contents