Skip to content

Commit

Permalink
follow up 5ad518afd2. Better handling of temporary directories
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed May 16, 2014
1 parent 50a258d commit 6088dba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
5 changes: 1 addition & 4 deletions python/plugins/processing/algs/qgis/PointsToPaths.py
Expand Up @@ -119,10 +119,7 @@ def processAlgorithm(self, progress):
f['begin'] = vertices[0][0]
f['end'] = vertices[-1][0]

if dirName == '':
fileName = system.getTempFilenameInTempFolder('%s.txt' % group)
else:
fileName = os.path.join(dirName, '%s.txt' % group)
fileName = os.path.join(dirName, '%s.txt' % group)

fl = open(fileName, 'w')
fl.write('angle=Azimuth\n')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/outputs/OutputDirectory.py
Expand Up @@ -29,4 +29,4 @@


class OutputDirectory(Output):
pass
directory = True
19 changes: 17 additions & 2 deletions python/plugins/processing/tools/system.py
Expand Up @@ -29,7 +29,9 @@
import time
import sys
import uuid

from PyQt4.QtCore import *

from qgis.core import *

numExported = 1
Expand Down Expand Up @@ -61,8 +63,11 @@ def tempFolder():


def setTempOutput(out, alg):
ext = out.getDefaultFileExtension(alg)
out.value = getTempFilenameInTempFolder(out.name + '.' + ext)
if hasattr(out, 'directory'):
out.value = getTempDirInTempFolder()
else:
ext = out.getDefaultFileExtension(alg)
out.value = getTempFilenameInTempFolder(out.name + '.' + ext)


def getTempFilename(ext):
Expand All @@ -89,6 +94,16 @@ def getTempFilenameInTempFolder(basename):
return filename


def getTempDirInTempFolder():
"""Returns a temporary directory, putting it into a temp folder.
"""

path = tempFolder()
path = os.path.join(path, str(uuid.uuid4()).replace('-', ''))
mkdir(path)
return path


def removeInvalidChars(string):
validChars = \
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.'
Expand Down

0 comments on commit 6088dba

Please sign in to comment.