geoips.filenames package#

Submodules#

geoips.filenames.base_paths module#

Module for setting paths used throughout GeoIPS.

This module sets various directory paths required for GeoIPS. Setting these variables here keeps geoips code and outputs consolidated. Eventually, we aim to supplant this method of setting variables with a config file. GEOIPS_OUTDIRS serves as the base reference for all other variables and defaults to the current directory.

The module defaults to the values set in environment variables for all other variables. It also provides a function for creating directories.

Functions#

  • get_env_var: Retrieve an environment variable or a provided default value.

  • initialize_paths: Returns a dictionary with GeoIPS directories and variables.

  • make_dirs: Create directories if they don’t already exist.

- PATHS
Type:

Dictionary with initialized paths for various GeoIPS directories and URLs.

Environment Variables
- GEOIPS_OUTDIRS (required)
Type:

Base output directory for GeoIPS.

geoips.filenames.base_paths.get_env_var(var_name, default, rstrip_path=True)[source]#

Retrieve environment variable or provided default, optionally rstrip a ‘/’.

Parameters:
  • var_name (str) – The name of the environment variable.

  • default (str) – The default value to return if the environment variable is not set.

  • rstrip_path (bool, optional) – If True, strip trailing slashes from the returned path (default is True).

Returns:

The value of the environment variable or the default value if not set.

Return type:

str

geoips.filenames.base_paths.initialize_paths()[source]#

Initialize and return a dictionary of paths used throughout GeoIPS.

Returns:

A dictionary containing various paths used by GeoIPS.

Return type:

dict

Raises:

KeyError – If the required environment variable GEOIPS_OUTDIRS is not set.

geoips.filenames.base_paths.make_dirs(path)[source]#

Make directories, catching exceptions if directory already exists.

Parameters:

path (str) – Path to directory to create

Returns:

Path if successfully created

Return type:

str

geoips.filenames.duplicate_files module#

Module to handle removing duplicate files, based on filename formats.

If an individual filename format has a method named "<filename_formatter>_remove_duplicates" defined, use that method to remove duplicates for the given current filename.

geoips.filenames.duplicate_files.remove_duplicates(fnames, remove_files=False)[source]#

Remove duplicate files from all filenames included in dict fnames.

Parameters:
  • fnames (dict) – Dictionary with individual filenames as keys, and a field named “filename_formatter” which indicates the filename format used to generate the given filename.

  • remove_files (bool, optional) – Specify whether to remove files (True), or just list what would have been removed, default to False

Returns:

  • removed_files (list) – List of files that were removed.

  • saved_files (list) – List of files that were not removed.

Module contents#

geoips.filenames init file.