Commit Graph

30 Commits

Author SHA1 Message Date
Jeff Epler
1c09a0b494
fix string construction 2023-09-22 13:53:56 -05:00
Dan Halbert
d582407b06 pre-commit fixes 2023-08-14 00:59:22 -04:00
Jeff Epler
a8bbb21eeb
Use short-circuiting or (also may save some code size)
Co-authored-by: Dan Halbert <halbert@adafruit.com>
2023-03-29 10:09:01 -05:00
Jeff Epler
cc3d0f6fa1
getenv: treat a read error like eof
Otherwise, the following would occur:
 * settings.toml is in the process of being written by host computer
 * soft-reset begins
 * web workflow tries to grab CIRCUITPY_WIFI_SSID, but loops forever
   because FAT filesystem is in inconsistent state and file reads error
 * settings.toml write by host computer never completes and the filesystem
   remains corrupt
 * restarting yields a soft-bricked device, because startup reads
   CIRCUITPY_WIFI_SSID again
2023-03-29 10:04:06 -05:00
Jeff Epler
7a005aa96b
break out after reading the value
This is a small optimization, it avoids reading the full file when an
early key is requested.

In the case of an *invalid* TOML file such as
```
K=80
K=81
```
this stops the value of K actually returned being 8081 and makes it 80
instead; but as it's a malformed file it doesn't really matter much.
2022-12-28 13:24:38 -06:00
Jeff Epler
15a24b400d
Permit trailing whitespace in getenv_int 2022-12-28 12:37:27 -06:00
Jeff Epler
f6b69cf5e3
Allow settings.toml to end without a newline 2022-12-26 10:53:58 -06:00
Jeff Epler
4dbbfa0931
Print errors to repl about getenv 2022-12-26 10:53:58 -06:00
Jeff Epler
d40ba94449
explain why this is its own file 2022-12-13 13:19:10 -06:00
Jeff Epler
35f2046ab2
Fix returning GETENV_ERR_LENGTH for over-long strings 2022-12-13 12:02:07 -06:00
Jeff Epler
dd6dd5df21
rework the getenv test again
* use a virtual fat filesystem during the test
 * this makes the file I/O part more closely patch runtime which is nice
 * side-steps the need to add a special function for testing
   * but test still can't be run on a device, because the vfs calls
     are incompatible, and you intentionally can't remount "/" anyway
 * and side-steps problems with storing 'bad' toml files
2022-12-10 12:58:08 -06:00
Jeff Epler
040fac0724
No need to track excess length
.. this is a relic from when the actual required length was given
back to the caller
2022-12-09 14:29:14 -06:00
Jeff Epler
cc7d550407
Really finish renaming to getenv 2022-12-09 14:28:46 -06:00
Jeff Epler
44f15d563d
Rename "environ" errors to "getenv" errors 2022-12-09 14:14:53 -06:00
Jeff Epler
3a92c079fc
Finish renaming os_environ_get_key to os_getenv
.. for consistency.
2022-12-09 14:07:23 -06:00
Jeff Epler
3459fe322b
Withdraw the _environ module
This existed solely for testing, so expose it a different way during
the unix coverage build

Also turn off os.getenv support on samd21.
2022-12-08 15:33:10 -06:00
Jeff Epler
ef2bfdb5db
dotenv becomes settings.toml 2022-12-08 12:44:20 -06:00
Isaac Benitez
71d649613f Updated utime() to take a 2-tuple instead of a plain int 2022-09-22 00:56:44 -07:00
Isaac Benitez
5a21c30ab2 Added utime() to the os librady 2022-09-18 18:43:27 -07:00
Scott Shawcroft
a30de85d57
Add dotenv read support
os.getenv() will use it (when available) to load variables from
/.env

This will also be useful when we need secrets or config for
CircuitPython outside of the VM (like WiFi credentials.)

Fixes #4212
2022-05-18 14:01:35 -07:00
microDev
a52eb88031
run code formatting script 2021-03-15 19:27:36 +05:30
Scott Shawcroft
2b4ad1ed03
Fix warnings that come from -O3 (I think) 2021-01-20 19:16:56 -08:00
Diego Elio Pettenò
34b4993d63 Add license to some obvious files. 2020-07-06 19:16:25 +01:00
jepler
676f7aa808 os_listdir: This can be long-running, run background tasks
While finding sources of clicks and buzzes in nrf i2sout, I identified
this site as one which could be long running.  Reproducer code was to
play a 22.05kHz sample and repeatedly print `os.listdir('')`
2019-09-09 20:14:02 -05:00
Noralf Trønnes
28383afa11 shared-module/os: Fix os.mkdir('a/b')
This fixes commit a99f9427420d("'/' and '\' are also acceptable ends of the path now") which broke mkdir.
The problem is where the directory name is a single letter like this:
>>> os.mkdir('a')
>>> os.mkdir('a/b')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 17] File exists
>>> os.mkdir('a/bb')
>>>

I wasn't smart enough to fix this in the oofatfs library, so I did it in the os shared module by
creating a path lookup function for the os methods that only deals with directories. I reverted
the library change introduced by the aforementioned commit.

This means that os.stat and os.rename can't handle trailing slashes. This is to avoid allowing
filenames with trailing slashes to pass through. In order to handle trailing slashes for these
it would be necessary to check if it really is a directory before stripping. I didn't do this
since the original issue was to make os.chdir tolerate trailing slashes.

There's an open MicroPython issue #2929 wrt. trailing slashes and mkdir.
2018-11-09 19:20:56 +01:00
Dan Halbert
bc760dd341 WIP: complete manual inspection of all significant changes 2018-07-23 21:34:25 -04:00
Dan Halbert
e2e01efa84 compiles and runs; hangs on import storage;storage.VfsFat.<tab> 2018-07-13 22:51:10 -04:00
Dan Halbert
327b0f76da fix os.listdir() when current dir is '/' 2018-06-15 10:51:03 -04:00
Scott Shawcroft
c797f3cb24 shared-module: Fix os.listdir to correctly return list rather than
iterator.
2017-06-28 12:51:32 -07:00
Scott Shawcroft
778e975936 Split uos module into os and storage.
os is a subset of CPython's os. storage contains additional
file system mounting functionality based on UNIX's mount
management.

Fixes #140
2017-06-27 15:17:30 -07:00