How to use the storage.mount function in storage

To help you get started, we’ve selected a few storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adafruit / rosie-ci / tester.py View on Github external
if "circuitpython_tests" in tests:
        # First find our CircuitPython disk.
        start_time = time.monotonic()
        disk_path = None
        while not disk_path and time.monotonic() - start_time < 10:
            for disk in os.listdir("/dev/disk/by-path"):
                if board["path"] in disk and disk.endswith("part1"):
                    disk_path = disk
        if not disk_path:
            raise RuntimeError("Cannot find CIRCUITPY disk for device: " + board["path"])

        disk_path = "/dev/disk/by-path/" + disk_path
        disk_device = os.path.basename(os.readlink(disk_path))[:-1]

        with storage.mount(storage.NativeFileSystem(disk_path), "/media/cpy-" + board["path"]):
            mountpoint = "/media/cpy-" + board["path"]
            redis_log(log_key, "Successfully mounted CIRCUITPY disk at {0}\n".format(mountpoint))

            # Now find the serial.
            serial_device_name = None
            for port in list_ports.comports():
                if port.location and port.location.split(":")[0][2:] == board["path"]:
                    serial_device_name = port.name
            if not serial_device_name:
                raise RuntimeError("No CircuitPython serial connection found at path: " + board["path"])
            with serial.Serial("/dev/" + serial_device_name, 115200, write_timeout=4, timeout=4) as conn:
                tests_ok = run_circuitpython_tests(log_key, board["board"], board["test_env"], mountpoint, disk_device, conn, tests["circuitpython_tests"]) and tests_ok


    return tests_ok
github oVirt / vdsm / tests / mountTests.py View on Github external
def testLookupWipe(self):
        with open(mount._PROC_MOUNTS_PATH) as f:
            old_mounts = f.read()
        with open(mount._ETC_MTAB_PATH) as f:
            old_mtab = f.read()

        self.assertEquals(len(list(mount.iterMounts())), 1100)
        mounts_mnt = mount.MountRecord('/dev/loop10001',
                                       '/mnt/loop10001',
                                       'xfs',
                                       'rw,foobar,errors=continue',
                                       '0', '0')
        mtab_mnt = mount.MountRecord('/images/loop10001.img',
                                     '/mnt/loop%d',
                                     'xfs',
                                     'rw,loop=/dev/loop10001',
                                     '0', '0')

        with open(mount._PROC_MOUNTS_PATH, 'a') as f:
            f.write(self.line_fmt % mounts_mnt._asdict())
github oVirt / vdsm / tests / mkimageTests.py View on Github external
def test_mkFloppyFs(self, label):
        """
        Tests mkimage.mkFloppyFs creating an image and checking its content.
        Requires root permissions for writing into the floppy image.
        """
        floppy = mkimage.mkFloppyFs("vmId_floppy", self.files, label)
        self.assertTrue(os.path.exists(floppy))
        m = storage.mount.Mount(floppy, self.workdir)
        m.mount(mntOpts='loop')
        try:
            self._check_content(checkPerms=False)
            self._check_label(floppy, label)
        finally:
            m.umount(force=True, freeloop=True)
            # TODO: Use libudev to wait for specific event
            with stopwatch("Wait for udev events"):
                storage.udevadm.settle(5)
github maholli / SAM32 / firmware / esp32_firmware / esp_talk.py View on Github external
led.direction = digitalio.Direction.OUTPUT
rts.direction = digitalio.Direction.OUTPUT
dtr.direction = digitalio.Direction.OUTPUT

led.value = 0
rts.value = 1
dtr.value = 1


# SPI and SD card setup
try:
	spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
	cs = digitalio.DigitalInOut(board.xSDCS)
	sdcard = adafruit_sdcard.SDCard(spi, cs)
	vfs = storage.VfsFat(sdcard)
	storage.mount(vfs, "/sd")
	SD_IN = True
except OSError:
	SD_IN = False
	print('\n---- No SD card found, proceeding without it ----\n')
	pass

startUP = True
test=[]


# Use the filesystem as normal! Our files are under /sd 
# This helper function will print the contents of the SD 
def print_directory(path, tabs=0):    
    for file in os.listdir(path):
        stats = os.stat(path + "/" + file)
        filesize = stats[6]
