本文整理汇总了Python中uos.remove方法的典型用法代码示例。如果您正苦于以下问题:Python uos.remove方法的具体用法?Python uos.remove怎么用?Python uos.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uos
的用法示例。
在下文中一共展示了uos.remove方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
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")
示例2: rm
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
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()
示例3: delete_file
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
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
示例4: run
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
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
示例5: log_msg
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
def log_msg(level, *args):
global verbose_l
if verbose_l >= level:
print(*args)
# close client and remove it from the list
示例6: remove_property_file
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
def remove_property_file(self, uri):
import uos
uos.remove(uri)
示例7: rmdir
# 需要导入模块: import uos [as 别名]
# 或者: from uos import remove [as 别名]
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()