Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Copyright (c) 2014, Facebook, Inc. All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. #
"""Return the contents of the file at `path`"""
"""Write `contents` to the file at `path`"""
"""Create necessary directory heirarchy to `path` if it doesn't exist""" except OSError as err: if err.errno != errno.EEXIST: raise
# This function is really handy. Make it accessible via this module
"""Return the mount that `path` is present on.
Requires `psutil`.""" import psutil path = os.path.realpath(path) found = None
for partition in psutil.disk_partitions('all'): mountpoint = partition.mountpoint if not mountpoint.endswith('/'): mountpoint += '/' if path.startswith(mountpoint): if found is None: found = partition elif len(mountpoint) > len(found.mountpoint): found = partition return found
return self.name
"""Overridden to include the temp dir path for debugging clarity.""" (self.__class__.__name__, self.name, id(self))
"""Trigger cleanup (if it has not been disabled)"""
"""Request persistence of the contents of this temporary directory.
Disabled the cleanup logic that is normally triggered on `__exit__()`, `__del__()`, or close() calls."""
"""Implement this to cleanup after yourself""" raise NotImplementedError()
"""Wrapper around `mkdtemp` that cleans up after itself
These objects provide the following additional nice features:
- A `name` attribute, which refers to the full temporary path created - The ContextManager protocol, similar to ctx.tempdir, to cleanup as the context exits. - Implicit cleanup on dereference (via `__del__`) - Helpers for reading and writing files relative to this created directory """
"""Writes `contents` to the `path` relative to this directory"""
"""Reads the contents from the `path` relative to this directory"""
"""Create a symlink to `dst` at the `path` relative to this directory"""
|