2016-04-26 18:55:06 -04:00
|
|
|
:mod:`uos` -- basic "operating system" services
|
2016-04-27 07:11:27 -04:00
|
|
|
===============================================
|
2014-10-30 21:37:19 -04:00
|
|
|
|
2016-04-26 18:55:06 -04:00
|
|
|
.. module:: uos
|
2014-10-30 21:37:19 -04:00
|
|
|
:synopsis: basic "operating system" services
|
|
|
|
|
2017-07-02 08:37:31 -04:00
|
|
|
|see_cpython_module| :mod:`python:os`.
|
|
|
|
|
2017-06-03 06:51:13 -04:00
|
|
|
The ``uos`` module contains functions for filesystem access and ``urandom``
|
2016-04-03 13:32:02 -04:00
|
|
|
function.
|
2014-10-30 21:37:19 -04:00
|
|
|
|
|
|
|
Functions
|
|
|
|
---------
|
|
|
|
|
|
|
|
.. function:: chdir(path)
|
|
|
|
|
|
|
|
Change current directory.
|
|
|
|
|
|
|
|
.. function:: getcwd()
|
|
|
|
|
|
|
|
Get the current directory.
|
|
|
|
|
2017-05-09 22:44:21 -04:00
|
|
|
.. function:: ilistdir([dir])
|
|
|
|
|
|
|
|
This function returns an iterator which then yields 3-tuples corresponding to
|
|
|
|
the entries in the directory that it is listing. With no argument it lists the
|
2017-06-27 17:37:47 -04:00
|
|
|
current directory, otherwise it lists the directory given by *dir*.
|
2017-05-09 22:44:21 -04:00
|
|
|
|
2017-06-27 17:37:47 -04:00
|
|
|
The 3-tuples have the form *(name, type, inode)*:
|
2017-05-09 22:44:21 -04:00
|
|
|
|
2017-06-27 17:37:47 -04:00
|
|
|
- *name* is a string (or bytes if *dir* is a bytes object) and is the name of
|
2017-05-09 22:44:21 -04:00
|
|
|
the entry;
|
2017-06-27 17:37:47 -04:00
|
|
|
- *type* is an integer that specifies the type of the entry, with 0x4000 for
|
2017-05-09 22:44:21 -04:00
|
|
|
directories and 0x8000 for regular files;
|
2017-06-27 17:37:47 -04:00
|
|
|
- *inode* is an integer corresponding to the inode of the file, and may be 0
|
2017-05-09 22:44:21 -04:00
|
|
|
for filesystems that don't have such a notion.
|
|
|
|
|
2014-10-30 21:37:19 -04:00
|
|
|
.. function:: listdir([dir])
|
|
|
|
|
|
|
|
With no argument, list the current directory. Otherwise list the given directory.
|
|
|
|
|
|
|
|
.. function:: mkdir(path)
|
|
|
|
|
|
|
|
Create a new directory.
|
|
|
|
|
|
|
|
.. function:: remove(path)
|
|
|
|
|
|
|
|
Remove a file.
|
|
|
|
|
|
|
|
.. function:: rmdir(path)
|
|
|
|
|
|
|
|
Remove a directory.
|
|
|
|
|
2015-05-10 20:30:56 -04:00
|
|
|
.. function:: rename(old_path, new_path)
|
|
|
|
|
|
|
|
Rename a file.
|
|
|
|
|
2014-10-30 21:37:19 -04:00
|
|
|
.. function:: stat(path)
|
|
|
|
|
|
|
|
Get the status of a file or directory.
|
|
|
|
|
2017-04-05 04:44:10 -04:00
|
|
|
.. function:: statvfs(path)
|
|
|
|
|
|
|
|
Get the status of a fileystem.
|
|
|
|
|
|
|
|
Returns a tuple with the filesystem information in the following order:
|
|
|
|
|
|
|
|
* ``f_bsize`` -- file system block size
|
|
|
|
* ``f_frsize`` -- fragment size
|
|
|
|
* ``f_blocks`` -- size of fs in f_frsize units
|
|
|
|
* ``f_bfree`` -- number of free blocks
|
|
|
|
* ``f_bavail`` -- number of free blocks for unpriviliged users
|
|
|
|
* ``f_files`` -- number of inodes
|
|
|
|
* ``f_ffree`` -- number of free inodes
|
|
|
|
* ``f_favail`` -- number of free inodes for unpriviliged users
|
|
|
|
* ``f_flag`` -- mount flags
|
|
|
|
* ``f_namemax`` -- maximum filename length
|
|
|
|
|
|
|
|
Parameters related to inodes: ``f_files``, ``f_ffree``, ``f_avail``
|
|
|
|
and the ``f_flags`` parameter may return ``0`` as they can be unavailable
|
|
|
|
in a port-specific implementation.
|
2016-09-27 05:29:31 -04:00
|
|
|
|
2014-10-30 21:37:19 -04:00
|
|
|
.. function:: sync()
|
|
|
|
|
|
|
|
Sync all filesystems.
|
|
|
|
|
|
|
|
.. function:: urandom(n)
|
|
|
|
|
2017-04-16 02:22:47 -04:00
|
|
|
Return a bytes object with n random bytes. Whenever possible, it is
|
|
|
|
generated by the hardware random number generator.
|
2014-10-30 21:37:19 -04:00
|
|
|
|
2017-06-14 02:02:57 -04:00
|
|
|
.. function:: dupterm(stream_object, index=0)
|
2015-06-10 17:29:56 -04:00
|
|
|
|
2017-12-04 11:36:20 -05:00
|
|
|
Duplicate or switch the MicroPython terminal (the REPL) on the given `stream`-like
|
2017-06-14 02:02:57 -04:00
|
|
|
object. The *stream_object* argument must implement the ``readinto()`` and
|
|
|
|
``write()`` methods. The stream should be in non-blocking mode and
|
|
|
|
``readinto()`` should return ``None`` if there is no data available for reading.
|
|
|
|
|
|
|
|
After calling this function all terminal output is repeated on this stream,
|
|
|
|
and any input that is available on the stream is passed on to the terminal input.
|
|
|
|
|
|
|
|
The *index* parameter should be a non-negative integer and specifies which
|
|
|
|
duplication slot is set. A given port may implement more than one slot (slot 0
|
|
|
|
will always be available) and in that case terminal input and output is
|
|
|
|
duplicated on all the slots that are set.
|
|
|
|
|
|
|
|
If ``None`` is passed as the *stream_object* then duplication is cancelled on
|
|
|
|
the slot given by *index*.
|
|
|
|
|
|
|
|
The function returns the previous stream-like object in the given slot.
|