gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / scripts / libs / tempfile.py @ 478
History | View | Annotate | Download (726 Bytes)
1 |
|
---|---|
2 |
|
3 |
# ==========================================================
|
4 |
#
|
5 |
# Permite obtener un nombre de fichero temporal en la carpeta
|
6 |
# de ficheros temporales del sistema.
|
7 |
#
|
8 |
# Por ejemplo:
|
9 |
#
|
10 |
# print getTempFile("capa", ".shp")
|
11 |
#
|
12 |
# En un sistema linux mostrara:
|
13 |
#
|
14 |
# /tmp/taller/capa-55b798f1.shp
|
15 |
#
|
16 |
|
17 |
|
18 |
# https://docs.python.org/2/library/os.path.html
|
19 |
import tempfile |
20 |
# https://docs.python.org/2/library/tempfile.html
|
21 |
import os |
22 |
# https://docs.python.org/2/library/time.html
|
23 |
import time |
24 |
|
25 |
def getTempFile(name, ext): |
26 |
tempdir = os.path.join(tempfile.gettempdir(),"taller")
|
27 |
if not os.path.isdir(tempdir): |
28 |
os.makedirs(tempdir) |
29 |
f = os.path.join( |
30 |
tempdir, |
31 |
"%s-%x%s" % (name,time.time(),ext)
|
32 |
) |
33 |
return f
|