eric6/MicroPython/MicroPythonCommandsInterface.py

branch
micropython
changeset 7137
4ed2573947ff
parent 7136
bddcb634a9b8
child 7174
de8175253dfc
equal deleted inserted replaced
7136:bddcb634a9b8 7137:4ed2573947ff
309 out, err = self.execute(commands) 309 out, err = self.execute(commands)
310 if err: 310 if err:
311 raise IOError(self.__shortError(err)) 311 raise IOError(self.__shortError(err))
312 return ast.literal_eval(out.decode("utf-8")) 312 return ast.literal_eval(out.decode("utf-8"))
313 313
314 def lls(self, dirname="", fullstat=False): 314 def lls(self, dirname="", fullstat=False, showHidden=False):
315 """ 315 """
316 Public method to get a long directory listing of the connected device 316 Public method to get a long directory listing of the connected device
317 including meta data. 317 including meta data.
318 318
319 @param dirname name of the directory to be listed 319 @param dirname name of the directory to be listed
320 @type str 320 @type str
321 @param fullstat flag indicating to return the full stat() tuple 321 @param fullstat flag indicating to return the full stat() tuple
322 @type bool
323 @param showHidden flag indicating to show hidden files as well
322 @type bool 324 @type bool
323 @return list containing the directory listing with tuple entries of 325 @return list containing the directory listing with tuple entries of
324 the name and and a tuple of mode, size and time (if fullstat is 326 the name and and a tuple of mode, size and time (if fullstat is
325 false) or the complete stat() tuple. 'None' is returned in case the 327 false) or the complete stat() tuple. 'None' is returned in case the
326 directory doesn't exist. 328 directory doesn't exist.
330 if self.__repl.isMicrobit(): 332 if self.__repl.isMicrobit():
331 # BBC micro:bit does not support directories 333 # BBC micro:bit does not support directories
332 commands = [ 334 commands = [
333 "import os as __os_", 335 "import os as __os_",
334 "\n".join([ 336 "\n".join([
335 "def is_visible(filename):", 337 "def is_visible(filename, showHidden):",
336 " return filename[0] != '.' and filename[-1] != '~'", 338 " return showHidden or "
339 "(filename[0] != '.' and filename[-1] != '~')",
337 ]), 340 ]),
338 "\n".join([ 341 "\n".join([
339 "def stat(filename):", 342 "def stat(filename):",
340 " size = __os_.size(filename)", 343 " size = __os_.size(filename)",
341 " return (0, 0, 0, 0, 0, 0, size, 0, 0, 0)" 344 " return (0, 0, 0, 0, 0, 0, size, 0, 0, 0)"
342 ]), 345 ]),
343 "\n".join([ 346 "\n".join([
344 "def listdir_stat():", 347 "def listdir_stat(showHidden):",
345 " files = __os_.listdir()", 348 " files = __os_.listdir()",
346 " return list((f, stat(f)) for f in files if" 349 " return list((f, stat(f)) for f in files if"
347 " is_visible(f))", 350 " is_visible(f,showHidden))",
348 ]), 351 ]),
349 "print(listdir_stat())", 352 "print(listdir_stat({0}))".format(showHidden),
350 "del __os_, stat, listdir_stat, is_visible", 353 "del __os_, stat, listdir_stat, is_visible",
351 ] 354 ]
352 else: 355 else:
353 commands = [ 356 commands = [
354 "import os as __os_", 357 "import os as __os_",
355 "\n".join([ 358 "\n".join([
356 "def is_visible(filename):", 359 "def is_visible(filename, showHidden):",
357 " return filename[0] != '.' and filename[-1] != '~'", 360 " return showHidden or "
361 "(filename[0] != '.' and filename[-1] != '~')",
358 ]), 362 ]),
359 "\n".join([ 363 "\n".join([
360 "def stat(filename):", 364 "def stat(filename):",
361 " try:", 365 " try:",
362 " rstat = __os_.lstat(filename)", 366 " rstat = __os_.lstat(filename)",
363 " except:", 367 " except:",
364 " rstat = __os_.stat(filename)", 368 " rstat = __os_.stat(filename)",
365 " return tuple(rstat)", 369 " return tuple(rstat)",
366 ]), 370 ]),
367 "\n".join([ 371 "\n".join([
368 "def listdir_stat(dirname):", 372 "def listdir_stat(dirname, showHidden):",
369 " try:", 373 " try:",
370 " files = __os_.listdir(dirname)", 374 " files = __os_.listdir(dirname)",
371 " except OSError:", 375 " except OSError:",
372 " return None", 376 " return None",
373 " if dirname in ('', '/'):", 377 " if dirname in ('', '/'):",
374 " return list((f, stat(f)) for f in files if" 378 " return list((f, stat(f)) for f in files if"
375 " is_visible(f))", 379 " is_visible(f, showHidden))",
376 " return list((f, stat(dirname + '/' + f))" 380 " return list((f, stat(dirname + '/' + f))"
377 " for f in files if is_visible(f))", 381 " for f in files if is_visible(f, showHidden))",
378 ]), 382 ]),
379 "print(listdir_stat('{0}'))".format(dirname), 383 "print(listdir_stat('{0}', {1}))".format(dirname, showHidden),
380 "del __os_, stat, listdir_stat, is_visible", 384 "del __os_, stat, listdir_stat, is_visible",
381 ] 385 ]
382 out, err = self.execute(commands) 386 out, err = self.execute(commands)
383 if err: 387 if err:
384 raise IOError(self.__shortError(err)) 388 raise IOError(self.__shortError(err))

eric ide

mercurial