gpy file system
-
I've been frustrated in my attempts to do file handling in micropython on the gpy. Basic functions like os.rename are not available. I decided to see what others might be doing. https://github.com/Bucknalla/resin-pycom-ota is a pycom project. At https://github.com/Bucknalla/resin-pycom-ota/blob/master/Pycom/1.0.0/flash/lib/OTA.py line 70 I see os.rename(new_path, dest_path) WTF! are there better versions of os on other pycom devices different to whats on the gpy?
-
@kjm upip is meant to install (micro)python packages on a micropython device. So it downloads and extracts micropython packages. You have to tell yourself whether it is useful for you. But at least it is a good example. Paul is an excellent Python specialist and programmer.
There is a upip.help() telling how to use it. And upip.tarfile is, as far as I understand it, the tarfile extractor.
-
@robert-hh So I'm looking for alternatives to tar=tarfile.open & tar.extractall Rob:
upip.tarfile.py is an tar opener maybe? How would anyone know since the author gives no clue on what it does or how to use it?
upip.py is looking like an extractor maybe? But it's only for specialist code not just any tar "Note: only MicroPython packages (usually, named micropython-*) are supported for installation, upip does not support arbitrary code in setup.py."
-
@kjm The files of interest are upip.py and upip.tarfile.py. They run on an ESP32 and ESP8266 with MicroPython from micropython.org and should be mostly compatible to the Pycom branch.
-
@robert-hh This is never gonna install on the gpy with cmds like mkdir -p ~/.micropython/lib/ in it Rob
-
@kjm There is some of a tarfile implementation here: https://github.com/micropython/micropython-lib/tree/master/upip
Maybe that helps.
-
@kjm It's possible & requires a firmware change. At the end, it looks like:
>>> help("modules") MQTTClient gc sqnscodec uio MQTTConst hashlib sqnscrc ujson MQTTDeviceShadow json sqnstp umachine MQTTLib machine sqnsupgrade uos MQTTMsgHandler math ssl upysh MQTTShadowManager micropython station uqueue __main__ mount struct ure _boot network sys uselect _main os time uselect _thread pycom ubinascii usocket array pye ubinascii ussl binascii queue ucollections ustruct builtins re ucrypto utime cmath reload uctypes utimeq crypto select uerrno uzlib errno socket uerrno websocket framebuf sqnsbrz uhashlib Plus any modules on the filesystem
Edit: I made a PR for that.
-
@robert-hh Any chance of a link to the modules docs Rob?
-
@kjm for the builtins set of names and commands, you can use:
import builtins
dir(builtins)For the set of modules you have to use the documentation. help("modules") is not implemented in the Pycom branch of micropython.
-
@robert-hh Tnx Rob, my bad, a typo. I'm trying to reuse an OTA directory updater from an Rpi in the gpy. I've been lucky enough to find some code snippet alternatives online for cmds like os.copyfileobject but replacements for the likes of os.rmtree still elude me, mostly because they in turn need path or walk.
- Is it possible to customise os to add missing cmds?
- Is there something like dir(os) that shows what python cmds are available on the gpy? I can't seem to get tarfile.open() to work
>>> tar = tarfile.open('/flash/100.tar') Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'tarfile' is not defined
-
@kjm if you enter the commands:
import os dir(os)
you should see all commands that are supported. Looking at the sources, there is no difference in os or uos between the various Pycom modules. So your difficulties must be cause by something else, like the target file exists, or wrong spelling/coding of os.rename(). Try to retype it.
What is exactly the error which you get?