From b1693db3821960d007e20d972fa69851b39bcf22 Mon Sep 17 00:00:00 2001 From: Prodesire Date: Fri, 29 Dec 2017 19:59:32 +0800 Subject: [PATCH] add doc for system.FileTracker --- docs/system.rst | 33 +++++++++++++++++++++++++++++++++ pydu/system.py | 12 ++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/docs/system.rst b/docs/system.rst index 1053c36..388f158 100644 --- a/docs/system.rst +++ b/docs/system.rst @@ -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. diff --git a/pydu/system.py b/pydu/system.py index c9dd030..822a035 100644 --- a/pydu/system.py +++ b/pydu/system.py @@ -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