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


Python tempfile.gettempprefix方法代码示例

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


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

示例1: mkstemp

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def mkstemp(suffix=None, prefix=None, dir=None, text=False):
    """
    Args:
        suffix (`pathlike` or `None`): suffix or `None` to use the default
        prefix (`pathlike` or `None`): prefix or `None` to use the default
        dir (`pathlike` or `None`): temp dir or `None` to use the default
        text (bool): if the file should be opened in text mode
    Returns:
        Tuple[`int`, `fsnative`]:
            A tuple containing the file descriptor and the file path
    Raises:
        EnvironmentError

    Like :func:`python3:tempfile.mkstemp` but always returns a `fsnative`
    path.
    """

    suffix = fsnative() if suffix is None else path2fsn(suffix)
    prefix = gettempprefix() if prefix is None else path2fsn(prefix)
    dir = gettempdir() if dir is None else path2fsn(dir)

    return tempfile.mkstemp(suffix, prefix, dir, text) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:24,代码来源:_temp.py

示例2: mkdtemp

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def mkdtemp(suffix=None, prefix=None, dir=None):
    """
    Args:
        suffix (`pathlike` or `None`): suffix or `None` to use the default
        prefix (`pathlike` or `None`): prefix or `None` to use the default
        dir (`pathlike` or `None`): temp dir or `None` to use the default
    Returns:
        `fsnative`: A path to a directory
    Raises:
        EnvironmentError

    Like :func:`python3:tempfile.mkstemp` but always returns a `fsnative` path.
    """

    suffix = fsnative() if suffix is None else path2fsn(suffix)
    prefix = gettempprefix() if prefix is None else path2fsn(prefix)
    dir = gettempdir() if dir is None else path2fsn(dir)

    return tempfile.mkdtemp(suffix, prefix, dir) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:21,代码来源:_temp.py

