fastwater.otm_gpl.files module

@note … this work is based on a collaborative effort of the Telemac-Mascaret consortium

@history 15/11/2011 – Sebastien E. Bourban

Addition of diff_text_files, a differential tool, which is called in the main.

@history 15/11/2011 – Sebastien E. Bourban

Addition of move_file.

@history 15/11/2011 – Sebastien E. Bourban

Addition of a progress bar to the put_file_content and add_file_content methods – had to write by line, instead of just one.

@history 04/06/2012 – Fabien Decung

Extension of get_these_files to include subdirectories of source/.

@history 31/05/2012 – Sebastien E. Bourban

Addition of a simple unzipping method (unzip)

@history 15/04/20124– Sebastien E. Bourban

function is_newer now processes files within a directory also.

@brief

fastwater.otm_gpl.files.add_file_content(fle, lines)[source]

Add line to file

@param fle (string) file @param lines (string) adding line

fastwater.otm_gpl.files.add_to_list(lst, name, value)[source]

Add item to dictionary

@param lst (dictionnary) list @param name (any) key @param value (any) adding value

@return (dictionary) updating lst

fastwater.otm_gpl.files.check_safe(src, safe, c_k)[source]

Check

@param src (string) file to check @param safe (string) directory to check @param c_k (integer) ???? todo

@return (boolean) True if file exists

Checking if symlink is available @param use_link (boolean) option link instead of copy in the temporary folder @return (boolean)

fastwater.otm_gpl.files.copy_file(src, dest)[source]

Copy one file to directory

@param src (string) source file @param dest (string) target directory

fastwater.otm_gpl.files.copy_file2file(src, dest)[source]

Copy one file to file

@param src (string) source file @param dest (string) target file

fastwater.otm_gpl.files.copy_files(src, dest)[source]

Copy all the files within src @param src (string) source directory @param dest (string) target directory

fastwater.otm_gpl.files.create_directories(p_o)[source]

create directories tree

@param p_o (string) directory

fastwater.otm_gpl.files.diff_text_files(f_file, t_file, options)[source]

Command line interface to provide diffs in four formats:

  • ndiff: lists every line and highlights interline changes.

  • context: highlights clusters of changes in a before/after format.

  • unified: highlights clusters of changes in an inline format.

  • html: generates side by side comparison with change highlights.

@param f_file (string) @param t_file (string) @param options (string)

@return (str)

fastwater.otm_gpl.files.get_file_content(fle)[source]

Read fle file

@param fle (string) file

@return ilines (list) content line file

fastwater.otm_gpl.files.get_these_files(root, exts)[source]

@brief Make a list of all files in root that have the extension in [ext] – Return the list

@param root (string) path root @param exts (string) extension file

@return (list) files list

fastwater.otm_gpl.files.is_newer(nfile, ofile)[source]

Evaluate whether one file is more recent than the other Return 1 is ofile exists and is more recent than nfile, 0 otherwise > newer(ofile,nfile) is True if ofile exists and is more recent than nfile

@param nfile (string) new file @param ofile (string) old file or directory

@return (integer) Return 1 is ofile exists and is more recent than nfile, 0 otherwise

fastwater.otm_gpl.files.is_online(url='http://www.opentelemac.org/', timeout=5)[source]

Check url @param url (string) url @param timeout (integer) timeout @return (bool)

fastwater.otm_gpl.files.match_safe(src, ex, safe, c_k)[source]

???????? todo

@param src (string) file to check @param ex (string) pattern file to check @param safe (string) directory to check @param c_k (integer) ???? todo

@return (boolean) True if file exists

fastwater.otm_gpl.files.move_file(src, dest)[source]

Move file to directory

@param src (string) source file @param dest (string) target directory

fastwater.otm_gpl.files.move_file2file(src, dest)[source]

Move file to file

@param src (string) source file @param dest (string) target file

fastwater.otm_gpl.files.put_file_content(fle, lines)[source]

put line to file

@param fle (string) file @param lines (string) adding line

fastwater.otm_gpl.files.recursive_glob(treeroot, pattern)[source]

Returns list of files matching pattern in all subdirectories of treeroot (to avoid usage of glob.glob with recursive argument which is not suppoted by Python >3.5)

@param treeroot (str) Path of folder @param pattern (str) Pattern to search for

fastwater.otm_gpl.files.remove_directories(root)[source]

Walk through the directory structure available from the root and removes everything in it, including the root

@param root (string) directory structure to remove

Copy a file to its destination @param src (string) source file @param dest (string) target file

fastwater.otm_gpl.files.tel_zip(zname, bname, form)[source]

bname is a the root directory to be archived – Return the name of the archive, zname, with its full path – form can be either ‘zip’, ‘gztar’ … read from the config file

@param zname (string) archive name @param bname (string) file or directory to archive @param form (string) archive format

@return zipfile (string) name of the archive, zname, with its full path

fastwater.otm_gpl.files.unzip(zip_name, bname)[source]

bname is a the root directory where the archive is to be extracted –

@param zip_name (string) archive file @param bname (string) target directory

fastwater.otm_gpl.files.zipsortie(sortie)[source]

zip files and remove virtually all of them !

@param sortie (string) output to archive

@return zname (string) name of the archive