当前位置: 首页>>代码示例>>Python>>正文


Python os.W_OK属性代码示例

本文整理汇总了Python中os.W_OK属性的典型用法代码示例。如果您正苦于以下问题:Python os.W_OK属性的具体用法?Python os.W_OK怎么用?Python os.W_OK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在os的用法示例。


在下文中一共展示了os.W_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start_download

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def start_download(self):
        self.url.assert_no_error()
        self.username.assert_no_error()
        self.password.assert_no_error()
        self.proxy.assert_no_error()
        self.save_path.assert_no_error()

        url = self.url.get_input()
        proxy = self.proxy.get_input() or None
        username = self.username.get_input()
        password = self.password.get_input()
        path_prefix = self.save_path.get_path()

        if not os.access(path_prefix, os.W_OK):
            return info("对下载文件夹没有写权限,请重新选择")
        if self.downloader is not None:
            if not self.downloader.done:
                return info("请停止后再重新点击下载...")
        self.downloader = pixiv_run(
            url=url,
            username=username,
            password=password,
            proxy=proxy,
            path_prefix=path_prefix,
        ) 
开发者ID:winkidney,项目名称:PickTrue,代码行数:27,代码来源:downloader.py

示例2: __init__

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def __init__(self, n_pop=4, **specs):
        
        FortneyMarleyCahoyMix1.__init__(self, **specs)
        
        # number of category
        self.n_pop = int(n_pop)
        
        # read forecaster parameter file
        downloadsdir = get_downloads_dir()
        filename = 'fitting_parameters.h5'
        parampath = os.path.join(downloadsdir, filename)
        if not os.path.exists(parampath) and os.access(downloadsdir, os.W_OK|os.X_OK):
            fitting_url = 'https://raw.github.com/dsavransky/forecaster/master/fitting_parameters.h5'
            self.vprint("Fetching Forecaster fitting parameters from %s to %s" % (fitting_url, parampath))
            try:
                urlretrieve(fitting_url, parampath)
            except:
                self.vprint("Error: Remote fetch failed. Fetch manually or see install instructions.")

        assert os.path.exists(parampath), 'fitting_parameters.h5 must exist in /.EXOSIMS/downloads'

        h5 = h5py.File(parampath, 'r')
        self.all_hyper = h5['hyper_posterior'][:]
        h5.close() 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:26,代码来源:Forecaster.py

示例3: get_output_filename

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def get_output_filename(self, user_outputname):
        '''
        check that we have permissions to write to output directory
        adds 'dscalar.nii' to end of outputname if not already present
        '''
        outputname = os.path.realpath(user_outputname)
        output_dir = os.path.dirname(outputname)
        if not os.access(output_dir, os.W_OK):
            logger.error('Cannot write to output file {}\n'\
                         'The folder does not exist, or you do not have permission to write there'\
                         ''.format(outputname))
            sys.exit(1)
        if not outputname.endswith('dscalar.nii'):
            if not outputname.endswith('dtseries.nii'):
                logger.info("Appending '.dscalar.nii' extension to outputname")
                outputname = '{}.dscalar.nii'.format(outputname)
        return outputname 
开发者ID:edickie,项目名称:ciftify,代码行数:19,代码来源:ciftify_vol_result.py

示例4: find_config

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def find_config():
    w = None
    for f in search_config:
        f = os.path.expanduser(f)
        f = os.path.abspath(f)
        d = os.path.dirname(f)
        if os.path.exists(d):
            if os.access(d, os.W_OK):
                w = f
            if os.path.exists(f):
                if os.access(f, os.W_OK):
                    return f
        elif os.access(os.path.dirname(d), os.W_OK):
            os.makedirs(d)
            w = f
    if w is None:
        print ("Cannot find suitable config path to write, create one in %s" % ' or '.join(search_config))
        raise Exception("No config file")
    return w 
开发者ID:klattimer,项目名称:LGWebOSRemote,代码行数:21,代码来源:__init__.py

