def clear(*args, **kwargs): dryrun = kwargs['dryrun'] or False for f in microfs.ls(): if not f.endswith('.py'): logging.info('Removing file %s', f) if not dryrun: microfs.rm(f)
def flashF(folder): print("MicroBit is at: " + microfs.find_microbit()[0] + "\nMicroBit directory is at: " + uflash.find_microbit()) try: mfiles = microfs.ls() except OSError as e: print( str(e) + "\nMicrobit is probably calibrating, calibrate and then try again\nIf it still does not work try to " "replug your microbit or close other programs that is accessing your microbit" ) return "Could not write" print("Removing old stuff: " + str(mfiles)) for file in mfiles: microfs.rm(file) files = os.listdir(folder) print("Flashing new stuff: " + str(files)) for file in files: microfs.put(folder + "\\" + file) print("Flashed new stuff: " + str(microfs.ls()) + "\n") time.sleep(0.1) print("Done!" + "\n" + "Don't forget to name your main file \"main.py\"" + "\n" + InternalTools.bcolors.BOLD + "Reset your MicroBit to apply changes!")
def main(): print(TITLE) csv_files = [file for file in ls() if file.endswith(output_extension) ] # Load all csv file names from the Microbit if not csv_files: print(" No '{}' files to copy!".format(output_extension)) return 0 name = input(" Enter target name: ") name = name.capitalize() if name else "Unnamed" # Create sub-directory in RAW_Data directory dir_name = os.path.join( "RAW_Data", "{} {}".format(name, datetime.now().strftime("%d %m %Y %H-%M"))) os.makedirs(dir_name, exist_ok=True) # Make the sub-directory if it doesn't exist print() for i, file in enumerate(csv_files): print(" Progress: {:<50} ({}/{})".format( "█" * int(50 * (i + 1) / len(csv_files)), i + 1, len(csv_files)), end="\r") f_name = "{}{}{}".format( name, i, output_extension) # Prepare file name at destination directory get(file, os.path.join( dir_name, f_name)) # Copy file from Microbit to given directory as f_name time.sleep(1) rm(file) time.sleep(1) # Remove file from Microbit print("\n\n {} files moved to '{}'".format(i + 1, dir_name)) return 0
def test_rm_with_error(): """ Ensure an IOError is raised if stderr returns something. """ with mock.patch('microfs.execute', return_value=(b'', b'error')): with pytest.raises(IOError) as ex: microfs.rm('foo') assert ex.value.args[0] == 'error'
def test_rm_with_error(): """ Ensure an IOError is raised if stderr returns something. """ mock_serial = mock.MagicMock() with mock.patch("microfs.execute", return_value=(b"", b"error")): with pytest.raises(IOError) as ex: microfs.rm("foo", mock_serial) assert ex.value.args[0] == "error"
def test_rm(): """ Given a filename and nothing in stderr from the micro:bit, return True. """ with mock.patch('microfs.execute', return_value=(b'', b'')) as execute: assert microfs.rm('foo') execute.assert_called_once_with("import os;\nos.remove('foo')")
def test_rm(): """ Given a filename and nothing in stderr from the micro:bit, return True. """ mock_serial = mock.MagicMock() with mock.patch('microfs.execute', return_value=(b'', b'')) as execute: assert microfs.rm('foo', mock_serial) execute.assert_called_once_with([ "import os", "os.remove('foo')", ], mock_serial)
def clear_microbit(): """ clear files from micro:bit """ print('Cleaning micro:bit file system') files = microfs.ls() for fname in files: microfs.rm(fname)