8000 Split uos module into os and storage. · ladyada/circuitpython@778e975 · GitHub
[go: up one dir, main page]

Skip to content

Commit 778e975

Browse files
committed
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 adafruit#140
1 parent e87a61f commit 778e975

File tree

17 files changed

+851
-219
lines changed

17 files changed

+851
-219
lines changed

atmel-samd/Makefile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 8000 @@ SRC_C = \
187187
fatfs_port.c \
188188
flash_api.c \
189189
main.c \
190-
moduos.c \
191190
mphalport.c \
192191
samd21_pins.c \
193192
shared_dma.c \
@@ -228,25 +227,26 @@ STM_SRC_C = $(addprefix stmhal/,\
228227
)
229228

230229
SRC_COMMON_HAL = \
231-
board/__init__.c \
232-
microcontroller/__init__.c \
233-
microcontroller/Pin.c \
234230
analogio/__init__.c \
235231
analogio/AnalogIn.c \
236232
analogio/AnalogOut.c \
237233
audioio/__init__.c \
238234
audioio/AudioOut.c \
235+
board/__init__.c \
236+
busio/__init__.c \
237+
busio/I2C.c \
238+
busio/SPI.c \
239+
busio/UART.c \
239240
digitalio/__init__.c \
240241
digitalio/DigitalInOut.c \
242+
microcontroller/__init__.c \
243+
microcontroller/Pin.c \
244+
neopixel_write/__init__.c \
245+
os/__init__.c \
241246
pulseio/__init__.c \
242247
pulseio/PulseIn.c \
243248
pulseio/PulseOut.c \
244249
pulseio/PWMOut.c \
245-
busio/__init__.c \
246-
busio/I2C.c \
247-
busio/SPI.c \
248-
busio/UART.c \
249-
neopixel_write/__init__.c \
250250
time/__init__.c \
251251
touchio/__init__.c \
252252
touchio/TouchIn.c \
@@ -271,6 +271,8 @@ SRC_SHARED_MODULE = \
271271
bitbangio/OneWire.c \
272272
bitbangio/SPI.c \
273273
busio/OneWire.c \
274+
os/__init__.c \
275+
storage/__init__.c \
274276
uheap/__init__.c \
275277

276278
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \

atmel-samd/common-hal/os/__init__.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "genhdr/mpversion.h"
28+
#include "py/mpconfig.h"
29+
#include "py/objstr.h"
30+
#include "py/objtuple.h"
31+
#include "py/qstr.h"
32+
33+
STATIC const qstr os_uname_info_fields[] = {
34+
MP_QSTR_sysname, MP_QSTR_nodename,
35+
MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine
36+
};
37+
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "samd21");
38+
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "samd21");
39+
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING);
40+
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE);
41+
STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME);
42+
43+
44+
STATIC MP_DEFINE_ATTRTUPLE(
45+
os_uname_info_obj,
46+
os_uname_info_fields,
47+
5,
48+
(mp_obj_t)&os_uname_info_sysname_obj,
49+
(mp_obj_t)&os_uname_info_nodename_obj,
50+
(mp_obj_t)&os_uname_info_release_obj,
51+
(mp_obj_t)&os_uname_info_version_obj,
52+
(mp_obj_t)&os_uname_info_machine_obj
53+
);
54+
55+
mp_obj_t common_hal_os_uname(void) {
56+
return (mp_obj_t)&os_uname_info_obj;
57+
}

atmel-samd/moduos.c

Lines changed: 0 additions & 122 deletions
This file was deleted.

atmel-samd/mpconfigport.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ extern const struct _mp_obj_module_t digitalio_module;
137137
extern const struct _mp_obj_module_t pulseio_module;
138138
extern const struct _mp_obj_module_t busio_module;
139139
extern const struct _mp_obj_module_t board_module;
140-
extern const struct _mp_obj_module_t uos_module;
140+
extern const struct _mp_obj_module_t os_module;
141+
extern const struct _mp_obj_module_t storage_module;
141142
extern const struct _mp_obj_module_t time_module;
142143
extern const struct _mp_obj_module_t neopixel_write_module;
143144
extern const struct _mp_obj_module_t uheap_module;
@@ -174,7 +175,8 @@ extern const struct _mp_obj_module_t usb_hid_module;
174175
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
175176
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
176177
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
177-
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&uos_module }, \
178+
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \
179+
{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \
178180
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
179181
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module }, \
180182
{ MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module }, \

docs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
Adafruit's MicroPython Documentation
1+
Adafruit's CircuitPython Documentation
22
=========================
33

