Python Documentation: entree.utils

module name

entree.utils

DESCRIPTION

.. module:: entree.utils
.. moduleauthor:: Julien Spronck
.. created:: Feb 2018

Simple module to create files and directories in a programming project

dependent modules

  • fnmatch
  • jinja2
  • json
  • os
  • six
  • time
  • zipfile

variables

  • CONFIG_DIR
  • CONFIG_FILE_NAME
  •  
  •  

functions

  • copy_file_structure(rootdir, path, replace=None, files_to_ignore=None, partial=None, zipf=None, template_root=None)
    Walks through the file structure and copy all directories and files.

    Args:
    rootdir (str): the root directory where the files will be copied to
    path (str): the path to walk through and reproduce

    Keyword args:
    replace (dict, default=None): dictionary for file name replacement.
    Keys are old file names and values are new file names.
    files_to_ignore (list, default=None): list of file names to ignore.
    partial (list, default=None): list of paths for a partial build.
    Only the paths in the lists will be created.
    zipf (zipfile.ZipFile, default=None)
    template_root (str, default=None): the path to the project template
    directory
    **kwargs: dictionary containing the variables for templating
  • create_dirs(rootdir)
    Creates directories

    Args:
    rootdir (str): the root directory
    dirs (str): directories to create
  • create_general_file(fname, file_content, zipf=None)
    Creates a file.

    Args:
    fname (str): file name
    file_content (iterator): generator/iterator containing
    the file content.

    Keyword args:
    zipf (zipfile.ZipFile, default=None)
  • create_single_file(rootdir, newfilename, template_path, zipf=None)
    Creates a single file from a template.

    Args:
    rootdir (str): the root directory where the file will be created
    newfilename (str): name of the new file
    template_path (str): the path for the template file

    Keyword args:
    zipf (zipfile.ZipFile, default=None)
    **kwargs: dictionary containing the variables for templating
  • filemap(files, replace=None)
    Mapping between file/dir names and their template
    for testing purposes.
  • get_all_dirs_and_files(rootdir, basename='', files_to_ignore=None)
    Get all path names for template directories
  • get_config_dir()
    Returns path for the config directory.
  • get_config_file()
    Returns path of the config file.
  • get_config_param(param, value=None, project_type=None)
    Gets a specific parameter from the config file

    Args:
    param: the name of the parameter to get from the config file

    Keyword Args:
    value (default=None): default value for the parameter if not found
    in the config file
    project_type (str, default=None): project type for project-specific
    configuration

    Returns:
    config parameter
  • read_config()
    Reads the config file

    Returns:
    config: dict containing the configuration
  • render_template(filename)
    Renders a template file given the variables defined in kwargs

    Args:
    filename (str): the filename

    Keyword args:
    **kwargs: dictionary containing the variables needed in the template

    Returns:
    string containing the content of the file after templating
  • replace_pathname(pathname, replace=None)
    Replaces a directory name based on patterns defined in a dictionary

    Args:
    replace (dict, default=None): dictionary with replacement patterns

    Returns:
    new directory name (str)
  • set_config(overwrite=False)
    Sets the config parameters

    Keyword Args:
    overwrite (bool, default=False): Set to True to overwrite an existing
    config file.
    **config: all other keyword args will be used
    as config parameters in the config file.