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

Method ls

Algorithmia/CLI.py:168–220  ·  view source on GitHub ↗
(self, path, client, longlist=False)

Source from the content-addressed store, hash-verified

166
167 # algo ls <path>
168 def ls(self, path, client, longlist=False):
169 # by default list user's hosted data
170 listing = ""
171 if path is None:
172 path = "data://"
173
174 file = path.split('/')
175 if file[-1] != '':
176 # path is a file, list parent
177 directory = path[:-len(file[-1])]
178 f = client.dir(directory)
179
180 response = client.getHelper(f.url, **{})
181 if response.status_code != 200:
182 raise DataApiError("failed to get file info: " + str(response.content))
183
184 responseContent = response.content
185 if isinstance(responseContent, six.binary_type):
186 responseContent = responseContent.decode()
187
188 content = json.loads(responseContent)
189
190 if 'files' in content:
191 f = client.file(path)
192 for file_info in content['files']:
193 if file_info['filename'] == file[-1]:
194 f.set_attributes(file_info)
195
196 if longlist:
197 listing += f.last_modified.strftime("%Y-%m-%d %H:%M:%S") + ' '
198 listing += str(f.size) + ' '
199 listing += f.path + "\n"
200 else:
201 listing += f.path + "\n"
202 else:
203 # path is a directory
204 if longlist:
205 listingDir = client.dir(path)
206 for f in listingDir.dirs():
207 listing += f.path + "/\n"
208 for f in listingDir.files():
209 listing += f.last_modified.strftime("%Y-%m-%d %H:%M:%S") + ' '
210 listing += str(f.size) + ' '
211 listing += f.path + "\n"
212
213 else:
214 listingDir = client.dir(path)
215 for f in listingDir.dirs():
216 listing += f.path + "/\n"
217 for f in listingDir.files():
218 listing += f.path + "\n"
219
220 return listing
221
222 # algo cat <file>
223 def cat(self, path, client):

Callers 9

authMethod · 0.95
mainFunction · 0.80
test_lsMethod · 0.80
test_mkdirMethod · 0.80
test_rmdirMethod · 0.80
test_cp_L2RMethod · 0.80
test_cp_R2RMethod · 0.80
test_rmMethod · 0.80
test_api_address_authMethod · 0.80

Calls 7

DataApiErrorClass · 0.90
getHelperMethod · 0.80
dirMethod · 0.45
fileMethod · 0.45
set_attributesMethod · 0.45
dirsMethod · 0.45
filesMethod · 0.45

Tested by 7

test_lsMethod · 0.64
test_mkdirMethod · 0.64
test_rmdirMethod · 0.64
test_cp_L2RMethod · 0.64
test_cp_R2RMethod · 0.64
test_rmMethod · 0.64
test_api_address_authMethod · 0.64