getting system root path

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
devnull
Posts: 54
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall

getting system root path

Postby devnull » Sat Mar 18, 2017 12:40 am

Is there a better, more reliable or more efficient way of determining the system root path other than what I came up with ??

Code: Select all

import sys

## ESP32
_root = sys.path[1].split('lib')[0] #['', '/flash/lib']
print(_root) # /flash/

## ESP8266
_root = sys.path[1].split('lib')[0] #['', '/lib', '/']
print(_root) # /

User avatar
pythoncoder
Posts: 1385
Joined: Fri Jul 18, 2014 8:01 am

Re: getting system root path

Postby pythoncoder » Sat Mar 18, 2017 8:56 am

I appreciate this isn't really answering your question, but with a recent firmware build the ESP8266 is consistent with other ports in having the flash filesystem at '/flash':

Code: Select all

MicroPython v1.8.1-1435-g528aeb3-dirty on 2017-03-14; ESP module with ESP8266
Type "help()" for more information.
>>> import os
>>> os.listdir('/')
['flash']
>>>
Peter Hinch

devnull
Posts: 54
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall

Re: getting system root path

Postby devnull » Sat Mar 18, 2017 9:47 am

Hmm, if that's the case, maybe I should change my 8266 v1.8.7 setup to use the /flash root.

If I don't want to re-compile, is it OK to rebuild the sys.path on boot.py ??

Code: Select all

del sys.path[:]
sys.path.extend(['','/flash/lib'])


Update
No that won't work as boot.py still needs to be loaded from /

Is qstrdefsport.h the correct file to set the sys.path ??

Code: Select all

// Entries for sys.path
Q(/)
Q(/lib)

User avatar
pythoncoder
Posts: 1385
Joined: Fri Jul 18, 2014 8:01 am

Re: getting system root path

Postby pythoncoder » Sun Mar 19, 2017 10:41 am

I'm puzzled. This is what I see:

Code: Select all

MicroPython v1.8.1-1435-g528aeb3-dirty on 2017-03-14; ESP module with ESP8266
Type "help()" for more information.
>>> import os, sys
>>> sys.path
['', '/flash/lib', '/flash']
>>> os.listdir('/')
['flash']
>>> os.listdir('/flash')
['boot.py', 'main.py', 'roundrobin.py', 'utelnetserver.py', 'art.py', 'art1.py', 'aremote.py']
>>>

Note the location of boot.py and main.py
Peter Hinch


Return to “General Discussion and Questions”

Who is online

Users browsing this forum: No registered users and 1 guest