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 | gunzip_files |
Gunzip all files keeping the old .gz file. More... | |
def | unzip_files |
Unzip all files keeping the old .zip 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... | |
def common.module_toolbox_file.download_files | ( | fileurls, | |
local_dir, | |||
client = None , |
|||
verbose = 0 |
|||
) |
Download url web files in local folder.
Overwrite old existing file.
[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] | List | of downloaded file absolute path |
[out] | List | of log messages |
def common.module_toolbox_file.fileno | ( | file_or_fd | ) |
Get file number (?)
def common.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.
[in] | file1 | file path 1 |
[in] | file1 | file path 1 |
[in] | n | line number of footer to be compared (default 10) |
def common.module_toolbox_file.get_modif_datetime | ( | filepath | ) |
Return modification date of a file.
def common.module_toolbox_file.gunzip_files | ( | zipfiles, | |
verbose = 0 |
|||
) |
Gunzip all files keeping the old .gz file.
Overwrite old gunzipped existing file.
Paths are absolute paths. IN:
[in] | zipfiles,: | list(0..N-1) of file to unzip OUT: |
[out] | List | of unzipped file absolute path |
[out] | List | of log messages |
def common.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.
[in] | file1 | file path 1 |
[in] | file1 | file path 1 |
[in] | n | line number of header to be compared (default 10) |
def common.module_toolbox_file.init_ftp | ( | website | ) |
Init a ftp session.
def common.module_toolbox_file.init_sftp | ( | machine, | |
username, | |||
port = 22 |
|||
) |
Init a sftp session. Default port is 22.
def common.module_toolbox_file.merge_images | ( | layers_path, | |
img_out_path, | |||
x = 0 , |
|||
y = 0 |
|||
) |
Merge images using Python PIL.Image library.
Merge layers on the same image.
All layers are placed defining the coordinate in pixel in background image of their lower left corner.
[in] | layers,: | list of input path image to be merged |
[in] | margin_left,: | size in pixel |
[in] | margin_up,: | size in pixel |
[out] | image_out,: | merged image path |
Exception:
def common.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 common.module_toolbox_file.stdout_redirected | ( | to = os.devnull , |
|
stdout = None |
|||
) |
Redirect output to some device.
https://stackoverflow.com/a/22434262/190597 (J.F. Sebastian)
def common.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 common.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.
[in] | image_path_in,: | path of the transparent image to transform. |
[in] | image_path_out,: | path of the future no transparent image. |
Exception:
def common.module_toolbox_file.unzip_files | ( | zipfiles, | |
verbose = 0 |
|||
) |
Unzip all files keeping the old .zip file.
Overwrite old uunzipped existing file.
Paths are absolute paths. IN:
[in] | zipfiles,: | list(0..N-1) of file to unzip OUT: |
[out] | List | of unzipped file absolute path |
[out] | List | of log messages |