utils module

utils.confirmFile(path)[source]

Confirm if a path is a valid file path.

Parameters:

path (str) – path to file

Raises:

OSError – if path is not file or does not exists

Returns:

the same path, if valid

Return type:

str

utils.confirmPath(path)[source]

Confirm if a path is a valid directory path.

Parameters:

path (str) – path to dir

Raises:

OSError – if path is not dir or does not exists

Returns:

the same path, if valid

Return type:

string

utils.cssHash(search_files)[source]

Hash the css classes and return a tuple

Parameters:

search_files (list) – list of all files founded

Returns:

(classes_dict, css_files, count)
  • classes_dict (list): list of dicts ({class: hashed}) of the hashed css classes

  • css_files (list): list of tuples ([(root, file)]) of css files

  • count (int): counter of the files altered

Return type:

tuple

utils.getFiles(search_files, extension)[source]

Get the list of files, separate and filter them by the extension and returns a tuple of (root, file)

Parameters:
  • search_files (list) – list of all files searched

  • extension (str) – extension type

Returns:

list of tuples [(root, file)] of the selected extension
  • root (str): root path for the file (without the filename)

  • file (str): filename

Return type:

list

utils.getVars(file)[source]

Get and prepare the vars to use for a single file; Being the name, extension, new name and content (based on the proper regex) on the file.

Parameters:

file (str) – path to the file

Returns:

(new_name, classes_file)
  • new_name (str): the new name with the minifier extension

  • classes_file (list): the content of the file extracted from the regex

Return type:

tuple

utils.htmlHash(search_files, classes_dict, css_files)[source]

Hash the html files and return a count of files altered

Parameters:
  • search_files (list) – list of all files founded

  • classes_dict (list) – list of dicts ({class: hashed}) of the hashed css classes

  • css_files (list) – list of tuples ([(root, file)]) of css files

Returns:

count of the html files altered

Return type:

int

utils.loadConfig()[source]

Initialize the config.json file and config var

Returns:

config dictionary

Return type:

dict

utils.loadPath(path='')[source]

Loads the PATH to the dir with the files to convert

Parameters:

path (str, optional) – path of the dir (in config.json defaults to ‘examples’). Defaults to ‘’.

Returns:

the path of the dir to convert the files

Return type:

str

utils.lookFiles(path)[source]

Look for the files to convert. Find all files with matching extensions out of config.json

  • Use _PATH as the root.

  • Ignore the dirs as specified in config[‘dirsIgnore’]

  • Select files with extensions as specified in config[‘filesSearch’]

  • Ignore files with extensions as specified in config[‘filesIgnore’]

Parameters:

path (str) – path to convert the files

Returns:

list of tuples [(root, file)] of all the files founded (given the extension on config.json)

Return type:

list

utils.read(file)[source]

Basic functions to read contents of files.

Parameters:

file (str) – path of the file

Returns:

lines of the file

Return type:

list

utils.write(root, new_name, lines)[source]

Basic functions to write in a file.

Parameters:
  • root (str) – path of the root for the file

  • new_name (str) – new name of the file

  • lines (list) – list of the string to write