本文整理汇总了Python中tempfile.gettempdir方法的典型用法代码示例。如果您正苦于以下问题:Python tempfile.gettempdir方法的具体用法?Python tempfile.gettempdir怎么用?Python tempfile.gettempdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile
的用法示例。
在下文中一共展示了tempfile.gettempdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_workflow
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def download_workflow(url):
"""Download workflow at ``url`` to a local temporary file.
:param url: URL to .alfredworkflow file in GitHub repo
:returns: path to downloaded file
"""
filename = url.split('/')[-1]
if (not filename.endswith('.alfredworkflow') and
not filename.endswith('.alfred3workflow')):
raise ValueError('attachment not a workflow: {0}'.format(filename))
local_path = os.path.join(tempfile.gettempdir(), filename)
wf().logger.debug(
'downloading updated workflow from `%s` to `%s` ...', url, local_path)
response = web.get(url)
with open(local_path, 'wb') as output:
output.write(response.content)
return local_path
示例2: maybe_download_mnist_file
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def maybe_download_mnist_file(file_name, datadir=None, force=False):
try:
from urllib.parse import urljoin
from urllib.request import urlretrieve
except ImportError:
from urlparse import urljoin
from urllib import urlretrieve
if not datadir:
datadir = tempfile.gettempdir()
dest_file = os.path.join(datadir, file_name)
if force or not os.path.isfile(file_name):
url = urljoin('http://yann.lecun.com/exdb/mnist/', file_name)
urlretrieve(url, dest_file)
return dest_file
示例3: __init__
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def __init__(self, label="DefaultValues", logfile=None, verbose=False, debug=False):
super(DefaultValues, self).__init__(label=label, logfile=logfile, verbose=verbose, debug=debug)
self._validator = Validator(logfile=logfile, verbose=verbose, debug=debug)
pipeline_dir = os.path.dirname(self._validator.get_full_path(os.path.dirname(scripts.__file__)))
self._DEFAULT_seed = random.randint(0, 2147483640)
self._DEFAULT_tmp_dir = tempfile.gettempdir()
self._DEFAULT_directory_pipeline = pipeline_dir
original_wd = os.getcwd()
os.chdir(pipeline_dir)
file_path_config = os.path.join(pipeline_dir, "default_config.ini")
if self._validator.validate_file(file_path_config, silent=True):
self._from_config(file_path_config)
else:
self._from_hardcoded(pipeline_dir)
os.chdir(original_wd)
示例4: default_ccache_dir
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def default_ccache_dir() -> str:
""":return: ccache directory for the current platform"""
# Share ccache across containers
if 'CCACHE_DIR' in os.environ:
ccache_dir = os.path.realpath(os.environ['CCACHE_DIR'])
try:
os.makedirs(ccache_dir, exist_ok=True)
return ccache_dir
except PermissionError:
logging.info('Unable to make dirs at %s, falling back to local temp dir', ccache_dir)
# In osx tmpdir is not mountable by default
import platform
if platform.system() == 'Darwin':
ccache_dir = "/tmp/_mxnet_ccache"
os.makedirs(ccache_dir, exist_ok=True)
return ccache_dir
return os.path.join(tempfile.gettempdir(), "ci_ccache")
示例5: sendImageWithUrl
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def sendImageWithUrl(self, to_, url):
"""Send a image with given image url
:param url: image url to send
"""
path = '%s/pythonLine-%1.data' % (tempfile.gettempdir(), randint(0, 9))
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(path, 'w') as f:
shutil.copyfileobj(r.raw, f)
else:
raise Exception('Download image failure.')
try:
self.sendImage(to_, path)
except Exception as e:
raise e
示例6: build
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def build(path,inConsole=False,addWeb=False):
params=[path,"--noupx","--onefile"]
if not inConsole:
params.append( "--noconsole")
web=os.path.join( os.path.dirname(path), "web" )
if addWeb and os.path.isdir(web):
sep = (os.name == 'nt') and ";" or ":"
params.append("--add-data=%s%sweb" % (web,sep))
temp=os.path.join(tempfile.gettempdir(),".build")
params.append( "--workpath" )
params.append( temp )
params.append( "--distpath" )
params.append( os.path.dirname(path) )
print( "PYINSTALLER:",params )
pyi.run( params )
示例7: _tar_and_copy
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def _tar_and_copy(src_dir, target_dir):
"""Tar and gzip src_dir and copy to GCS target_dir."""
src_dir = src_dir.rstrip("/")
target_dir = target_dir.rstrip("/")
tmp_dir = tempfile.gettempdir().rstrip("/")
src_base = os.path.basename(src_dir)
cloud.shell_run(
"tar -zcf {tmp_dir}/{src_base}.tar.gz -C {src_dir} .",
src_dir=src_dir,
src_base=src_base,
tmp_dir=tmp_dir)
final_destination = "%s/%s.tar.gz" % (target_dir, src_base)
cloud.shell_run(
("gsutil cp {tmp_dir}/{src_base}.tar.gz "
"{final_destination}"),
tmp_dir=tmp_dir,
src_base=src_base,
final_destination=final_destination)
return final_destination
示例8: tar_and_copy_usr_dir
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def tar_and_copy_usr_dir(usr_dir, train_dir):
"""Package, tar, and copy usr_dir to GCS train_dir."""
tf.logging.info("Tarring and pushing t2t_usr_dir.")
usr_dir = os.path.abspath(os.path.expanduser(usr_dir))
# Copy usr dir to a temp location
top_dir = os.path.join(tempfile.gettempdir(), "t2t_usr_container")
tmp_usr_dir = os.path.join(top_dir, usr_dir_lib.INTERNAL_USR_DIR_PACKAGE)
shutil.rmtree(top_dir, ignore_errors=True)
shutil.copytree(usr_dir, tmp_usr_dir)
# Insert setup.py if one does not exist
top_setup_fname = os.path.join(top_dir, "setup.py")
setup_file_str = get_setup_file(
name="DummyUsrDirPackage",
packages=get_requirements(usr_dir)
)
with tf.gfile.Open(top_setup_fname, "w") as f:
f.write(setup_file_str)
usr_tar = _tar_and_copy(top_dir, train_dir)
return usr_tar
示例9: configure
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def configure(dir=None, format_strs=None):
if dir is None:
dir = os.getenv('OPENAI_LOGDIR')
if dir is None:
dir = osp.join(tempfile.gettempdir(),
datetime.datetime.now().strftime("openai-%Y-%m-%d-%H-%M-%S-%f"))
assert isinstance(dir, str)
os.makedirs(dir, exist_ok=True)
if format_strs is None:
strs = os.getenv('OPENAI_LOG_FORMAT')
format_strs = strs.split(',') if strs else LOG_OUTPUT_FORMATS
output_formats = [make_output_format(f, dir) for f in format_strs]
Logger.CURRENT = Logger(dir=dir, output_formats=output_formats)
log('Logging to %s'%dir)
示例10: test_toolchain_standard_not_implemented
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def test_toolchain_standard_not_implemented(self):
spec = Spec()
with self.assertRaises(NotImplementedError):
self.toolchain(spec)
with self.assertRaises(NotImplementedError):
self.toolchain.assemble(spec)
with self.assertRaises(NotImplementedError):
self.toolchain.link(spec)
# Check that the build_dir is set on the spec based on tempfile
self.assertTrue(spec['build_dir'].startswith(
realpath(tempfile.gettempdir())))
# Also that it got deleted properly.
self.assertFalse(exists(spec['build_dir']))
示例11: configure
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def configure(dir=None, format_strs=None):
if dir is None:
dir = os.getenv('OPENAI_LOGDIR')
if dir is None:
dir = osp.join(tempfile.gettempdir(),
datetime.datetime.now().strftime("openai-%Y-%m-%d-%H-%M-%S-%f"))
assert isinstance(dir, str)
os.makedirs(dir, exist_ok=True)
log_suffix = ''
from mpi4py import MPI
rank = MPI.COMM_WORLD.Get_rank()
if rank > 0:
log_suffix = "-rank%03i" % rank
if format_strs is None:
if rank == 0:
format_strs = os.getenv('OPENAI_LOG_FORMAT', 'stdout,log,csv').split(',')
else:
format_strs = os.getenv('OPENAI_LOG_FORMAT_MPI', 'log').split(',')
format_strs = filter(None, format_strs)
output_formats = [make_output_format(f, dir, log_suffix) for f in format_strs]
Logger.CURRENT = Logger(dir=dir, output_formats=output_formats)
log('Logging to %s'%dir)
示例12: __init__
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def __init__(
self,
seed=0,
episode_len=None,
no_images=None
):
from tensorflow.examples.tutorials.mnist import input_data
# we could use temporary directory for this with a context manager and
# TemporaryDirecotry, but then each test that uses mnist would re-download the data
# this way the data is not cleaned up, but we only download it once per machine
mnist_path = osp.join(tempfile.gettempdir(), 'MNIST_data')
with filelock.FileLock(mnist_path + '.lock'):
self.mnist = input_data.read_data_sets(mnist_path)
self.np_random = np.random.RandomState()
self.np_random.seed(seed)
self.observation_space = Box(low=0.0, high=1.0, shape=(28,28,1))
self.action_space = Discrete(10)
self.episode_len = episode_len
self.time = 0
self.no_images = no_images
self.train_mode()
self.reset()
示例13: main
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def main():
# Get data files for the model.
data_paths, [deploy_file, model_file, mean_proto] = common.find_sample_data(description="Runs an MNIST network using a Caffe model file", subfolder="mnist", find_files=["mnist.prototxt", "mnist.caffemodel", "mnist_mean.binaryproto"])
# Cache the engine in a temporary directory.
engine_path = os.path.join(tempfile.gettempdir(), "mnist.engine")
with get_engine(deploy_file, model_file, engine_path) as engine, engine.create_execution_context() as context:
# Build an engine, allocate buffers and create a stream.
# For more information on buffer allocation, refer to the introductory samples.
inputs, outputs, bindings, stream = common.allocate_buffers(engine)
mean = retrieve_mean(mean_proto)
# For more information on performing inference, refer to the introductory samples.
inputs[0].host, case_num = load_normalized_test_case(data_paths, mean)
# The common.do_inference function will return a list of outputs - we only have one in this case.
[output] = common.do_inference(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream)
pred = np.argmax(output)
print("Test Case: " + str(case_num))
print("Prediction: " + str(pred))
# After the engine is destroyed, we destroy the plugin. This function is exposed through the binding code in plugin/pyFullyConnected.cpp.
fc_factory.destroy_plugin()
示例14: test_task_embed
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def test_task_embed(self):
inputs, outputs = get_model(
token_num=20,
embed_dim=12,
head_num=3,
transformer_num=2,
use_task_embed=True,
task_num=10,
training=False,
dropout_rate=0.0,
)
model = keras.models.Model(inputs, outputs)
model_path = os.path.join(tempfile.gettempdir(), 'keras_bert_%f.h5' % np.random.random())
model.save(model_path)
model = keras.models.load_model(
model_path,
custom_objects=get_custom_objects(),
)
model.summary(line_length=200)
示例15: retrieve_download
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import gettempdir [as 别名]
def retrieve_download(dl):
"""Saves a download to a temporary file and returns path.
.. versionadded: 1.37
Args:
url (unicode): URL to .alfredworkflow file in GitHub repo
Returns:
unicode: path to downloaded file
"""
if not match_workflow(dl.filename):
raise ValueError('attachment not a workflow: ' + dl.filename)
path = os.path.join(tempfile.gettempdir(), dl.filename)
wf().logger.debug('downloading update from '
'%r to %r ...', dl.url, path)
r = web.get(dl.url)
r.raise_for_status()
r.save_to_path(path)
return path