コード例 #1
0
def pivot_root(new, old):
    """Move the filesystem specfied by `new` and mount it at '/' and move the old '/' to `old`

    Arguments
    ----------
    :param str new: Path to a mounted filesystem to make the new '/'
    :param str old: Location where current '/' should be mounted

    Returns
    --------
    No return value

    Exceptions
    -----------
    :raises ValueError: `new` or `old` does not refer to a directory
    :raises ValueError: `new` or `old` are on the current root filesystem or filesystem already mounted on `old`
    :raises ValueError: `old` is not a folder underneath `new`
    :raises PermissionError: No permission to pivot_root to new location
    """
    assert len(new) > 0
    assert len(old) > 0

    assert isinstance(new, (str, bytes)), "new must be a string"
    assert isinstance(old, (str, bytes)), "old must be a string"

    if isinstance(new, str):
        new = new.encode()

    if isinstance(old, str):
        old = old.encode()

    err = _lib.pivot_root(new, old)

    if err < 0:
        err = _ffi.errno
        if err == _errno.EINVAL:
            raise ValueError("{} is not a sub-directory of {}".format(
                old, new))
        elif err == _errno.EBUSY:
            raise ValueError(
                "old or new are on the current root filesystem or filesystem already mounted on {}"
                .format(old))
        elif err == _errno.ENOTDIR:
            if _isdir(new):
                raise ValueError("{} is not a Directory".format(new))
            elif _isdir(old):
                raise ValueError("{} is not a Directory".format(old))
            else:
                # this is a bug but testing for this case just in case, let us know if you
                # hit it
                raise ValueError(
                    "old or new is not a dir but could not work out which one")
        elif err == _errno.EPERM:
            raise PermissionError(
                "Permission denied, CAP_SYS_ADMIN not in capability bits")
        else:
            # If you are here, its a bug. send us the traceback
            raise UnknownError(err)
コード例 #2
0
ファイル: system.py プロジェクト: dasSOZO/python-butter
def pivot_root(new, old):
    """Move the filesystem specfied by `new` and mount it at '/' and move the old '/' to `old`

    Arguments
    ----------
    :param str new: Path to a mounted filesystem to make the new '/'
    :param str old: Location where current '/' should be mounted

    Returns
    --------
    No return value

    Exceptions
    -----------
    :raises ValueError: `new` or `old` does not refer to a directory
    :raises ValueError: `new` or `old` are on the current root filesystem or filesystem already mounted on `old`
    :raises ValueError: `old` is not a folder underneath `new`
    :raises PermissionError: No permission to pivot_root to new location
    """
    assert len(new) > 0
    assert len(old) > 0

    assert isinstance(new, (str, bytes)), "new must be a string"
    assert isinstance(old, (str, bytes)), "old must be a string"

    if isinstance(new, str):
        new = new.encode()

    if isinstance(old, str):
        old = old.encode()

    err = _C.pivot_root(new, old)

    if err < 0:
        err = _ffi.errno
        if err == _errno.EINVAL:
            raise ValueError("{} is not a sub-directory of {}".format(old, new))
        elif err == _errno.EBUSY:
            raise ValueError("old or new are on the current root filesystem or filesystem already mounted on {}".format(old))
        elif err == _errno.ENOTDIR:
            if _isdir(new):
                raise ValueError("{} is not a Directory".format(new))
            elif _isdir(old):
                raise ValueError("{} is not a Directory".format(old))
            else:
                # this is a bug but testing for this case just in case, let us know if you
                # hit it
                raise ValueError("old or new is not a dir but could not work out which one")
        elif err == _errno.EPERM:
            raise PermissionError("Permission denied, CAP_SYS_ADMIN not in capability bits")
        else:
            # If you are here, its a bug. send us the traceback
            raise UnknownError(err)
コード例 #3
0
def Check(FilePath):
    """Check(FilPath)
    Check the permission of file and return value
    """
    if (_isfile(FilePath) or _isdir(FilePath)):
        chmodValue = ((oct(_stat(FilePath).st_mode & 0O777))[-3:])
        return (int(chmodValue))
    else:
        chmodValue = "File Not Found"
        return (chmodValue)
コード例 #4
0
ファイル: office.py プロジェクト: bbsdkjdx/jingqu_report
def enum_files(root,*allow_ext):
    allow_ext=list(map(lambda s:s.lower(),allow_ext))
    if len(allow_ext)==0:
        allow_ext=['']
    if not _isdir(root):
        return
    for di,fd,fl in _walk(root):
        for f in fl:
            for ext in allow_ext:
                if f.lower().endswith(ext):
                    yield _join(di,f)
コード例 #5
0
def loader(path):
    """
    Returns a loader object for a given path, with
    the correct finder class (``ModuleFinder`` for
    directories and ``FileFinder`` for single file
    modules).

    :param path: The path to the module(s).
    """
    finder = ModuleFinder if _isdir(path) else FileFinder
    return Loader(finder(path))
コード例 #6
0
ファイル: file.py プロジェクト: cgalleguillosm/accasim
def dir_exists(dir_path, create=False):
    """

    :param dir_path:
    :param create:
    :return:
    """
    exists = _isdir(dir_path)
    if create and not exists:
        _makedir(dir_path)
        return True
    return exists
コード例 #7
0
def symlink(src, dst):
    """
    Extended "os.symlink" that:
    - Autodetect if target is directory.
    - Ignore error if file already exists.
    - Ensure to link to real absolute path of the source.

    Args:
        src (path-like object): Source path.
        dst (path-like object): Destination path.
    """
    src = _realpath(_fsdecode(src))
    try:
        _symlink(src, _fsdecode(dst), target_is_directory=_isdir(src))
    except FileExistsError:
        pass
コード例 #8
0
ファイル: fabfile.py プロジェクト: EnTeQuAk/inyoka-legacy
def create_virtualenv(directory=None, pyver=None, interpreter='python'):
    """
    Create a virtual environment for inyoka.

    :param directory: Where to create this virtual environment (folder must not exist).
    :param pyver: Which Python Version to use.
    """
    if directory is None:
        workon_home = os.environ.get('WORKON_HOME')
        if workon_home:
            directory = _path.join(workon_home, 'inyoka')
        else:
            directory = '../inyoka-testsuite'
    if not _isdir(directory):
        _mkdir(_path.expanduser(_path.expandvars(directory)))
    local('%s %s > %s' % (interpreter,
        _j('extra/make-bootstrap.py'), _j('bootstrap.py')), capture=False)
    local('%s ./bootstrap.py --no-site-packages -r %s %s' % (interpreter,
        _j('extra/requirements.txt'), directory), capture=False)
コード例 #9
0
ファイル: fabfile.py プロジェクト: cgnkev/inyoka-legacy
def create_virtualenv(directory=None, pyver=None, interpreter='python'):
    """
    Create a virtual environment for inyoka.

    :param directory: Where to create this virtual environment (folder must not exist).
    :param pyver: Which Python Version to use.
    """
    if directory is None:
        workon_home = os.environ.get('WORKON_HOME')
        if workon_home:
            directory = _path.join(workon_home, 'inyoka')
        else:
            directory = '../inyoka-testsuite'
    if not _isdir(directory):
        _mkdir(_path.expanduser(_path.expandvars(directory)))
    local('%s %s > %s' %
          (interpreter, _j('extra/make-bootstrap.py'), _j('bootstrap.py')),
          capture=False)
    local('%s ./bootstrap.py --no-site-packages -r %s %s' %
          (interpreter, _j('extra/requirements.txt'), directory),
          capture=False)
