Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3017806

Browse files
committed
#10999: Add missing documentation for chflags constants to stat module docs
Patch by Michal Nowikowski.
1 parent c29cd93 commit 3017806

3 files changed

Lines changed: 77 additions & 32 deletions

File tree

Doc/library/os.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -842,16 +842,16 @@ Files and Directories
842842
Set the flags of *path* to the numeric *flags*. *flags* may take a combination
843843
(bitwise OR) of the following values (as defined in the :mod:`stat` module):
844844

845-
* ``UF_NODUMP``
846-
* ``UF_IMMUTABLE``
847-
* ``UF_APPEND``
848-
* ``UF_OPAQUE``
849-
* ``UF_NOUNLINK``
850-
* ``SF_ARCHIVED``
851-
* ``SF_IMMUTABLE``
852-
* ``SF_APPEND``
853-
* ``SF_NOUNLINK``
854-
* ``SF_SNAPSHOT``
845+
* :data:`stat.UF_NODUMP`
846+
* :data:`stat.UF_IMMUTABLE`
847+
* :data:`stat.UF_APPEND`
848+
* :data:`stat.UF_OPAQUE`
849+
* :data:`stat.UF_NOUNLINK`
850+
* :data:`stat.SF_ARCHIVED`
851+
* :data:`stat.SF_IMMUTABLE`
852+
* :data:`stat.SF_APPEND`
853+
* :data:`stat.SF_NOUNLINK`
854+
* :data:`stat.SF_SNAPSHOT`
855855

856856
Availability: Unix.
857857

Doc/library/stat.rst

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ for each test. These are also useful when checking for information about a file
7373
that isn't handled by :mod:`os.path`, like the tests for block and character
7474
devices.
7575

76+
Example::
77+
78+
import os, sys
79+
from stat import *
80+
81+
def walktree(top, callback):
82+
'''recursively descend the directory tree rooted at top,
83+
calling the callback function for each regular file'''
84+
85+
for f in os.listdir(top):
86+
pathname = os.path.join(top, f)
87+
mode = os.stat(pathname)[ST_MODE]
88+
if S_ISDIR(mode):
89+
# It's a directory, recurse into it
90+
walktree(pathname, callback)
91+
elif S_ISREG(mode):
92+
# It's a file, call the callback function
93+
callback(pathname)
94+
else:
95+
# Unknown file type, print a message
96+
print('Skipping %s' % pathname)
97+
98+
def visitfile(file):
99+
print('visiting', file)
100+
101+
if __name__ == '__main__':
102+
walktree(sys.argv[1], visitfile)
103+
76104
All the variables below are simply symbolic indexes into the 10-tuple returned
77105
by :func:`os.stat`, :func:`os.fstat` or :func:`os.lstat`.
78106

@@ -262,31 +290,47 @@ The following flags can also be used in the *mode* argument of :func:`os.chmod`:
262290

263291
Unix V7 synonym for :data:`S_IXUSR`.
264292

265-
Example::
293+
The following flags can be used in the *flags* argument of :func:`os.chflags`:
266294

267-
import os, sys
268-
from stat import *
295+
.. data:: UF_NODUMP
269296

270-
def walktree(top, callback):
271-
'''recursively descend the directory tree rooted at top,
272-
calling the callback function for each regular file'''
297+
Do not dump the file.
273298

274-
for f in os.listdir(top):
275-
pathname = os.path.join(top, f)
276-
mode = os.stat(pathname)[ST_MODE]
277-
if S_ISDIR(mode):
278-
# It's a directory, recurse into it
279-
walktree(pathname, callback)
280-
elif S_ISREG(mode):
281-
# It's a file, call the callback function
282-
callback(pathname)
283-
else:
284-
# Unknown file type, print a message
285-
print('Skipping %s' % pathname)
299+
.. data:: UF_IMMUTABLE
286300

287-
def visitfile(file):
288-
print('visiting', file)
301+
The file may not be changed.
289302

290-
if __name__ == '__main__':
291-
walktree(sys.argv[1], visitfile)
303+
.. data:: UF_APPEND
304+
305+
The file may only be appended to.
306+
307+
.. data:: UF_OPAQUE
308+
309+
The file may not be renamed or deleted.
310+
311+
.. data:: UF_NOUNLINK
312+
313+
The directory is opaque when viewed through a union stack.
314+
315+
.. data:: SF_ARCHIVED
316+
317+
The file may be archived.
318+
319+
.. data:: SF_IMMUTABLE
320+
321+
The file may not be changed.
322+
323+
.. data:: SF_APPEND
324+
325+
The file may only be appended to.
326+
327+
.. data:: SF_NOUNLINK
328+
329+
The file may not be renamed or deleted.
330+
331+
.. data:: SF_SNAPSHOT
332+
333+
The file is a snapshot file.
334+
335+
See the \*BSD or Mac OS systems man page :manpage:`chflags(2)` for more information.
292336

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ Stefan Norberg
578578
Tim Northover
579579
Joe Norton
580580
Neal Norwitz
581+
Michal Nowikowski
581582
Nigel O'Brian
582583
Kevin O'Connor
583584
Tim O'Malley

0 commit comments

Comments
 (0)