MCPcopy Index your code
hub / github.com/algorithmiaio/algorithmia-python / putAsZip

Method putAsZip

Algorithmia/datafile.py:166–182  ·  view source on GitHub ↗

Zip file/directory and upload to data API location defined by `DataFile` object. Accepts either a single file or a directory containing other files and directories.

(self, path)

Source from the content-addressed store, hash-verified

164 raise DataApiError("Attempted to .putNumpy() a file without numpy available, please install numpy.")
165
166 def putAsZip(self, path):
167 """Zip file/directory and upload to data API location defined by `DataFile` object.
168
169 Accepts either a single file or a directory containing other files and directories.
170 """
171 temp = tempfile.NamedTemporaryFile(delete=False).name
172 if os.path.isdir(path):
173 with zipfile.ZipFile(temp, 'w') as ziph:
174 for root, dirs, files in os.walk(path):
175 for file in files:
176 f_path = os.path.join(root, file)
177 arc_path = os.path.relpath(os.path.join(root, file), path)
178 ziph.write(f_path, arc_path)
179 else:
180 with zipfile.ZipFile(temp, 'w') as ziph:
181 ziph.write(path)
182 return self.putFile(temp)
183
184 def delete(self):
185 # Delete from data api

Callers 1

Calls 1

putFileMethod · 0.95

Tested by 1