mirror of https://github.com/flaggo/pydu.git
add doc for system.FileTracker
This commit is contained in:
parent
69c279b3b4
commit
b1693db382
|
@ -1,6 +1,39 @@
|
|||
System
|
||||
------
|
||||
|
||||
|
||||
.. py:class:: pydu.system.FileTracker()
|
||||
|
||||
Track current opening files, started with ``FileTracker.track()``.
|
||||
When opening several files, ``FileTracker`` tracks them and you can locate them by calling
|
||||
``FileTraker.get_openfiles()``.
|
||||
|
||||
.. py:staticmethod:: track()
|
||||
|
||||
Start tracking opening files.
|
||||
|
||||
.. py:staticmethod:: untrack()
|
||||
|
||||
Stop tracking opening files.
|
||||
|
||||
.. py:staticmethod:: get_openfiles()
|
||||
|
||||
Get current opening files.
|
||||
|
||||
>>> from pydu.system import FileTracker
|
||||
>>> FileTracker.track()
|
||||
>>> f = open('test', 'w')
|
||||
>>> FileTracker.get_openfiles()
|
||||
{<_io.TextIOWrapper name='test' mode='w' encoding='UTF-8'>}
|
||||
>>> f.close()
|
||||
>>> FileTracker.get_openfiles()
|
||||
set()
|
||||
>>> FileTracker.untrack()
|
||||
>>> f = open('test', 'w')
|
||||
>>> FileTracker.get_openfiles()
|
||||
set()
|
||||
|
||||
|
||||
.. py:function:: pydu.system.makedirs(path, mode=0o755, ignore_errors=False, exist_ok=False)
|
||||
|
||||
Based on ``os.makedirs``,create a leaf directory and all intermediate ones.
|
||||
|
|
|
@ -45,20 +45,20 @@ else:
|
|||
|
||||
|
||||
class FileTracker(object):
|
||||
@classmethod
|
||||
def track(cls):
|
||||
@staticmethod
|
||||
def track():
|
||||
builtins.open = _trackopen
|
||||
if PY2:
|
||||
builtins.file = _trackfile
|
||||
|
||||
@classmethod
|
||||
def untrack(cls):
|
||||
@staticmethod
|
||||
def untrack():
|
||||
builtins.open = _origin_open
|
||||
if PY2:
|
||||
builtins.file = _origin_file
|
||||
|
||||
@classmethod
|
||||
def get_openfiles(cls):
|
||||
@staticmethod
|
||||
def get_openfiles():
|
||||
return _openfiles
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue