Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elmot/mpremote #284

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "pypi"

[packages]
docopt = "*"
adafruit-ampy = "*"
mpremote = "*"
pyserial = "*"

[dev-packages]
Expand Down
8 changes: 0 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions scripts/findusb.py

This file was deleted.

75 changes: 16 additions & 59 deletions scripts/microcleanfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,24 @@
# limitations under the License.


"""Remove the contents of the file system on a MicroPython device.

Usage:
microcleanfs PORT [options]

Options:
-f --force Remove ALL files from filesystem w/o preserving excludes
"""Remove the contents of the file system on a MicroPython device, skipping boot.py
"""

import traceback
from typing import List

import sys
import time

from ampy.files import Files
from ampy.pyboard import Pyboard, PyboardError
from docopt import docopt


def main(args: List[str]) -> None:
opts = docopt(__doc__, argv=args)
port = opts['PORT']
force = opts['--force']

print('Connecting to {}'.format(port), file=sys.stderr)
board = Pyboard(port)
files = Files(board)

# Specifying subdirectories DOES NOT work as they will be deleted when the
# parent directory is deleted. Specifying top level directories DOES work.
exclude_files = ['boot.py']

print('Removing the contents of the file system')
wait_for_board()
for name in files.ls(long_format=False):
if force or name not in exclude_files:
try:
files.rm(name)
except (RuntimeError, PyboardError):
try:
files.rmdir(name)
except (RuntimeError, PyboardError):
print('Unknown Error removing file {}'.format(name),
file=sys.stderr)

print('Done')
import os


def wait_for_board() -> None:
"""Wait for some ESP8266 devices to become ready for REPL commands."""
time.sleep(0.5)
def delete_recursive(folder):
for fileInfo in os.ilistdir(folder):
name = folder + fileInfo[0]
if fileInfo[1] == 16384:
print("Scanning " + name, end="\r\n")
delete_recursive(name + '/')
os.rmdir(name)
else:
if name == 'boot.py':
print("Skipping boot.py", end="\r\n")
else:
print("Deleting " + name, end="\r\n")
os.remove(name)


if __name__ == '__main__':
try:
main(sys.argv[1:])
exitcode = 0
except:
traceback.print_exc()
exitcode = 1
finally:
input('Press ENTER to continue')
sys.exit(exitcode)
delete_recursive('')
114 changes: 0 additions & 114 deletions scripts/microrepl.py

This file was deleted.

37 changes: 16 additions & 21 deletions scripts/microupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
from typing import List, Iterable, TypeVar, Sequence, Set

from docopt import docopt
from ampy.pyboard import Pyboard
from ampy.files import Files, DirectoryExistsError

from mpremote.transport_serial import SerialTransport
from mpremote.transport import TransportError

__all__ = []

Expand All @@ -53,11 +52,9 @@ def main(args: List[str]) -> None:

port = opts['PORT']
print('Connecting to {}'.format(port), file=sys.stderr)
board = Pyboard(port)
files = Files(board)
rel_root = os.path.relpath(root, os.getcwd())

wait_for_board()
transport = SerialTransport(device=port)

if os.path.isdir(root):
to_upload = [os.path.join(rel_root, x)
Expand All @@ -74,15 +71,15 @@ def main(args: List[str]) -> None:
file=sys.stderr, flush=True)
remote_dir = os.path.dirname(path)
if remote_dir:
make_dirs(files, remote_dir, created_cache)
with open(local_path, 'rb') as fd:
files.put(remote_path, fd.read())
make_dirs(transport, remote_dir, created_cache)
transport.enter_raw_repl(soft_reset=False)
transport.fs_put(local_path, remote_path)

print('Soft reboot', file=sys.stderr, flush=True)
soft_reset(board)
soft_reset(transport)


def make_dirs(files: Files, path: str,
def make_dirs(transport: SerialTransport, path: str,
created_cache: Set[str] = None) -> None:
"""Make all the directories the specified relative path consists of."""
if path == '.':
Expand All @@ -91,16 +88,19 @@ def make_dirs(files: Files, path: str,
created_cache = set()
parent = os.path.dirname(path)
if parent and parent not in created_cache:
make_dirs(files, parent, created_cache)
with suppress(DirectoryExistsError):
make_dirs(transport, parent, created_cache)
posix_path = path.replace(os.path.sep, '/')
try:
posix_path = path.replace(os.path.sep, '/')
files.mkdir(posix_path)
transport.fs_mkdir(posix_path)
created_cache.add(path)
except TransportError:
pass


def soft_reset(board: Pyboard) -> None:
def soft_reset(transport: SerialTransport) -> None:
"""Perform soft-reset of the ESP8266 board."""
board.serial.write(b'\x03\x04')
transport.enter_raw_repl(soft_reset=True)


def list_files(path: str, excluded: List[str]) -> Iterable[str]:
Expand All @@ -116,11 +116,6 @@ def list_files(path: str, excluded: List[str]) -> Iterable[str]:
yield os.path.relpath(os.path.join(root, f), path)


def wait_for_board() -> None:
"""Wait for some ESP8266 devices to become ready for REPL commands."""
time.sleep(0.5)


def progress(msg: str, xs: Sequence[T]) -> Iterable[T]:
"""Show progress while iterating over a sequence."""
size = len(xs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jetbrains.micropython.actions

import com.intellij.facet.ui.ValidationResult
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.jetbrains.micropython.settings.firstMicroPythonFacet
Expand All @@ -15,4 +16,6 @@ abstract class MicroPythonAction : AnAction() {
e.presentation.isEnabledAndVisible = false
}
}

override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT
}

This file was deleted.

Loading
Loading