TGMtools API docs

Submodules

tgmtools.core Provides basic core functions to be used other Python projects.
tgmtools.obsfuscate Provides basic file related functions to be used in other Python projects.

core

Provides basic core functions to be used other Python projects.

exception tgmtools.core.TGMException

Exception class used in the tgmtools project.

tgmtools.core.convert_nested_defaultdict_to_dict(dd)

Converts a nested collections.defaultdict object to a nested pure Python dictionary structure.

Parameters:dd (collections.defaultdict object that is nested to any degree.) –
Returns:nested_dict
Return type:dict that is equivalent to the original object.
tgmtools.core.make_nested_defaultdict(inner_type, N=1)

Creates an empty nested collections.defaultdict object.

Parameters:
  • inner_type (type of object at the innermost level of the nested collections.defaultdict.) –
  • N (int of the number of nested levels (maximum five).) –
Returns:

empty_nested_defaultdict

Return type:

Nested collections.defaultdict objects that are empty.

tgmtools.core.pf(item)

Convenience function that returns the output of pprint.pformat.

tgmtools.core.pp(item)

Convenience function that prints out the output of pf()

tgmtools.core.pairwise(iterable)

s -> (s0,s1), (s1,s2), (s2, s3), ...

tgmtools.core.memory_used(unit='kB')

Output memory usage with specified units.

Parameters:unit (str specifying unit (case insensitive). Must be a key in all_units.) –
tgmtools.core.all_units

dict of available units and conversion factors from kilobytes.

Returns:memory_used
Return type:str of memory usage with specified unit.

obsfuscate

Provides basic file related functions to be used in other Python projects.

tgmtools.obsfuscate.create_encoded_path(filename, hash_key=None, datetime_object=None)

Creates an encoded path to store files in from a hash_key and a datetime object.

Intended purpose is to prevent subdirectory count limits while providing obfuscation.

Parameters:
  • filename (str of filename to be stored) –
  • hash_key (str key used during the hashing operation) –
  • datetime_object (datetime object used during the hashing operation.) –
Returns:

encoded_path

Return type:

str of encoded path that can be decoded using decode_path().

tgmtools.obsfuscate.decode_path(encoded_path, hash_key=None)

Decodes a path encoded by create_encoded_path() using the same hash_key.

Parameters:
  • encoded_path (str of path encoded by encode_path using the same hash_key) –
  • hash_key (str of key used by encode_path) –
Returns:

  • datetime (datetime object)
  • filename (str of original filename)