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 @ 468
History | View | Annotate | Download (911 Bytes)
1 | 468 | jjdelcerro | |
---|---|---|---|
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 | # Usar la siguiente linea para importar el getTempFile de este modulo
|
||
18 | #
|
||
19 | # import_from_module("libs.tempfile","getTempFile")
|
||
20 | #
|
||
21 | # Antes debe haberse cargado el modulo "import_utils".
|
||
22 | #
|
||
23 | |||
24 | |||
25 | # https://docs.python.org/2/library/os.path.html
|
||
26 | import tempfile |
||
27 | # https://docs.python.org/2/library/tempfile.html
|
||
28 | import os |
||
29 | # https://docs.python.org/2/library/time.html
|
||
30 | import time |
||
31 | |||
32 | def getTempFile(name, ext): |
||
33 | tempdir = os.path.join(tempfile.gettempdir(),"taller")
|
||
34 | if not os.path.isdir(tempdir): |
||
35 | os.makedirs(tempdir) |
||
36 | f = os.path.join( |
||
37 | tempdir, |
||
38 | "%s-%x%s" % (name,time.time(),ext)
|
||
39 | ) |
||
40 | return f |