コード例 #10
0
def put(sources, host=None, expiry="24h", archive=False, compression=None, name=None):
    """

    Args:
        sources (iterable of str): The files or directory to share.
        archive (bool): If True, create an archive before putting on the share.
            Automatic if "sources" is a directory or multiples files.
        expiry (str or int): The download expiry time. In hours, or with a specific time
            unit by appending: "s" for seconds, "m" for minutes, "h" for hours or "d"
            for days (For instance: "7d" for 7 days, "30m" for 30 minutes).
        compression (str): The compression method to use when archiving.
            Possible values: "gz", "bz2", "xz". Default to value saved in configuration
            or "gz".
        host (str): The remote storage host.
        name (str): Rename the file being put.

    Returns:
        str: The shareable URL to the shared object.
    """
    config = _get_host_config(host)

    expiry = _parse_expiry(expiry)
    max_expiry = config["max_expiry_sec"]
    if max_expiry and expiry > max_expiry:
        raise ValueError(f"Expiry can't be more than {config['max_expiry']}.")

    if archive or len(sources) > 1 or any(_isdir(path) for path in sources):
        compression = compression or config["compression"]
        dst = _set_dst_path(name or f"archive.tar.{compression}", config)
        with _open(dst, "wb") as fileobj:
            with _tarfile_open(fileobj=fileobj, mode=f"w:{compression}") as dst_archive:
                for src in sources:
                    dst_archive.add(src, arcname=_basename(src))

    else:
        dst = _set_dst_path(name or _basename(sources[0]), config)
        _copy(sources[0], dst)

    return _shareable_url(dst, expiry)
コード例 #11
0
ファイル: file_handler.py プロジェクト: mscroggs/KLBFAX
def test_dir(directory):
    if not _isdir(directory):
        try:
            _mkdir(directory)
        except:
            pass
コード例 #12
0
ファイル: __init__.py プロジェクト: zopyx/pyfilesystem
 def isdir(self, path):
     return _isdir(self.getsyspath(path))
コード例 #13
0
ファイル: cxio.py プロジェクト: CeroProgramming/cxlibs
def make_all_dirs(*file_paths):
    for fp in file_paths:
        if not _isdir(fp):
            _make_dirs(fp)
コード例 #14
0
ファイル: cxconstants.py プロジェクト: CeroProgramming/cxlibs
from os.path import isdir as _isdir, join as _join

AUTHOR = 'CeroProgramming'
LICENSE = 'MIT'
VERSION = '0.0.1'
DATAFP = '/var/local/cxapps/'
LOGFP = '/var/log/cxapps/'
LOGFILENAME = 'default.log'
APPFP = '/usr/local/cxapps/'
APPSFP = '/usr/local/cxapps/modules/'
CONFIGFP = '/usr/local/etc/cxapps/'
LIBFP = '/usr/local/lib/cxlibs/'

LOG_LEVEL = 'DEBUG'
MODE = 'dev'

if MODE == 'dev':
    DATAFP = '/tmp' + DATAFP
    LOGFP = '/tmp' + LOGFP
    APPFP = '/tmp' + APPFP
    APPSFP = '/tmp' + APPSFP
    CONFIGFP = '/tmp' + CONFIGFP

for fp in (DATAFP, LOGFP, APPFP, APPSFP, CONFIGFP):
    if not _isdir(fp):
        _make_dirs(fp)


def get_application_install_path(name):
    return _join(APPSFP, name.lower())
コード例 #15
0
ファイル: file_handler.py プロジェクト: Giannie/KLBFAX
def test_dir(directory):
    if not _isdir(directory):
        try:
            _mkdir(directory)
        except:
            pass
コード例 #16
0
 def isdir(self, path):
     return _isdir(self.getsyspath(path))
コード例 #17
0
# maybe set GDAL_DATA variable
from os import environ as _environ
from os.path import join as _join, dirname as _dirname, basename as _basename

# from warnings import warn as _warn

if not "GDAL_DATA" in _environ:
    from os.path import isdir as _isdir
    from sys import executable as _executable

    for d in [
            _join(_dirname(_executable), "Library", "share",
                  "gdal"),  # Common location on windows
            _join(_dirname(_executable), "..", "share", "gdal"),
    ]:  # Common location on linux
        if _isdir(d):
            # _warn("Setting GDAL_DATA to: "+d, UserWarning)
            _environ["GDAL_DATA"] = d
            break

    if not "GDAL_DATA" in _environ:
        raise RuntimeError(
            "Could not locate GDAL_DATA folder. Please set this as an environment variable pointing to the GDAL static files"
        )

# import the utilities
import geokit.util
import geokit.srs
import geokit.geom
import geokit.raster
import geokit.vector
コード例 #18
0
ファイル: _cache.py プロジェクト: prxnav/apkmirror_extractor
def mkdir(x: str):
    if _isdir(x):
        return False
    _i_mkdir(x)
    return True