I think you guys should check this out....

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jdcrunchman
Posts: 17
Joined: Wed Jun 19, 2019 8:17 pm

I think you guys should check this out....

Post by jdcrunchman » Fri Jul 26, 2019 7:28 pm

I created a file Quickies.py for the purpose of looking at files and
directories.

I'm running this on an ESP32 connected to my Powerbook Pro, running 10.13.6
I'm using Atom IDE, with the PyMakr plugin that allows me direct access to the ESP32.

I hacked up this simple file. For the purpose of allowing me access to files and changing directories.
----------- Quickies.py ----------
from os import listdir, remove, chdir


def ls():
  print(listdir())


## remove selected file
def rm(fname):
    remove(fname)
    print (fname + ' removed')


def dispfile(fname):
    with open(fname, "r") as f:
        for line in f:
            print(line.rstrip())


def cd(fname):
    chdir(fname)
-------- end --------


Then I ran it.... after uploading it.


MicroPython v1.11-45-g14cf91f70 on 2019-06-16; ESP32 module with ESP32
Type "help()" for more information.
>>>
>>> dir() .       <--- I checked to see of all functions got loaded,  they did.
['uos', 'dispfile', 'chdir', 'remove', 'bdev', 'listdir', 'rm', '__name__', 'ls', 'gc', 'cd', 'time']
>>> ls() .        <---- I did the "ls()" function,  and it worked.
['boot.py', 'img', 'microWebSrv.py', 'microWebSocket.py', 'microWebTemplate.py', 'mainweb.py', 'Networking.py', 'trace.py', 'startup.py', 'hotspot.py', 'www', 'MainSetup.py', 'test1.pyhtml', 'tabletest.pyhtml', 'Messaging.html', 'css', 'user.py', 'lora_api.py', 'runtest.py', 'fonts', 'Older files', 'project.pymakr', 'Quickies', 'ideas.py', 'index.html', 'p-contacts.html', 'p-msg.html', 'quickies.py', 'textApp.py', 'w-msg.html', 'webview.py']
>>> cd('www') .   <--- next I CD'ed into the "www" directory (which in fact contains nothing)
>>> ls() .    <---- I did the ls() again,   to confirm there were no files in that directory.   But notice this....  the actual files listed this 2nd time,  are different then whats in the root above. WHERE DID THESE FILES COME FROM.
['Older files', 'css', 'fonts', 'img', 'www', 'MainSetup.py', 'project.pymakr', 'Quickies', 'ideas.py', 'lora_api.py', 'mainweb.py', 'microWebSocket.py', 'microWebSrv.py', 'microWebTemplate.py', 'quickies.py', 'textApp.py', 'user.py', 'webview.py', 'index.html', 'p-contacts.html', 'p-msg.html', 'w-msg.html'] .  <---- But this is what I get....   I get these files...   where did they come from,  the directory is supposed to be empty.


Next,  I did things by hand...
>>> import os .     <--- imported os to see if just this might have changed things...
>>> ls() .               <--- it didn't change things.
['Older files', 'css', 'fonts', 'img', 'www', 'MainSetup.py', 'project.pymakr', 'Quickies', 'ideas.py', 'lora_api.py', 'mainweb.py', 'microWebSocket.py', 'microWebSrv.py', 'microWebTemplate.py', 'quickies.py', 'textApp.py', 'user.py', 'webview.py', 'index.html', 'p-contacts.html', 'p-msg.html', 'w-msg.html']
>>> os.listdir() .    <---- but look at this!!!   it seems that when I did the earlier ls() while within the "www" directory,  it listed the files in the root directory.
['Older files', 'css', 'fonts', 'img', 'www', 'MainSetup.py', 'project.pymakr', 'Quickies', 'ideas.py', 'lora_api.py', 'mainweb.py', 'microWebSocket.py', 'microWebSrv.py', 'microWebTemplate.py', 'quickies.py', 'textApp.py', 'user.py', 'webview.py', 'index.html', 'p-contacts.html', 'p-msg.html', 'w-msg.html']
>>> os.getcwd() .   <---- I wanted to confirm I was in the WWW directory.
'/www' .                   <---- I was.
>>>
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)


