tfatool icon indicating copy to clipboard operation
tfatool copied to clipboard

Make everything work through a connection context

Open TadLeonard opened this issue 7 years ago • 2 comments

A Session object to keep connection state

The session.Session object keeps track of: - Which filters are applied - What the URL of the FlashAir device is (this is for #12) - What the local directory is - What the remote directory is

It's not clear how useful this will be to users of tfatool, but this object also provides some context managers so you can write code like:

session = session.Session(url="http://10.10.3.2", filters=(lambda f: f.size < 10000,))
with session.filtered(lambda f: f.filename.endswith(".jpg")):
    ...  # upload, download, sync, or whatever with the JPEG filter
    ...  # note that the original size filter is no longer applied
with session.added_filters(lambda f: f.filename.endswith(".jpg")):
    ...  # upload, download, sync, or whatever withe the JPEG filter
    ... # note that the original size filter is still applied
with session.transferring_to(local_dir="~/Trash/"):
    ...  # temporarily throw things in the trash
    ...  # note that both local_dir and remote_dir can be specified (or omitted)

Note that this means you have to pass Session everywhere

Functions in the sync, command, upload, and config modules now take a Session object to gather all the info they need about filters, local/remote directories, and the FlashAir device URL.

A call for testing

If anybody's listening, this branch needs functional testing. The procedure goes like this:

  1. Install this branch: git fetch followed by git checkout session
  2. Run the functional tests: pytest test_functional.py -s -v

Any help is hugely appreciated. I can't do it 'cause I've lost my FlashAir device.

TadLeonard avatar Feb 05 '18 06:02 TadLeonard

I'm not sure if this project is still in development, but I'm in need of this tool so that I can watch/sync multiple Flashair cards on the same network. What's the current state of the functionality of this branch?

joshbg2k avatar Jul 26 '19 21:07 joshbg2k

Hello. I am getting this trying to run the test_functional script. Seems the command file is trying to load up a default session, but the NamedTuple cannot take no arguments? Not sure if this is a python version issue or not? I am running 3.6.0.

I get same response trying to run any other command.

Jamess-MacBook-Pro-2016:tfatool jamesrusso$ python test_functional.py 
Traceback (most recent call last):
  File "test_functional.py", line 7, in <module>
    from tfatool import command, upload, sync
  File "/Users/jamesrusso/tfatool/tfatool/command.py", line 22, in <module>
    def map_files(session: Session = Session()) -> Dict[str, FileInfo]:
  File "/Users/jamesrusso/tfatool/tfatool/session.py", line 20, in __init__
    self._session = _Session(*args, **kwargs)
TypeError: __new__() missing 4 required positional arguments: 'url', 'remote_dir', 'local_dir', and 'filters'
Jamess-MacBook-Pro-2016:tfatool jamesrusso$ 

jamesrusso avatar Sep 27 '19 14:09 jamesrusso