TadLeonard / tfatool

Tools for managing files with the Toshiba FlashAir wireless SD card
MIT License
36 stars 8 forks source link

Make everything work through a connection context #13

Open TadLeonard opened 6 years ago

TadLeonard commented 6 years ago

A Session object to keep connection state

The session.Session object keeps track of:

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.

joshbg2k commented 5 years ago

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?

jamesrusso commented 5 years ago

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$