44
The latest documentation can be found at:
5-
http://adafruit-micropython.readthedocs.io/en/latest/
5+
http://circuitpython.readthedocs.io/en/latest/
66

77
The documentation you see there is generated from the files in the whole tree:
8-
https://github.com/adafruit/micropython/tree/master
8+
https://github.com/adafruit/circuitpython/tree/master
99

1010
Building the documentation locally
1111
----------------------------------
@@ -19,8 +19,8 @@ preferably in a virtualenv:
1919
pip install sphinx
2020
pip install sphinx_rtd_theme
2121

22-
In `micropython/`, build the docs:
22+
In `circuitpython/`, build the docs:
2323

2424
sphinx-build -v -b html . _build/html
2525

26-
You'll find the index page at `micropython/docs/_build/html/index.html`.
26+
You'll find the index page at `_build/html/index.html`.

esp8266/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ SRC_C = \
9393
machine_hspi.c \
9494
modesp.c \
9595
modnetwork.c \
96-
modutime.c \
97-
moduos.c \
9896
modonewire.c \
9997
ets_alt_task.c \
10098
fatfs_port.c \
@@ -119,6 +117,7 @@ SRC_COMMON_HAL = \
119117
busio/SPI.c \
120118
busio/UART.c \
121119
neopixel_write/__init__.c \
120+
os/__init__.c \
122121
time/__init__.c \
123122
board/__init__.c
124123

@@ -139,6 +138,8 @@ SRC_SHARED_MODULE = \
139138
bitbangio/SPI.c \
140139
busio/I2C.c \
141140
busio/OneWire.c \
141+
os/__init__.c \
142+
storage/__init__.c \
142143

143144
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
144145
$(addprefix shared-module/, $(SRC_SHARED_MODULE))

esp8266/moduos.c renamed to esp8266/common-hal/os/__init__.c

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2015 Josef Gajdusek
7+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
78
*
89
* Permission is hereby granted, free of charge, to any person obtaining a copy
910
* of this software and associated documentation files (the "Software"), to deal
@@ -28,11 +29,7 @@
2829

2930
#include "py/objtuple.h"
3031
#include "py/objstr.h"
31-
#include "extmod/misc.h"
32-
#include "extmod/vfs.h"
33-
#include "extmod/vfs_fat.h"
3432
#include "genhdr/mpversion.h"
35-
#include "esp_mphal.h"
3633
#include "user_interface.h"
3734

3835
STATIC const qstr os_uname_info_fields[] = {
@@ -57,60 +54,9 @@ STATIC mp_obj_tuple_t os_uname_info_obj = {
5754
}
5855
};
5956

60-
STATIC mp_obj_t os_uname(void) {
57+
mp_obj_t common_hal_os_uname(void) {
6158
// We must populate the "release" field each time in case it was GC'd since the last call.
6259
const char *ver = system_get_sdk_version();
6360
os_uname_info_obj.items[2] = mp_obj_new_str(ver, strlen(ver), false);
6461
return (mp_obj_t)&os_uname_info_obj;
6562
}
66-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
67-
68-
STATIC mp_obj_t os_urandom(mp_obj_t num) {
69-
mp_int_t n = mp_obj_get_int(num);
70-
vstr_t vstr;
71-
vstr_init_len(&vstr, n);
72-
for (int i = 0; i < n; i++) {
73-
vstr.buf[i] = *WDEV_HWRNG;
74-
}
75-
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
76-
}
77-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
78-
79-
STATIC mp_obj_t os_dupterm_notify(mp_obj_t obj_in) {
80-
(void)obj_in;
81-
mp_hal_signal_dupterm_input();
82-
return mp_const_none;
83-
}
84-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_dupterm_notify_obj, os_dupterm_notify);
85-
86-
STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
87-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uos) },
88-
{ MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },
89-
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },
90-
#if MICROPY_PY_OS_DUPTERM
91-
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mp_uos_dupterm_obj) },
92-
{ MP_ROM_QSTR(MP_QSTR_dupterm_notify), MP_ROM_PTR(&os_dupterm_notify_obj) },
93-
#endif
94-
#if MICROPY_VFS_FAT
95-
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
96-
{ MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) },
97-
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
98-
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
99-
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
100-
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj 925D ) },
101-
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
102-
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
103-
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&mp_vfs_rename_obj) },
104-
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
105-
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
106-
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
107-
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
108-
#endif
109-
};
110-
111-
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
112-
113-
const mp_obj_module_t uos_module = {
114-
.base = { &mp_type_module },
115-
.globals = (mp_obj_dict_t*)&os_module_globals,
116-
};

0 commit comments

Comments
 (0)
0