zip_tools
_create_zip(folder, output)
¶
Zip a folder into a zip-file or into a BytesIO.
| PARAMETER | DESCRIPTION |
|---|---|
folder
|
Folder to be zipped.
TYPE:
|
output
|
Either a string with the path of the zip file, or a BytesIO object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T
|
Either the zip-file path string, or the modified BytesIO object. |
Source code in fractal_server/zip_tools.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
_folder_can_be_deleted(folder)
¶
Given the path of a folder as string, returns False if either:
- the related zip file {folder}.zip does already exists,
- the folder and the zip file have a different number of internal files,
- the zip file has a very small size.
Otherwise returns True.
Source code in fractal_server/zip_tools.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
_read_single_file_from_zip(*, file_path, archive_path)
¶
Reads and returns the contents of a single file from a ZIP archive using
unzip -p.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
relative to the archive
TYPE:
|
archive_path
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The file content |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
if the file is not inside the archive |
Source code in fractal_server/zip_tools.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
_zip_folder_to_byte_stream_iterator(folder)
¶
Returns byte stream with the zipped log folder of a job.
| PARAMETER | DESCRIPTION |
|---|---|
folder
|
the folder to zip
TYPE:
|
Source code in fractal_server/zip_tools.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
_zip_folder_to_file_and_remove(folder)
¶
Creates a ZIP archive of the specified folder and removes the original folder (if it can be deleted).
This function performs the following steps:
1. Creates a ZIP archive of the folder and names it with a temporary
suffix _tmp.zip.
2. Renames the ZIP removing the suffix (this would possibly overwrite a
file with the same name already present).
3. Checks if the folder can be safely deleted using the
_folder_can_be_deleted function. If so, deletes the original folder.
Source code in fractal_server/zip_tools.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |