當前位置: 首頁>>代碼示例>>Python>>正文


Python os.curdir方法代碼示例

本文整理匯總了Python中os.curdir方法的典型用法代碼示例。如果您正苦於以下問題:Python os.curdir方法的具體用法?Python os.curdir怎麽用?Python os.curdir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.curdir方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _candidate_tempdir_list

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def _candidate_tempdir_list():
    """Generate a list of candidate temporary directories which
    _get_default_tempdir will try."""

    dirlist = []

    # First, try the environment.
    for envname in 'TMPDIR', 'TEMP', 'TMP':
        dirname = _os.getenv(envname)
        if dirname: dirlist.append(dirname)

    # Failing that, try OS-specific locations.
    if _os.name == 'nt':
        dirlist.extend([ r'c:\temp', r'c:\tmp', r'\temp', r'\tmp' ])
    else:
        dirlist.extend([ '/tmp', '/var/tmp', '/usr/tmp' ])

    # As a last resort, the current directory.
    try:
        dirlist.append(_os.getcwd())
    except (AttributeError, OSError):
        dirlist.append(_os.curdir)

    return dirlist 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:26,代碼來源:tempfile.py

示例2: translate_path

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?',1)[0]
        path = path.split('#',1)[0]
        path = posixpath.normpath(urllib_parse.unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        return path 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:23,代碼來源:server.py

示例3: bestrelpath

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def bestrelpath(self, dest):
        """ return a string which is a relative path from self
            (assumed to be a directory) to dest such that
            self.join(bestrelpath) == dest and if not such
            path can be determined return dest.
        """
        try:
            if self == dest:
                return os.curdir
            base = self.common(dest)
            if not base:  # can be the case on windows
                return str(dest)
            self2base = self.relto(base)
            reldest = dest.relto(base)
            if self2base:
                n = self2base.count(self.sep) + 1
            else:
                n = 0
            l = [os.pardir] * n
            if reldest:
                l.append(reldest)
            target = dest.sep.join(l)
            return target
        except AttributeError:
            return str(dest) 
開發者ID:pytest-dev,項目名稱:py,代碼行數:27,代碼來源:common.py

示例4: build

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def build(self):
        use_windows_commands = os.name == 'nt'
        command = "build" if use_windows_commands else "./build.sh"
        if self.options.toolset != 'auto':
            command += " "+str(self.options.toolset)
        build_dir = os.path.join(self.source_folder, "source")
        engine_dir = os.path.join(build_dir, "src", "engine")
        os.chdir(engine_dir)
        with tools.environment_append({"VSCMD_START_DIR": os.curdir}):
            if self.options.use_cxx_env:
                # Allow use of CXX env vars.
                self.run(command)
            else:
                # To avoid using the CXX env vars we clear them out for the build.
                with tools.environment_append({"CXX": "", "CXXFLAGS": ""}):
                    self.run(command)
        os.chdir(build_dir)
        command = os.path.join(
            engine_dir, "b2.exe" if use_windows_commands else "b2")
        full_command = \
            "{0} --ignore-site-config --prefix=../output --abbreviate-paths install".format(
                command)
        self.run(full_command) 
開發者ID:conan-io,項目名稱:conan-center-index,代碼行數:25,代碼來源:conanfile.py

示例5: download_setuptools

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
                        to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
    """
    Download setuptools from a specified location and return its filename

    `version` should be a valid setuptools version number that is available
    as an egg for download under the `download_base` URL (which should end
    with a '/'). `to_dir` is the directory where the egg will be downloaded.
    `delay` is the number of seconds to pause before an actual download
    attempt.

    ``downloader_factory`` should be a function taking no arguments and
    returning a function for downloading a URL to a target.
    """
    # making sure we use the absolute path
    to_dir = os.path.abspath(to_dir)
    zip_name = "setuptools-%s.zip" % version
    url = download_base + zip_name
    saveto = os.path.join(to_dir, zip_name)
    if not os.path.exists(saveto):  # Avoid repeated downloads
        log.warn("Downloading %s", url)
        downloader = downloader_factory()
        downloader(url, saveto)
    return os.path.realpath(saveto) 
開發者ID:fangpenlin,項目名稱:bugbuzz-python,代碼行數:26,代碼來源:ez_setup.py

示例6: normalize_path

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def normalize_path(path, parent=os.curdir):
    # type: (str, str) -> str
    """Normalize a single-path.

    :returns:
        The normalized path.
    :rtype:
        str
    """
    # NOTE(sigmavirus24): Using os.path.sep and os.path.altsep allow for
    # Windows compatibility with both Windows-style paths (c:\\foo\bar) and
    # Unix style paths (/foo/bar).
    separator = os.path.sep
    # NOTE(sigmavirus24): os.path.altsep may be None
    alternate_separator = os.path.altsep or ''
    if separator in path or (alternate_separator and
                             alternate_separator in path):
        path = os.path.abspath(os.path.join(parent, path))
    return path.rstrip(separator + alternate_separator) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:21,代碼來源:utils.py

示例7: normalize_paths

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def normalize_paths(value, parent=os.curdir):
    """Parse a comma-separated list of paths.

    Return a list of absolute paths.
    """
    if not value:
        return []
    if isinstance(value, list):
        return value
    paths = []
    for path in value.split(','):
        path = path.strip()
        if '/' in path:
            path = os.path.abspath(os.path.join(parent, path))
        paths.append(path.rstrip('/'))
    return paths 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:18,代碼來源:pycodestyle.py

示例8: convert_path

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def convert_path(pathname):
    """Return 'pathname' as a name that will work on the native filesystem.

    The path is split on '/' and put back together again using the current
    directory separator.  Needed because filenames in the setup script are
    always supplied in Unix style, and have to be converted to the local
    convention before we can actually use them in the filesystem.  Raises
    ValueError on non-Unix-ish systems if 'pathname' either starts or
    ends with a slash.
    """
    if os.sep == '/':
        return pathname
    if not pathname:
        return pathname
    if pathname[0] == '/':
        raise ValueError("path '%s' cannot be absolute" % pathname)
    if pathname[-1] == '/':
        raise ValueError("path '%s' cannot end with '/'" % pathname)

    paths = pathname.split('/')
    while os.curdir in paths:
        paths.remove(os.curdir)
    if not paths:
        return os.curdir
    return os.path.join(*paths) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:util.py

示例9: _update_namespaces

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def _update_namespaces(self) -> None:
        """Get the available namespaces.
        """

        # user defined search paths
        dir_list = set()
        self.namespaces = dict()
        for k, v in settings['SEARCH_PATHS'].items():
            if os.path.isdir(v):
                meta_path = os.path.join(v, settings['NAMESPACE_CONFIG_FILENAME'])
                meta = U.load_yaml(meta_path)[0] if os.path.exists(meta_path) else dict()
                meta['module_path'] = os.path.abspath(os.path.join(v, meta.get('module_path', './')))
                if os.path.isdir(meta['module_path']):
                    self.namespaces[k] = meta
                    dir_list.add(meta['module_path'])
                else:
                    U.alert_msg('Namespace "%s" has an invalid module path "%s".' % (k, meta['module_path']))

        # current path
        current_path = os.path.abspath(os.curdir)
        if not current_path in dir_list:
            self.namespaces['main'] = dict(module_path=current_path) 
開發者ID:ZhouYanzhao,項目名稱:Nest,代碼行數:24,代碼來源:modules.py

示例10: download_setuptools

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
        to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
    """
    Download setuptools from a specified location and return its filename

    `version` should be a valid setuptools version number that is available
    as an egg for download under the `download_base` URL (which should end
    with a '/'). `to_dir` is the directory where the egg will be downloaded.
    `delay` is the number of seconds to pause before an actual download
    attempt.

    ``downloader_factory`` should be a function taking no arguments and
    returning a function for downloading a URL to a target.
    """
    # making sure we use the absolute path
    to_dir = os.path.abspath(to_dir)
    zip_name = "setuptools-%s.zip" % version
    url = download_base + zip_name
    saveto = os.path.join(to_dir, zip_name)
    if not os.path.exists(saveto):  # Avoid repeated downloads
        log.warn("Downloading %s", url)
        downloader = downloader_factory()
        downloader(url, saveto)
    return os.path.realpath(saveto) 
開發者ID:jeremybmerrill,項目名稱:flyover,代碼行數:26,代碼來源:ez_setup.py

示例11: copy_extensions_to_source

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def copy_extensions_to_source(self):
        build_py = self.get_finalized_command('build_py')
        for ext in self.extensions:
            fullname = self.get_ext_fullname(ext.name)
            filename = self.get_ext_filename(fullname)
            modpath = fullname.split('.')
            package = '.'.join(modpath[:-1])
            package_dir = build_py.get_package_dir(package)
            dest_filename = os.path.join(package_dir,
                                         os.path.basename(filename))
            src_filename = os.path.join(self.build_lib, filename)

            # Always copy, even if source is older than destination, to ensure
            # that the right extensions for the current Python/platform are
            # used.
            copy_file(
                src_filename, dest_filename, verbose=self.verbose,
                dry_run=self.dry_run
            )
            if ext._needs_stub:
                self.write_stub(package_dir or os.curdir, ext, True) 
開發者ID:jpush,項目名稱:jbox,代碼行數:23,代碼來源:build_ext.py

示例12: build_assets

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def build_assets(args):
    """
    Build the longclaw assets
    """
    # Get the path to the JS directory
    asset_path = path.join(path.dirname(longclaw.__file__), 'client')
    try:
        # Move into client dir
        curdir = os.path.abspath(os.curdir)
        os.chdir(asset_path)
        print('Compiling assets....')
        subprocess.check_call(['npm', 'install'])
        subprocess.check_call(['npm', 'run', 'build'])
        os.chdir(curdir)
        print('Complete!')
    except (OSError, subprocess.CalledProcessError) as err:
        print('Error compiling assets:  {}'.format(err))
        raise SystemExit(1) 
開發者ID:JamesRamm,項目名稱:longclaw,代碼行數:20,代碼來源:longclaw.py

示例13: getLogger

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def getLogger(self):
        """
        Get logger configuration and create instance of a logger
        """
        # Known paths where loggingConfig.ini can exist
        relpath1 = os.path.join('etc', 'faraday')
        relpath2 = os.path.join('..', 'etc', 'faraday')
        setuppath = os.path.join(sys.prefix, 'etc', 'faraday')
        userpath = os.path.join(os.path.expanduser('~'), '.faraday')
        self.path = ''

        # Check all directories until first instance of loggingConfig.ini
        for location in os.curdir, relpath1, relpath2, setuppath, userpath:
            try:
                logging.config.fileConfig(os.path.join(location, "loggingConfig.ini"))
                self.path = location
                break
            except ConfigParser.NoSectionError:
                pass

        self._logger = logging.getLogger(self._name)
        return self._logger 
開發者ID:FaradayRF,項目名稱:Faraday-Software,代碼行數:24,代碼來源:helper.py

示例14: cmdline_for_run

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def cmdline_for_run(tool, executable, options, sourcefiles, propertyfile, rlimits):
    working_directory = tool.working_directory(executable)

    def relpath(path):
        return path if os.path.isabs(path) else os.path.relpath(path, working_directory)

    rel_executable = relpath(executable)
    if os.path.sep not in rel_executable:
        rel_executable = os.path.join(os.curdir, rel_executable)
    args = tool.cmdline(
        rel_executable,
        list(options),
        list(map(relpath, sourcefiles)),
        relpath(propertyfile) if propertyfile else None,
        rlimits.copy(),
    )
    assert all(args), "Tool cmdline contains empty or None argument: " + str(args)
    args = [os.path.expandvars(arg) for arg in args]
    args = [os.path.expanduser(arg) for arg in args]
    return args 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:22,代碼來源:model.py

示例15: save_params

# 需要導入模塊: import os [as 別名]
# 或者: from os import curdir [as 別名]
def save_params(dir_path=os.curdir, epoch=None, name="", params=None, aux_states=None,
                ctx=mx.cpu()):
    prefix = os.path.join(dir_path, name)
    _, param_saving_path, _ = get_saving_path(prefix, epoch)
    if not os.path.isdir(dir_path) and not (dir_path == ""):
        os.makedirs(dir_path)
    save_dict = {('arg:%s' % k): v.copyto(ctx) for k, v in params.items()}
    save_dict.update({('aux:%s' % k): v.copyto(ctx) for k, v in aux_states.items()})
    nd.save(param_saving_path, save_dict)
    return param_saving_path 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:12,代碼來源:utils.py


注:本文中的os.curdir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。