Python uos.remove() Examples
The following are 7
code examples of uos.remove().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
uos
, or try the search function
.
Example #1
Source File: Board.py From illuminOS with MIT License | 6 votes |
def format(self): import uos log.info("Formatting filesystem ...") while uos.listdir("/"): lst = uos.listdir("/") uos.chdir("/") while lst: try: uos.remove(lst[0]) log.info("Removed '" + uos.getcwd() + "/" + lst[0] + "'") lst = uos.listdir(uos.getcwd()) except: dir = lst[0] log.info("Directory '" + uos.getcwd() + "/" + dir + "' detected. Opening it...") uos.chdir(dir) lst = uos.listdir(uos.getcwd()) if len(lst) == 0: log.info("Directory '" + uos.getcwd() + "' is empty. Removing it...") uos.chdir("..") uos.rmdir(dir) break log.info("Format completed successfully")
Example #2
Source File: files.py From ampy with MIT License | 5 votes |
def rm(self, filename): """Remove the specified file or directory.""" command = """ try: import os except ImportError: import uos as os os.remove('{0}') """.format( filename ) self._pyboard.enter_raw_repl() try: out = self._pyboard.exec_(textwrap.dedent(command)) except PyboardError as ex: message = ex.args[2].decode("utf-8") # Check if this is an OSError #2, i.e. file/directory doesn't exist # and rethrow it as something more descriptive. if message.find("OSError: [Errno 2] ENOENT") != -1: raise RuntimeError("No such file/directory: {0}".format(filename)) # Check for OSError #13, the directory isn't empty. if message.find("OSError: [Errno 13] EACCES") != -1: raise RuntimeError("Directory is not empty: {0}".format(filename)) else: raise ex self._pyboard.exit_raw_repl()
Example #3
Source File: test_server.py From tinyweb with MIT License | 5 votes |
def delete_file(fn): # "unlink" gets renamed to "remove" in micropython, # so support both if hasattr(os, 'unlink'): os.unlink(fn) else: os.remove(fn) # HTTP headers helpers
Example #4
Source File: tagmain.py From developer-badge-2018-apps with Apache License 2.0 | 5 votes |
def run(self): # Check if it was downloaded before try: if self.IS_TEST: uos.remove(self.filename) else: f = open(self.filename, 'r') self.display_nametag(bytearray(f.read())) f.close() return except Exception as e: print(e) print('nametag image file ({}) loading failure'.format(self.filename)) # Show container self.container.show() self.open_status_box() # Check network try: self.check_network() except Exception as e: self.set_status_text(str(e)) return # Get Device ID sta_if = network.WLAN(network.STA_IF) deviceId = ''.join('{:02X}'.format(c) for c in sta_if.config('mac')) self.set_status_text('Your device ID is {}'.format(deviceId)) # TODO: Get device owner by device id # Download nametag try: self.download_nametag() except Exception as e: self.set_status_text(str(e)) return
Example #5
Source File: uftpd.py From FTP-Server-for-ESP8266-ESP32-and-PYBD with MIT License | 5 votes |
def log_msg(level, *args): global verbose_l if verbose_l >= level: print(*args) # close client and remove it from the list
Example #6
Source File: Stepper.py From illuminOS with MIT License | 5 votes |
def remove_property_file(self, uri): import uos uos.remove(uri)
Example #7
Source File: files.py From ampy with MIT License | 4 votes |
def rmdir(self, directory, missing_okay=False): """Forcefully remove the specified directory and all its children.""" # Build a script to walk an entire directory structure and delete every # file and subfolder. This is tricky because MicroPython has no os.walk # or similar function to walk folders, so this code does it manually # with recursion and changing directories. For each directory it lists # the files and deletes everything it can, i.e. all the files. Then # it lists the files again and assumes they are directories (since they # couldn't be deleted in the first pass) and recursively clears those # subdirectories. Finally when finished clearing all the children the # parent directory is deleted. command = """ try: import os except ImportError: import uos as os def rmdir(directory): os.chdir(directory) for f in os.listdir(): try: os.remove(f) except OSError: pass for f in os.listdir(): rmdir(f) os.chdir('..') os.rmdir(directory) rmdir('{0}') """.format( directory ) self._pyboard.enter_raw_repl() try: out = self._pyboard.exec_(textwrap.dedent(command)) except PyboardError as ex: message = ex.args[2].decode("utf-8") # Check if this is an OSError #2, i.e. directory doesn't exist # and rethrow it as something more descriptive. if message.find("OSError: [Errno 2] ENOENT") != -1: if not missing_okay: raise RuntimeError("No such directory: {0}".format(directory)) else: raise ex self._pyboard.exit_raw_repl()