コード例 #1
0
ファイル: MicroBitTools.py プロジェクト: swz-gh/MicroBitTools
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
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
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
ファイル: test_microfs.py プロジェクト: skylin008/microfs
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
ファイル: test_microfs.py プロジェクト: damianburrin/microfs
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
ファイル: test_microfs.py プロジェクト: skylin008/microfs
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
ファイル: make.py プロジェクト: SyluxDX/microbit-workspace
def clear_microbit():
    """ clear files from micro:bit """
    print('Cleaning micro:bit file system')
    files = microfs.ls()
    for fname in files:
        microfs.rm(fname)