So,  it seemed that by running the Quickies.py file,  the run command must have failed.


So,  by doing it by hand,  and typing it into the >>> prompt,  here is what I get


>>> import os
>>> os.listdir() .   <--- this is as expected
['Older files', 'css', 'fonts', 'img', 'www', 'MainSetup.py', 'project.pymakr', 'Quickies', 'ideas.py', 'lora_api.py', 'mainweb.py', 'microWebSocket.py', 'microWebSrv.py', 'microWebTemplate.py', 'quickies.py', 'textApp.py', 'user.py', 'webview.py', 'index.html', 'p-contacts.html', 'p-msg.html', 'w-msg.html']
>>>
>>>
>>> os.chdir('www') .   <--- changed to www
>>> os.listdir() .           <--- and this is what I expected...
[]
>>>


WTF?   What am I doing wrong... for most of the time,  it's my stupid mistakes
because my eyes are bad,  and I have trouble typing....   But with my friend watching over me,  he also confirms this is not something I'm doing wrong...

I've also posted this as a possible bug report for MicroWebSrv so I sent this to the MicroWebSrv developers as well, to bring this to their
attention.

Could this be a bug in Micropython?   And more importantly,  why the F**k is MicroWebSrv not able to deal with sub directories...   Any self respecting web server not being able to deal with sub directories,  should certainly concern them.


As soon as I can figure out how,  and hopefully get a workaround,  I want to post this to your GitHub,  I just want to make sure it's not MY stupid mistake.


John


Sent with ProtonMail Secure Email.

cefn
Posts: 230
Joined: Tue Aug 09, 2016 10:58 am

Re: I think you guys should check this out....

Post by cefn » Sun Jul 28, 2019 2:40 pm

Hi, John

Given what you've written it would've consistent with quite a few PEBCAK (user) errors. For example maybe there's a complete copy of the files from the root in the www directory, or maybe this was all running in a session where ls, cd etc weren't defined by Quickies.py at all. You say you ran it, but not how.

For a good bug report people should be able to recreate and verify the error, for example all steps recreated in a main.py including perhaps the steps to create a filesystem showing the broken behaviour from a newly flashed micropython on ESP32.

I strongly believe there's a simpler explanation than Micropython being broken in the way you suggest and trying to script the failure from a blank system usually reveals what your own error was in the first place.

Good luck and if the error can be recreated from a clean start with a script it will be a much clearer report which people could help you with. If it can't then it probably wasn't a bug in the first place.

jdcrunchman
Posts: 17
Joined: Wed Jun 19, 2019 8:17 pm

Re: I think you guys should check this out....

Post by jdcrunchman » Sun Jul 28, 2019 5:23 pm

You wrote: "Given what you've written it would've consistent with quite a few PEBCAK (user) errors"

What is a "PEBCAK (user) errors"

I've had to reflash the ESP32

Then, there was a synch problem involving the PyMakr in Atom IDE, I did so many tries to fix this strange bug, I just wasn't able to identify the one thing that might have fixed it.

John

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: I think you guys should check this out....

Post by Roberthh » Sun Jul 28, 2019 6:36 pm

@jdcrunchman Very nice. Did you see the upysh module at https://github.com/pfalcon/micropython-lib.git?
It exists quite a while.
Or the variant made by @HermannSW: https://github.com/Hermann-SW/micropyth ... ster/upysh

jdcrunchman
Posts: 17
Joined: Wed Jun 19, 2019 8:17 pm

Re: I think you guys should check this out....

Post by jdcrunchman » Mon Jul 29, 2019 5:09 pm

cefn replied:

>maybe this was all running in a session where ls, cd etc weren't defined by Quickies.py at all. You say you ran it, but not how.

I just defined simple UNIX like commands, then I just ran it, which was supposed to bring in these temporary functions making it easier for me to type in familiar UNIX like commands.

Roberthh replied:

>Very nice. Did you see the upysh module at https://github.com/pfalcon/micropython-lib.git?
It exists quite a while.

Not sure what that is, but I'll check it out.

Post Reply