示例5: check_path_owner

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def check_path_owner(path):
    # If we don't have a way to check the effective uid of this process, then
    # we'll just assume that we own the directory.
    if not hasattr(os, "geteuid"):
        return True

    previous = None
    while path != previous:
        if os.path.lexists(path):
            # Check if path is writable by current user.
            if os.geteuid() == 0:
                # Special handling for root user in order to handle properly
                # cases where users use sudo without -H flag.
                try:
                    path_uid = get_path_uid(path)
                except OSError:
                    return False
                return path_uid == 0
            else:
                return os.access(path, os.W_OK)
        else:
            previous, path = path, os.path.dirname(path) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:filesystem.py

示例6: CheckOutputFile

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def CheckOutputFile(filename):
  """Check that the given file does not exist and can be opened for writing.

  Args:
    filename: The name of the file.

  Raises:
    FileExistsError: if the given filename is not found
    FileNotWritableError: if the given filename is not readable.
    """
  full_path = os.path.abspath(filename)
  if os.path.exists(full_path):
    raise FileExistsError('%s: output file exists' % filename)
  elif not os.access(os.path.dirname(full_path), os.W_OK):
    raise FileNotWritableError(
        '%s: not writable' % os.path.dirname(full_path)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:bulkloader.py

示例7: saveProject

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def saveProject(self):
        """Writes all the settings into the file"""
        if not self.isLoaded():
            return

        # It could be another user project file without write permissions
        skipProjectFile = False
        if exists(self.fileName):
            if not os.access(self.fileName, os.W_OK):
                skipProjectFile = True
        else:
            if not os.access(dirname(self.fileName), os.W_OK):
                skipProjectFile = True

        if not skipProjectFile:
            with open(self.fileName, 'w',
                      encoding=DEFAULT_ENCODING) as diskfile:
                json.dump(self.props, diskfile, indent=4)
        else:
            logging.warning('Skipping updates in %s due to writing permissions',
                            self.fileName) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:23,代码来源:project.py

示例8: GetCacheDir

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def GetCacheDir(session):
    """Returns the path of a usable cache directory."""
    cache_dir = session.GetParameter("cache_dir")
    if cache_dir == None:
        return cache_dir

    cache_dir = os.path.expandvars(cache_dir)

    if not cache_dir:
        raise io_manager.IOManagerError(
            "Local profile cache is not configured - "
            "add a cache_dir parameter to ~/.rekallrc.")

    # Cache dir may be specified relative to the home directory.
    cache_dir = os.path.join(config.GetHomeDir(session), cache_dir)

    if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
        try:
            os.makedirs(cache_dir)
        except (IOError, OSError):
            raise io_manager.IOManagerError(
                "Unable to create or access cache directory %s" % cache_dir)

    return cache_dir 
开发者ID:google,项目名称:rekall,代码行数:26,代码来源:cache.py

示例9: chkdir

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def chkdir(self, path):
        """Create folder if nonexistent, check for write permission then change into directory"""
        try:
            os.makedirs(path)
            self.show_message(_("Folder created."))
            self.workdir(path)
            return True
        except OSError as exception:
            if exception.errno == errno.EEXIST:
                self.show_message(_("Directory already exists. OK."))
                if os.access(path, os.W_OK):
                    self.workdir(path)
                else:
                    self.show_message(_("Error: no write permission"))
                    self.workdir(self.stdir)
                return True
            elif exception.errno == errno.EACCES:
                self.show_message(_("Permission denied."))
                return False
            else:
                self.show_message(_("Invalid path"))
                self.workdir(self.stdir)
                return True

    # Verzeichnis wechseln 
开发者ID:encarsia,项目名称:gpt,代码行数:27,代码来源:modules.py

示例10: setTmpDir

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def setTmpDir(self):
        """Set the tmpDir attribute to a reasonnable location for a temporary
        directory"""
        if os.name != 'nt':
            # On unix use /tmp by default
            self.tmpDir = os.environ.get("TMPDIR", "/tmp")
            self.tmpDir = os.environ.get("TMP", self.tmpDir)
        else:
            # On Windows use the current directory
            self.tmpDir = os.environ.get("TMPDIR", "")
            self.tmpDir = os.environ.get("TMP", self.tmpDir)
            self.tmpDir = os.environ.get("TEMP", self.tmpDir)
        if not os.path.isdir(self.tmpDir):
            self.tmpDir = ""
        elif not os.access(self.tmpDir, os.F_OK + os.W_OK):
            self.tmpDir = "" 
开发者ID:QuantEcon,项目名称:MatchingMarkets.py,代码行数:18,代码来源:solvers.py

示例11: check_msr

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def check_msr():
    """
        Checks if the msr driver is loaded and if the user executing
        benchexec has the read and write permissions for msr.
    """
    res = {"loaded": False, "write": False, "read": False}
    loaded_modules = subprocess.check_output(["lsmod"]).decode("utf-8").split("\n")

    if any("msr" in module for module in loaded_modules):
        res["loaded"] = True
    if res["loaded"]:
        cpu_dirs = os.listdir("/dev/cpu")
        cpu_dirs.remove("microcode")
        if all(os.access("/dev/cpu/{}/msr".format(cpu), os.R_OK) for cpu in cpu_dirs):
            res["read"] = True
        if all(os.access("/dev/cpu/{}/msr".format(cpu), os.W_OK) for cpu in cpu_dirs):
            res["write"] = True
    return res 
开发者ID:sosy-lab,项目名称:benchexec,代码行数:20,代码来源:util.py

示例12: _mkstemp_inner

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def _mkstemp_inner(dir, pre, suf, flags):
    """Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""

    names = _get_candidate_names()

    for seq in xrange(TMP_MAX):
        name = names.next()
        file = _os.path.join(dir, pre + name + suf)
        try:
            fd = _os.open(file, flags, 0600)
            _set_cloexec(fd)
            return (fd, _os.path.abspath(file))
        except OSError, e:
            if e.errno == _errno.EEXIST:
                continue # try again
            if (_os.name == 'nt' and e.errno == _errno.EACCES and
                _os.path.isdir(dir) and _os.access(dir, _os.W_OK)):
                # On windows, when a directory with the chosen name already
                # exists, EACCES error code is returned instead of EEXIST.
                continue
            raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:tempfile.py

示例13: changeFileName

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def changeFileName(self, new_name, header=None, onConsole=True, onFile=True):
        """
        Change the name of the log
        new_name
        header (str) - A string describing the type of header information you
                       want with the logs passed to startLog: 'simple',
                       'message_only', 'no_time', <custom header>
                       (see startLog for more details on formatting)
        onConsole (bool) - True if you want logs written to the console
        onFile (bool)    - True if you want the log written to the file
        """
        # Get rid of tildas
        new_name = os.path.expanduser(new_name)
        # Check if name is okay
        # Copy old log to new name
        new_path, new_filename = os.path.split(new_name)
        if new_path == "":
            new_path = self.filePath
        new_full_filename = os.path.join(new_path, new_filename)
        if os.access(new_path, os.W_OK):
            self.out.handlers = []  # clear old handlers
            if self.onFile:
                copyfile(self.fileFullName, new_full_filename)
                os.remove(self.fileFullName)
            self.startLog(
                filePath=new_path,
                fileName=new_filename,
                header=header,
                onConsole=onConsole,
                onFile=onFile,
            )
        else:
            log.out.warning("No permissions to write new log name")


# Make a global log object to share 
开发者ID:uptake,项目名称:numpynet,代码行数:38,代码来源:loggit.py

示例14: check_write_access

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def check_write_access(path):
    try:
        if not exists(path):
            os.makedirs(path)
        if not os.access(path, os.W_OK):
            raise IOError
        return True
    except (IOError, OSError):
        return False 
开发者ID:graalvm,项目名称:mx,代码行数:11,代码来源:mx_fetchjdk.py

示例15: ValidateDirectoryWritable

# 需要导入模块: import os [as 别名]
# 或者: from os import W_OK [as 别名]
def ValidateDirectoryWritable(theDir):
    if not os.path.isdir(theDir):
        raise argparse.ArgumentTypeError("Directory does not exist")
    if os.access(theDir,os.W_OK):
        return theDir
    else:
        raise argparse.ArgumentTypeError("Directory is not writable") 
开发者ID:girishramnani,项目名称:hacking-tools,代码行数:9,代码来源:_pfish_tools.py


注:本文中的os.W_OK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。