github pycubed / software / default libraries / mainboard-v02 / pycubed.py View on Github external
self._rf_cs1.switch_to_output(value=True)
        self._rf_rst1.switch_to_output(value=True)
        self._rf_cs2 = digitalio.DigitalInOut(board.RF2_CS)
        self._rf_rst2 = digitalio.DigitalInOut(board.RF2_RST)
        self._rf_cs2.switch_to_output(value=True)
        self._rf_rst2.switch_to_output(value=True)

        # Define GPS
        self._en_gps = digitalio.DigitalInOut(board.EN_GPS)
        self._en_gps.switch_to_output()

        # Initialize sdcard
        try:
            self._sd   = adafruit_sdcard.SDCard(self._spi, self._sdcs)
            self._vfs = storage.VfsFat(self._sd)
            storage.mount(self._vfs, "/sd")
            sys.path.append("/sd")
            self.hardware['SDcard'] = True
        except Exception as e:
            print('[ERROR][SD Card]',e)
        
        # Initialize Power Monitor
        try:
            self.pwr = adm1176.ADM1176(self._i2c)
            self.pwr.sense_resistor = 0.025
            self.hardware['PWR'] = True
        except Exception as e:
            print('[ERROR][Power Monitor]',e)    

        # Initialize IMU
        # try:
        #     self.IMU = bmx160.BMX160_I2C(self._i2c)
github maholli / SAM32 / firmware / esp32_firmware / esp_ardu.py View on Github external
resetpin = DigitalInOut(board.RTS)
gpio0pin = DigitalInOut(board.DTR)
resetpin.direction = Direction.OUTPUT
gpio0pin.direction = Direction.OUTPUT

resetpin.value = 1
gpio0pin.value = 1

import adafruit_sdcard, storage

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = DigitalInOut(board.xSDCS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

def print_directory(path, tabs=0):
    for file in os.listdir(path):
        stats = os.stat(path + "/" + file)
        filesize = stats[6]
        isdir = stats[0] & 0x4000
        if filesize < 1000:
            sizestr = str(filesize) + " by"
        elif filesize < 1000000:
            sizestr = "%0.1f KB" % (filesize / 1000)
        else:
            sizestr = "%0.1f MB" % (filesize / 1000000)
        prettyprintname = ""
        for _ in range(tabs):
            prettyprintname += "   "
        prettyprintname += file
github adafruit / Adafruit_CircuitPython_PyPortal / adafruit_pyportal.py View on Github external
if self._debug:
            print("My IP address is", self._esp.pretty_ip(self._esp.ip_address))

        # set the default background
        self.set_background(self._default_bg)
        board.DISPLAY.show(self.splash)

        if self._debug:
            print("Init SD Card")
        sd_cs = DigitalInOut(board.SD_CS)
        self._sdcard = None
        try:
            self._sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
            vfs = storage.VfsFat(self._sdcard)
            storage.mount(vfs, "/sd")
        except OSError as error:
            print("No SD card found:", error)

        self._qr_group = None
        # Tracks whether we've hidden the background when we showed the QR code.
        self._qr_only = False

        if self._debug:
            print("Init caption")
        self._caption = None
        if caption_font:
            self._caption_font = bitmap_font.load_font(caption_font)
        self.set_caption(caption_text, caption_position, caption_color)

        if text_font:
            if isinstance(text_position[0], (list, tuple)):
github adafruit / Adafruit_Learning_System_Guides / Introducing_Trinket_M0 / Trinket_SDCardList.py View on Github external
import adafruit_sdcard
import busio
import digitalio
import board
import storage
import os

# Use any pin that is not taken by SPI
SD_CS = board.D0

# Connect to the card and mount the filesystem.
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# Use the filesystem as normal! Our files are under /sd

# This helper function will print the contents of the SD
def print_directory(path, tabs = 0):
    for file in os.listdir(path):
        stats = os.stat(path+"/"+file)
        filesize = stats[6]
        isdir = stats[0] & 0x4000
    
        if filesize < 1000:
            sizestr = str(filesize) + " by"
        elif filesize < 1000000:
            sizestr = "%0.1f KB" % (filesize/1000)
        else:
            sizestr = "%0.1f MB" % (filesize/1000000)
github adafruit / Adafruit_Learning_System_Guides / Introducing_Trinket_M0 / Trinket_SDlogger.py View on Github external
import digitalio
import microcontroller
import storage

# Use any pin that is not taken by SPI
SD_CS = board.D0

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Connect to the card and mount the filesystem.
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# Use the filesystem as normal! Our files are under /sd

print("Logging temperature to filesystem")
# append to the file!
while True:
    # open file for append
    with open("/sd/temperature.txt", "a") as f:
        led.value = True  # turn on LED to indicate we're writing to the file
        t = microcontroller.cpu.temperature
        print("Temperature = %0.1f" % t)
        f.write("%0.1f\n" % t)
        led.value = False  # turn off LED to indicate we're done
    # file is saved
    time.sleep(1)