示例3: test_exports

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempdir" : 1,
            "tempdir" : 1,
            "template" : 1,
            "SpooledTemporaryFile" : 1
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.assertTrue(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_tempfile.py

示例4: test_usable_template

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_usable_template(self):
        # gettempprefix returns a usable prefix string

        # Create a temp directory, avoiding use of the prefix.
        # Then attempt to create a file whose name is
        # prefix + 'xxxxxx.xxx' in that directory.
        p = tempfile.gettempprefix() + "xxxxxx.xxx"
        d = tempfile.mkdtemp(prefix="")
        try:
            p = os.path.join(d, p)
            try:
                fd = os.open(p, os.O_RDWR | os.O_CREAT)
            except:
                self.failOnException("os.open")
            os.close(fd)
            os.unlink(p)
        finally:
            os.rmdir(d) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_tempfile.py

示例5: repo_path

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def repo_path():
    '''
    Sice elasticsearch may be launched under the other user,
    tempfile.TemporaryDirectory can't be used, because python
    can't cleanup it after elasticsearch user.
    So we are just leaving it there.
    '''
    characters = "abcdefghijklmnopqrstuvwxyz0123456789_"
    temp_dir = tempfile.gettempdir()
    temp_prefix = '/' + tempfile.gettempprefix()
    temp_name = temp_prefix + ''.join(
        [random.choice(characters) for _ in range(8)]
    )

    dir_path = os.path.join(temp_dir + temp_name)
    os.makedirs(dir_path)
    yield dir_path

    try:
        shutil.rmtree(dir_path)
    except PermissionError:
        # if subdirs were created by other user
        pass 
开发者ID:aio-libs-abandoned,项目名称:aioes,代码行数:25,代码来源:test_snapshot.py

示例6: test_exports

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempdir" : 1,
            "tempdir" : 1,
            "template" : 1,
            "SpooledTemporaryFile" : 1,
            "TemporaryDirectory" : 1,
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.assertTrue(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:27,代码来源:test_tempfile.py

示例7: test_exports

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempdir" : 1,
            "tempdir" : 1,
            "template" : 1
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.failUnless(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_tempfile.py

示例8: __init__

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def __init__(self, filename=None):
        """Initializes a new DarkFrame object."""
        super(DarkFrame, self).__init__(filename=filename)
        self.options = Options({
            'auto_brightness': False,
            'brightness': 1.0,
            'auto_stretch': True,
            'bps': 16,
            'gamma': (1, 1),
            'rotation': 0,
        })
        self._tmp = os.path.join(
            tempfile.gettempdir(),
            '{prefix}{rand}'.format(
                prefix=tempfile.gettempprefix(),
                rand=''.join(random.SystemRandom().choice(
                    string.ascii_uppercase + string.digits) for _ in range(8)
                )
            )
        )
        self._filetype = None 
开发者ID:photoshell,项目名称:rawkit,代码行数:23,代码来源:raw.py

示例9: serve

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def serve(content):
    """Write content to a temp file and serve it in browser"""
    temp_folder = tempfile.gettempdir()
    temp_file_name = tempfile.gettempprefix() + str(uuid.uuid4()) + ".html"
    # Generate a file path with a random name in temporary dir
    temp_file_path = os.path.join(temp_folder, temp_file_name)

    # save content to temp file
    save(temp_file_path, content)

    # Open templfile in a browser
    webbrowser.open("file://{}".format(temp_file_path))

    # Block the thread while content is served
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        # cleanup the temp file
        os.remove(temp_file_path) 
开发者ID:vividvilla,项目名称:csvtotable,代码行数:22,代码来源:convert.py

示例10: _check_tmp_free_space

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def _check_tmp_free_space() -> CheckLevels:
    """
    Warn if there is not enough free space in the default temporary directory.
    """
    free_space = shutil.disk_usage(gettempdir()).free
    free_space_gb = free_space / 1024 / 1024 / 1024

    low_space_message = (
        'The default temporary directory ("{tmp_prefix}") has '
        '{free_space:.1f} GB of free space available. '
        'Creating a cluster typically takes approximately 2 GB of temporary '
        'storage. '
        'If you encounter problems with disk space usage, set the ``TMPDIR`` '
        'environment variable to a suitable temporary directory or use the '
        '``--workspace-dir`` option on the ``minidcos docker create`` command.'
    ).format(
        tmp_prefix=Path('/') / gettempprefix(),
        free_space=free_space_gb,
    )

    if free_space_gb < 5:
        warn(message=low_space_message)
        return CheckLevels.WARNING

    return CheckLevels.NONE 
开发者ID:dcos,项目名称:dcos-e2e,代码行数:27,代码来源:doctor.py

示例11: get_fileobject

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def get_fileobject(self, suffix="", prefix=tempfile.gettempprefix(),
                       dir=None, **kwargs):
        '''Return the temporary file to use.'''
        if dir is None:
            dir = os.path.normpath(os.path.dirname(self._path))
        descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
                                            dir=dir)
        # io.open() will take either the descriptor or the name, but we need
        # the name later for commit()/replace_atomic() and couldn't find a way
        # to get the filename from the descriptor.
        os.close(descriptor)
        kwargs['mode'] = self._mode
        kwargs['file'] = name
        return io.open(**kwargs) 
开发者ID:untitaker,项目名称:python-atomicwrites,代码行数:16,代码来源:__init__.py

示例12: gettempprefix

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def gettempprefix():
    """
    Returns:
        `fsnative`

    Like :func:`python3:tempfile.gettempprefix`, but always returns a
    `fsnative` path
    """

    return path2fsn(tempfile.gettempprefix()) 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:12,代码来源:_temp.py

示例13: test_sane_template

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_sane_template(self):
        # gettempprefix returns a nonempty prefix string
        p = tempfile.gettempprefix()

        self.assertIsInstance(p, basestring)
        self.assertTrue(len(p) > 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_tempfile.py

示例14: test_exports

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def test_exports(self):
        # There are no surprising symbols in the tempfile module
        dict = tempfile.__dict__

        expected = {
            "NamedTemporaryFile" : 1,
            "TemporaryFile" : 1,
            "mkstemp" : 1,
            "mkdtemp" : 1,
            "mktemp" : 1,
            "TMP_MAX" : 1,
            "gettempprefix" : 1,
            "gettempprefixb" : 1,
            "gettempdir" : 1,
            "gettempdirb" : 1,
            "tempdir" : 1,
            "template" : 1,
            "SpooledTemporaryFile" : 1,
            "TemporaryDirectory" : 1,
        }

        unexp = []
        for key in dict:
            if key[0] != '_' and key not in expected:
                unexp.append(key)
        self.assertTrue(len(unexp) == 0,
                        "unexpected keys: %s" % unexp) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:29,代码来源:test_tempfile.py

示例15: make_temp

# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempprefix [as 别名]
def make_temp(self):
        return tempfile._mkstemp_inner(tempfile.gettempdir(),
                                       tempfile.gettempprefix(),
                                       '',
                                       tempfile._bin_openflags,
                                       str) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_tempfile.py


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