예제 #1
0
파일: utils.py 프로젝트: azuaby/cinder
def read_file_as_root(file_path):
    """Secure helper to read file as root."""
    try:
        out, _err = execute('cat', file_path, run_as_root=True)
        return out
    except processutils.ProcessExecutionError:
        raise exception.FileNotFound(file_path=file_path)
예제 #2
0
def removefile(path):
    if not os.path.exists(path):
        raise exception.FileNotFound(file_path=path)
    os.unlink(path)
예제 #3
0
def symlink(src, dest):
    if not os.path.exists(src):
        raise exception.FileNotFound(file_path=src)
    os.symlink(src, dest)
예제 #4
0
def readfile(path):
    if not os.path.exists(path):
        raise exception.FileNotFound(file_path=path)
    with open(path, 'r') as f:
        return f.read()