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

Upyutils should use on the device only default functionality #33

Open
dsl400 opened this issue Oct 20, 2022 · 12 comments
Open

Upyutils should use on the device only default functionality #33

dsl400 opened this issue Oct 20, 2022 · 12 comments

Comments

@dsl400
Copy link
Contributor

dsl400 commented Oct 20, 2022

It would be nice to be able to use upydev get main.py without uploading aditional files onto the device

get the file tree from the device and make all the filtering on the pc

this concept should be applied to other scripts where possible.

@Carglglz
Copy link
Owner

Carglglz commented Oct 20, 2022

@dsl400

It would be nice to be able to use upydev get main.py without uploading aditional files onto the device

You can, just use -fg flag, see upydev get -h

usage:  get [-h] [-dir DIR] [-d D] [-fg] [-b B]
            file/pattern/dir [file/pattern/dir ...]

download files from device

positional arguments:
  file/pattern/dir  indicate a file/pattern/dir to download

optional arguments:
  -h, --help        show this help message and exit
  -dir DIR          path to download from
  -d D              depth level search for pattrn
  -fg               switch off faster get method
  -b B              read buffer for faster get method

[EDIT] Actually you're right, I forgot I chose this to enable pattern matching with nanoglob.py and a faster get method withupysh.py by default 🤔. I could merge #35 , but I prefer this not to be the default method, and only enable this method if using -fg flag. The reason is that iterating over device filesystem sending a command and receiving a list doesn't scale well, that is why I've tried to reduce back and forth operations between host and device and why I opted for in device script.

TLDR: I'm OK with your approach just don't set it as a default, i.e don't delete existing code, just use -fg flag to use your method and I will merge it after some tests. (Although I'm not sure when I will release next version) 👍🏼

Also note -fg is True by default,

"-fg": dict(help='switch off faster get method',
                                required=False,
                                default=True,
                                action='store_false'),

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 20, 2022

@Carglglz commented 2 hours ago

2 hours ... about how long it took me to make a PR

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 20, 2022

#35 will not work because it reaches self.fastfileio.init_get(dst_name, sz)

#35 could be usefull to implement pattern matching when using -fg

@Carglglz
Copy link
Owner

#35 will not work because it reaches self.fastfileio.init_get(dst_name, sz)

True, the size is needed for the progress bar and to check that the file size received matches. So you will need to modify read_file_tree to return a list of (name, size) tuples (or (size, name) not sure about the order right now)

#35 could be usefull to implement pattern matching when using -fg

Yes that's what I think too 👍🏼

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 20, 2022

#35 modified

btw, is there a fast way to upload nanoglob.py ?

@Carglglz
Copy link
Owner

Yes, upydev update_upyutils nanoglob.py, or upydev enable_sh (this will install shasum.py, upysh.py, upysh2.py and nanoglob.py)

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 20, 2022

it would be nice to present the user with this commands when the scripts are not available instead of some weird error

$ upydev get main.py 

nanoglob not availble
use upydev get main.py  -fg or upydev update_upyutils nanoglob.py 

@Carglglz
Copy link
Owner

it would be nice to present the user with this commands when the scripts are not available instead of some weird error

I agree, I should update the docs about get command, and improve the error message too. I will do it for next release 👍🏼

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 21, 2022

can we set arguments like -fg in upydev_.config ?

@Carglglz
Copy link
Owner

can we set arguments like -fg in upydev_.config ?

Not right now, however have a look at register command, you could register your device and add this flag in the shell function, e.g.

$ upydev register -@ esp8266
Registering Device: esp8266 ...
Device: esp8266 registered
Reload .profile with "$ source /Users/$USER/.profile" or open a new terminal to apply the new command

and in profile add -fg flag in the shell function

#UPYDEV DEVICE esp8266
function esp8266() { upydev "$@" -fg -@ esp8266; }
function _argcomp_upydev() { _python_argcomplete upydev; }
complete -o bashdefault -o default -o nospace -F _argcomp_upydev esp8266

Then source ~/.profile and that's it. 👍🏼

@dsl400
Copy link
Contributor Author

dsl400 commented Oct 21, 2022

the register command scares me because it allows anyone to overwrite system commands without being aware

@Carglglz
Copy link
Owner

the register command scares me because it allows anyone to overwrite system commands without being aware

I think I know what you mean, but it is pretty easy to test if a name is already a command with which, type, man, or even tab for autocompletion, etc before using upydev register, also it can take an alias as argument so you can change the name. e.g.

$ upydev register esp8 -@ esp8266
Registering Device: esp8266 ...
Device: esp8266 registered as esp8
Reload .profile with "$ source /Users/$USER/.profile" or open a new terminal to apply the new command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants