ConnectTool
 All Classes Namespaces Files Functions Variables Pages
Classes | Functions
module_toolbox_file Namespace Reference

Classes

class  ToolboxFileError
 

Functions

def fileno
 Get file number (?) More...
 
def stdout_redirected
 Redirect output to some device. More...
 
def init_sftp
 
def init_ftp
 
def download_files
 Download url web files in local folder. More...
 
def unzip_files
 Gunzip all files keeping the old .gz file. More...
 
def tar_files
 
def merge_images
 Merge images using Python PIL.Image library. More...
 
def transparent2white
 Transform transparent pixels of an image to white pixels. More...
 
def open_log
 Open a log file and write a header. More...
 
def get_modif_datetime
 Return modification date of a file. More...
 
def headcmp
 Compare header of 2 files. More...
 
def footcmp
 Compare footer of 2 files. More...
 

Function Documentation

def module_toolbox_file.download_files (   fileurls,
  local_dir,
  client = None 
)

Download url web files in local folder.

Overwrite old existing file.

Parameters
[in]fileurls: list(0..N-1) of file complete path (websitename/path/to/file)
[in]local_dir: where the files are copied
[in]client: an open FTP/SFTP client. If given, FTP/SFTP download. If not, URL download.
[out]Listof downloaded file absolute path
[out]Listof log messages
def module_toolbox_file.fileno (   file_or_fd)

Get file number (?)

Here is the caller graph for this function:

def module_toolbox_file.footcmp (   file1,
  file2,
  n = 10 
)

Compare footer of 2 files.

Based on Linux command tail.
Write tmp files in /tmp folder. Remove them at the end.

Parameters
[in]file1file path 1
[in]file1file path 1
[in]nline number of footer to be compared (default 10)
Returns
Boolean

Here is the caller graph for this function:

def module_toolbox_file.get_modif_datetime (   filepath)

Return modification date of a file.

Returns
mdate Datetime.datetime object
def module_toolbox_file.headcmp (   file1,
  file2,
  n = 10 
)

Compare header of 2 files.

Based on Linux command head.
Write tmp files in /tmp folder. Remove them at the end.

Parameters
[in]file1file path 1
[in]file1file path 1
[in]nline number of header to be compared (default 10)
Returns
Boolean

Here is the caller graph for this function:

def module_toolbox_file.init_ftp (   website)
Init a ftp session.
def module_toolbox_file.init_sftp (   machine,
  username,
  port = 22 
)
Init a sftp session.
Default port is 22.
def module_toolbox_file.merge_images (   background_path,
  layers_path,
  img_out_path,
  x = 0,
  y = 0 
)

Merge images using Python PIL.Image library.

Merge layers on the same background image.
All layers are placed defining the coordinate in pixel in background image of their lower left corner.

Parameters
[in]background,:background image
[in]layers,:list of input path image to be merged on background
[in]margin_left,:size in pixel
[in]margin_up,:size in pixel
[out]image_out,:merged image path

Exception:

  • If background image does not exist, raise a ToolboxFileError exception.
  • If a layer does not exists continue merging the others.
  • If all the layers do not exist, raise a ToolboxFileError exception.
def module_toolbox_file.open_log (   log_dir,
  log_basename,
  caller_name,
  project_name,
  datetime_in 
)

Open a log file and write a header.

Log path: os.path.join(log_dir,log_basename + _YYYYMMDD) Log header: ┌──────────────────────────────────────────────────┐ │ PROJECT_NAME │ │ │ │ CALLER_NAME │ ├──────────────────────────────────────────────────┤ │ Launched at datetime_in (UTC) │ └──────────────────────────────────────────────────┘

def module_toolbox_file.stdout_redirected (   to = os.devnull,
  stdout = None 
)

Redirect output to some device.

https://stackoverflow.com/a/22434262/190597 (J.F. Sebastian)

Here is the call graph for this function:

Here is the caller graph for this function:

def module_toolbox_file.tar_files (   files,
  tarname 
)
Tar some files.
Path are relative paths.
Input:
  * files: list of files to tar
  * tarname: with or without tar extension
Output:
  * logs: List of log message
def module_toolbox_file.transparent2white (   image_path_in,
  image_path_out 
)

Transform transparent pixels of an image to white pixels.

If paht in and out are the same, overwrite the existing image.

Parameters
[in]image_path_in,:path of the transparent image to transform.
[in]image_path_out,:path of the future no transparent image.

Exception:

def module_toolbox_file.unzip_files (   zipfiles)

Gunzip all files keeping the old .gz file.

Overwrite old gunzipped existing file.
Paths are absolute paths. IN:

Parameters
[in]zipfiles,:list(0..N-1) of file to unzip OUT:
[out]Listof unzipped file absolute path
[out]Listof log messages