本文整理汇总了Python中tempfile.tempdir方法的典型用法代码示例。如果您正苦于以下问题:Python tempfile.tempdir方法的具体用法?Python tempfile.tempdir怎么用?Python tempfile.tempdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile
的用法示例。
在下文中一共展示了tempfile.tempdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_module_scope_is_updated_on_patch
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def test_module_scope_is_updated_on_patch(expected_attrs):
'''
Patch should update the module's globals() on success
'''
from gooey.gui import image_repository
testing_icons = ('config_icon.png', 'success_icon.png')
try:
# setup
make_user_files(*testing_icons)
old_icon = image_repository.config_icon
# load up our new icon(s)
image_repository.patch_images(tempfile.tempdir)
new_icon = image_repository.config_icon
assert old_icon != new_icon
finally:
cleanup_temp(*testing_icons)
# helpers
示例2: test_test_cache
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def test_test_cache(mkdir_permissions):
# Test when cache dir exists already
path = mkdir_permissions(read=False, write=False)
assert (False, False) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=False, write=True)
assert (False, True) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=True, write=False)
assert (True, False) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=True, write=True)
assert (True, True) == cache.test_cache(dict(cache_line_dir=path))
# Test when cache dir doesn't exist
tmp = os.path.join(tempfile.tempdir,
next(tempfile._get_candidate_names()) + '_yatsm')
read_write = cache.test_cache(dict(cache_line_dir=tmp))
os.removedirs(tmp)
assert (True, True) == read_write
示例3: test_exports
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [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)
示例4: __setup_object_store
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def __setup_object_store(self, conf):
if "object_store_config_file" not in conf and "object_store_config" not in conf:
self.object_store = None
return
config_obj_kwds = dict(
file_path=conf.get("object_store_file_path", None),
object_store_check_old_style=False,
job_working_directory=conf.get("object_store_job_working_directory", None),
new_file_path=conf.get("object_store_new_file_path", tempdir),
umask=int(conf.get("object_store_umask", "0000")),
jobs_directory=None,
)
config_dict = None
if conf.get("object_store_config_file"):
config_obj_kwds["object_store_config_file"] = conf['object_store_config_file']
else:
config_dict = conf["object_store_config"]
object_store_config = Bunch(**config_obj_kwds)
self.object_store = build_object_store_from_config(object_store_config, config_dict=config_dict)
示例5: __init__
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def __init__(self, serial_no):
"""Creates an instance of a ``JLock`` and populates the name.
Note:
This method may fail if there is no temporary directory in which to
have the lockfile placed.
Args:
self (JLock): the ``JLock`` instance
serial_no (int): the serial number of the J-Link
Returns:
``None``
"""
self.name = self.SERIAL_NAME_FMT.format(serial_no)
self.acquired = False
self.fd = None
self.path = None
self.path = os.path.join(tempfile.tempdir, self.name)
示例6: test_exports
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [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)
示例7: setUp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def setUp(self):
self.tmpdir = realpath(tempfile.mkdtemp())
tempfile.tempdir = self.tmpdir
示例8: tearDown
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def tearDown(self):
# This is safe - the module will just call gettempdir() again
tempfile.tempdir = None
rmtree(self.tmpdir)
示例9: _prepare_protocol_v1
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def _prepare_protocol_v1(self, argv, ifile, ofile):
debug = environment.splunklib_logger.debug
# Provide as much context as possible in advance of parsing the command line and preparing for execution
self._input_header.read(ifile)
self._protocol_version = 1
self._map_metadata(argv)
debug(' metadata=%r, input_header=%r', self._metadata, self._input_header)
try:
tempfile.tempdir = self._metadata.searchinfo.dispatch_dir
except AttributeError:
raise RuntimeError('{}.metadata.searchinfo.dispatch_dir is undefined'.format(self.__class__.__name__))
debug(' tempfile.tempdir=%r', tempfile.tempdir)
CommandLineParser.parse(self, argv[2:])
self.prepare()
if self.record:
self.record = False
record_argv = [argv[0], argv[1], str(self._options), ' '.join(self.fieldnames)]
ifile, ofile = self._prepare_recording(record_argv, ifile, ofile)
self._record_writer.ofile = ofile
ifile.record(str(self._input_header), '\n\n')
if self.show_configuration:
self.write_info(self.name + ' command configuration: ' + str(self._configuration))
return ifile # wrapped, if self.record is True
示例10: zipLayer
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def zipLayer(layer):
"""Compress layer to zip file"""
file_path = layer.dataProvider().dataSourceUri()
if file_path.find('|') != -1:
file_path = file_path[0:file_path.find('|')]
if file_path.startswith('/vsizip/'):
file_path = file_path.replace('/vsizip/', '')
if layer.storageType() in ['ESRI Shapefile', 'GPX', 'GeoJSON', 'LIBKML']:
return file_path
_file = QFile(file_path)
file_info = QFileInfo(_file)
dirname = file_info.dir().absolutePath()
filename = stripAccents(file_info.completeBaseName())
layername = stripAccents(layer.name())
tempdir = checkTempDir()
zip_path = os.path.join(tempdir, layername + '.zip')
zip_file = zipfile.ZipFile(zip_path, 'w')
if layer.storageType() == 'ESRI Shapefile':
for suffix in ['.shp', '.dbf', '.prj', '.shx']:
if os.path.exists(os.path.join(dirname, filename + suffix)):
zip_file.write(os.path.join(dirname, filename + suffix), layername + suffix, zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'GeoJSON':
zip_file.write(file_path, layername + '.geojson', zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'GPX':
zip_file.write(file_path, layername + '.gpx', zipfile.ZIP_DEFLATED)
elif layer.storageType() == 'LIBKML':
zip_file.write(file_path, layername + '.kml', zipfile.ZIP_DEFLATED)
else:
geo_json_name = os.path.join(tempfile.tempdir, layername)
error = QgsVectorFileWriter.writeAsVectorFormat(layer, geo_json_name, "utf-8", None, "GeoJSON")
if error == QgsVectorFileWriter.NoError:
zip_file.write(geo_json_name + '.geojson', layername + '.geojson', zipfile.ZIP_DEFLATED)
zip_file.close()
return zip_path
示例11: checkTempDir
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def checkTempDir():
"""Check temporar dir"""
tempdir = tempfile.tempdir
if tempdir is None:
tempdir = tempfile.mkdtemp()
return tempdir
示例12: download
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def download(self, sql):
apiUrl = 'http://{}.{}/api/v2/sql?api_key={}&format=spatialite&q={}'.format(self.cartodbUser, self.hostname, self.apiKey, sql)
url = QUrl(apiUrl)
request = self._getRequest(url)
def finished(reply):
tempdir = tempfile.tempdir
if tempdir is None:
tempdir = tempfile.mkdtemp()
tf = tempfile.NamedTemporaryFile(delete=False)
sqlite = QFile(tf.name)
tf.close()
if(sqlite.open(QIODevice.WriteOnly)):
sqlite.write(reply.readAll())
sqlite.close()
self.fetchContent.emit(tf.name)
else:
self.error.emit('Error saving downloaded file')
manager = QNetworkAccessManager()
manager.finished.connect(finished)
reply = manager.get(request)
loop = QEventLoop()
reply.downloadProgress.connect(self.progressCB)
reply.error.connect(self._error)
reply.finished.connect(loop.exit)
loop.exec_()
示例13: override_temp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def override_temp(replacement):
"""
Monkey-patch tempfile.tempdir with replacement, ensuring it exists
"""
if not os.path.isdir(replacement):
os.makedirs(replacement)
saved = tempfile.tempdir
tempfile.tempdir = replacement
try:
yield
finally:
tempfile.tempdir = saved
示例14: main
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def main():
if "EMAIL_FROM_ADDRESS" not in os.environ:
raise ValueError("EMAIL_FROM_ADDRESS not found in environment variables")
if "PASSWORD" not in os.environ:
raise ValueError("PASSWORD not found in environment variables")
if "EMAIL_TO_ADDRESS" not in os.environ:
raise ValueError("EMAIL_TO_ADDRESS not found in environment variables")
os.chdir(os.path.dirname("../../quarkchain/cluster/"))
parser = argparse.ArgumentParser()
ClusterConfig.attach_arguments(parser)
args = parser.parse_args()
config = ClusterConfig.create_from_args(args)
# creat a config tempfile for health check, which is a copy of the original config file
tempfile.tempdir = "../../mainnet/singularity/"
fd, config.json_filepath = tempfile.mkstemp()
with os.fdopen(fd, "w") as tmp:
tmp.write(config.to_json())
print("Cluster config file: {}".format(config.json_filepath))
print(config.to_json())
cluster = HealthCheckCluster(config)
bootstrap_nodes = config.P2P.BOOT_NODES.split(",")
count = 0
while True:
bash_command_revised_config = (
"QKC_CONFIG="
+ config.json_filepath
+ " python3 ../../quarkchain/tools/config_p2p.py --bootnodes "
+ bootstrap_nodes[count]
)
os.system(bash_command_revised_config)
print("Start Bootstrap With " + bootstrap_nodes[count])
cluster.start_and_loop()
time.sleep(100)
count = (count + 1) % len(bootstrap_nodes)
示例15: override_temp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import tempdir [as 别名]
def override_temp(replacement):
"""
Monkey-patch tempfile.tempdir with replacement, ensuring it exists
"""
pkg_resources.py31compat.makedirs(replacement, exist_ok=True)
saved = tempfile.tempdir
tempfile.tempdir = replacement
try:
yield
finally:
tempfile.tempdir = saved