示例#1
0
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!")
示例#2
0
def test_ls_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.ls()
    assert ex.value.args[0] == 'error'
示例#3
0
def test_ls_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.ls(mock_serial)
    assert ex.value.args[0] == "error"
示例#4
0
文件: wbr.py 项目: rendermaniac/wbr
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)
示例#5
0
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
示例#6
0
def test_ls():
    """
    If a list is returned as a result in stdout, ensure that the equivalent
    Python list is returned from ls.
    """
    with mock.patch('microfs.execute', return_value=(b'[ \'a.txt\']\r\n',
                                                     b'')) as execute:
        result = microfs.ls()
        assert result == ['a.txt']
        execute.assert_called_once_with('import os;\nprint(os.listdir())')
示例#7
0
def test_ls():
    """
    If a list is returned as a result in stdout, ensure that the equivalent
    Python list is returned from ls.
    """
    mock_serial = mock.MagicMock()
    with mock.patch("microfs.execute",
                    return_value=(b"[ 'a.txt']\r\n", b"")) as execute:
        result = microfs.ls(mock_serial)
        assert result == ["a.txt"]
        execute.assert_called_once_with([
            "import os",
            "print(os.listdir())",
        ], mock_serial)
示例#8
0
def test_ls_width_delimiter():
    """
    If a delimiter is provided, ensure that the result from stdout is
    equivalent to the list returned by Python.
    """
    mock_serial = mock.MagicMock()
    with mock.patch("microfs.execute",
                    return_value=(b"[ 'a.txt','b.txt']\r\n", b"")) as execute:
        result = microfs.ls(mock_serial)
        delimitedResult = ";".join(result)
        assert delimitedResult == "a.txt;b.txt"
        execute.assert_called_once_with(
            [
                "import os",
                "print(os.listdir())",
            ],
            mock_serial,
        )
示例#9
0
文件: wbr.py 项目: rendermaniac/wbr
def download(*args, **kwargs):
    dryrun = kwargs['dryrun'] or False
    for f in microfs.ls():
        logging.info('Downloading file %s', f)
        if not dryrun:
            microfs.get(f)
示例#10
0
def clear_microbit():
    """ clear files from micro:bit """
    print('Cleaning micro:bit file system')
    files = microfs.ls()
    for fname in files:
        microfs.rm(fname)