Skip to content

Commit 6088dba

Browse files
committed
follow up 5ad518afd2. Better handling of temporary directories
1 parent 50a258d commit 6088dba

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

python/plugins/processing/algs/qgis/PointsToPaths.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ def processAlgorithm(self, progress):
119119
f['begin'] = vertices[0][0]
120120
f['end'] = vertices[-1][0]
121121

122-
if dirName == '':
123-
fileName = system.getTempFilenameInTempFolder('%s.txt' % group)
124-
else:
125-
fileName = os.path.join(dirName, '%s.txt' % group)
122+
fileName = os.path.join(dirName, '%s.txt' % group)
126123

127124
fl = open(fileName, 'w')
128125
fl.write('angle=Azimuth\n')

python/plugins/processing/outputs/OutputDirectory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929

3030

3131
class OutputDirectory(Output):
32-
pass
32+
directory = True

python/plugins/processing/tools/system.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import time
3030
import sys
3131
import uuid
32+
3233
from PyQt4.QtCore import *
34+
3335
from qgis.core import *
3436

3537
numExported = 1
@@ -61,8 +63,11 @@ def tempFolder():
6163

6264

6365
def setTempOutput(out, alg):
64-
ext = out.getDefaultFileExtension(alg)
65-
out.value = getTempFilenameInTempFolder(out.name + '.' + ext)
66+
if hasattr(out, 'directory'):
67+
out.value = getTempDirInTempFolder()
68+
else:
69+
ext = out.getDefaultFileExtension(alg)
70+
out.value = getTempFilenameInTempFolder(out.name + '.' + ext)
6671

6772

6873
def getTempFilename(ext):
@@ -89,6 +94,16 @@ def getTempFilenameInTempFolder(basename):
8994
return filename
9095

9196

97+
def getTempDirInTempFolder():
98+
"""Returns a temporary directory, putting it into a temp folder.
99+
"""
100+
101+
path = tempFolder()
102+
path = os.path.join(path, str(uuid.uuid4()).replace('-', ''))
103+
mkdir(path)
104+
return path
105+
106+
92107
def removeInvalidChars(string):
93108
validChars = \
94109
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.'

0 commit comments

Comments
 (0)