296 @type str |
296 @type str |
297 @return tuple containg the directory listing |
297 @return tuple containg the directory listing |
298 @rtype tuple of str |
298 @rtype tuple of str |
299 @exception OSError raised to indicate an issue with the device |
299 @exception OSError raised to indicate an issue with the device |
300 """ |
300 """ |
301 if self.__repl.isMicrobit(): |
301 commands = ( |
302 # BBC micro:bit does not support directories |
302 # BBC micro:bit does not support directories |
303 commands = [ |
303 [ |
304 "import os as __os_", |
304 "import os as __os_", |
305 "print(__os_.listdir())", |
305 "print(__os_.listdir())", |
306 "del __os_", |
306 "del __os_", |
307 ] |
307 ] |
308 else: |
308 if self.__repl.isMicrobit() else |
309 commands = [ |
309 [ |
310 "import os as __os_", |
310 "import os as __os_", |
311 "print(__os_.listdir('{0}'))".format(dirname), |
311 "print(__os_.listdir('{0}'))".format(dirname), |
312 "del __os_", |
312 "del __os_", |
313 ] |
313 ] |
|
314 ) |
314 out, err = self.execute(commands) |
315 out, err = self.execute(commands) |
315 if err: |
316 if err: |
316 raise OSError(self.__shortError(err)) |
317 raise OSError(self.__shortError(err)) |
317 return ast.literal_eval(out.decode("utf-8")) |
318 return ast.literal_eval(out.decode("utf-8")) |
318 |
319 |
332 false) or the complete stat() tuple. 'None' is returned in case the |
333 false) or the complete stat() tuple. 'None' is returned in case the |
333 directory doesn't exist. |
334 directory doesn't exist. |
334 @rtype tuple of (str, tuple) |
335 @rtype tuple of (str, tuple) |
335 @exception OSError raised to indicate an issue with the device |
336 @exception OSError raised to indicate an issue with the device |
336 """ |
337 """ |
337 if self.__repl.isMicrobit(): |
338 commands = ( |
338 # BBC micro:bit does not support directories |
339 # BBC micro:bit does not support directories |
339 commands = [ |
340 [ |
340 "import os as __os_", |
341 "import os as __os_", |
341 "\n".join([ |
342 "\n".join([ |
342 "def is_visible(filename, showHidden):", |
343 "def is_visible(filename, showHidden):", |
343 " return showHidden or " |
344 " return showHidden or " |
344 "(filename[0] != '.' and filename[-1] != '~')", |
345 "(filename[0] != '.' and filename[-1] != '~')", |
355 " is_visible(f,showHidden))", |
356 " is_visible(f,showHidden))", |
356 ]), |
357 ]), |
357 "print(listdir_stat({0}))".format(showHidden), |
358 "print(listdir_stat({0}))".format(showHidden), |
358 "del __os_, stat, listdir_stat, is_visible", |
359 "del __os_, stat, listdir_stat, is_visible", |
359 ] |
360 ] |
360 else: |
361 if self.__repl.isMicrobit() else |
361 commands = [ |
362 [ |
362 "import os as __os_", |
363 "import os as __os_", |
363 "\n".join([ |
364 "\n".join([ |
364 "def is_visible(filename, showHidden):", |
365 "def is_visible(filename, showHidden):", |
365 " return showHidden or " |
366 " return showHidden or " |
366 "(filename[0] != '.' and filename[-1] != '~')", |
367 "(filename[0] != '.' and filename[-1] != '~')", |
386 " for f in files if is_visible(f, showHidden))", |
387 " for f in files if is_visible(f, showHidden))", |
387 ]), |
388 ]), |
388 "print(listdir_stat('{0}', {1}))".format(dirname, showHidden), |
389 "print(listdir_stat('{0}', {1}))".format(dirname, showHidden), |
389 "del __os_, stat, listdir_stat, is_visible", |
390 "del __os_, stat, listdir_stat, is_visible", |
390 ] |
391 ] |
|
392 ) |
391 out, err = self.execute(commands) |
393 out, err = self.execute(commands) |
392 if err: |
394 if err: |
393 raise OSError(self.__shortError(err)) |
395 raise OSError(self.__shortError(err)) |
394 fileslist = ast.literal_eval(out.decode("utf-8")) |
396 fileslist = ast.literal_eval(out.decode("utf-8")) |
395 if fileslist is None: |
397 if fileslist is None: |