micropython-ctl icon indicating copy to clipboard operation
micropython-ctl copied to clipboard

Allow a target root for sync, maybe even ignore patterns

Open morungos opened this issue 4 years ago • 1 comments

First of all, this tool is exactly what I need to do some long-term work with a pycom setup on a Raspberry Pi (where the IDEs are frankly useless due to serial port hell).

However, the sync CLI function could be made significantly more useful with a few small tweaks, and especially, the ability to target a directory other than root. We want to update /fs, without touching /sd, and by only targeting root and removing non-matching files, we will always wipe the sd on sync, and need to create a special fs folder as well. In an ideal world, we'd also want to not touch deployed config files; that is significantly less crucial, but it's in more or less the same code, so would be handy.

What would be amazingly useful would be to allow an optional target, such as /fs, so the upload only affects part of the file system.

The code is nicely clear enough, so I'd be happy to assemble something and make a PR if you are okay with that.

morungos avatar Jul 22 '21 18:07 morungos

I don't know whether this is still of use to you, but I've made progress on this, and it seemed flush out a few issues in the current sync implementation.

What I've done (in a fork; all relating to the sync CLI command):

  • added a --dry-run option to allow people to not change a device
  • (for now, as a hack) allow a filter of pycache
  • used relative files for both source and target, applied in matching, using path.join() and path.resolve(), so, e.g., mctl sync ./src/py /flash/ will work

What I found:

  • I think some of the calls to remove existing files might break on directories, because the remove implementation is a bit sensitive. Adding a check to decide whether or not is this a directory, and then passing recursive only if so, seemed to work around that.
  • It also seems that using "." rather than "./" might cause a few issues, but using path functions more to accommodate those seemed to remove those problems -- in fact, I needed to use something like "./xxx" anyway, and I've now got that working fine too.
  • I didn't see much testing of the CLI layer to add, but can contribute something if you like. I've not used typescript all that much so this will be a chance to strengthen that a bit. Think that can be done using mocking, though. No need to touch a device at that level.

So I'll have something to make a PR with soon if you are interested

The bulk of this is here if you're interested: https://github.com/morungos/micropython-ctl/commit/0f311572d68a6fb34b375052204a57fb657d31bc

morungos avatar Jul 27 '21 14:07 morungos