Moved location of temp files

This commit is contained in:
Paweł Jastrzębski
2013-08-12 13:03:03 +02:00
parent c8bb9b4f5f
commit 3ccb1a63aa
2 changed files with 13 additions and 12 deletions
+12 -11
View File
@@ -597,8 +597,8 @@ def genEpubStruct(path):
def getWorkFolder(afile): def getWorkFolder(afile):
workdir = tempfile.mkdtemp()
if os.path.isdir(afile): if os.path.isdir(afile):
workdir = tempfile.mkdtemp('', 'KCC-TMP-', os.path.join(os.path.splitext(afile)[0], '..'))
try: try:
os.rmdir(workdir) # needed for copytree() fails if dst already exists os.rmdir(workdir) # needed for copytree() fails if dst already exists
fullPath = os.path.join(workdir, 'OEBPS', 'Images') fullPath = os.path.join(workdir, 'OEBPS', 'Images')
@@ -612,6 +612,7 @@ def getWorkFolder(afile):
pdf = pdfjpgextract.PdfJpgExtract(afile) pdf = pdfjpgextract.PdfJpgExtract(afile)
path = pdf.extract() path = pdf.extract()
else: else:
workdir = tempfile.mkdtemp('', 'KCC-TMP-', os.path.splitext(afile)[0])
cbx = cbxarchive.CBxArchive(afile) cbx = cbxarchive.CBxArchive(afile)
if cbx.isCbxFile(): if cbx.isCbxFile():
try: try:
@@ -682,8 +683,8 @@ def getDirectorySize(start_path='.'):
return total_size return total_size
def createNewTome(): def createNewTome(parentPath):
tomePathRoot = tempfile.mkdtemp() tomePathRoot = tempfile.mkdtemp('', 'KCC-TMP-', parentPath)
tomePath = os.path.join(tomePathRoot, 'OEBPS', 'Images') tomePath = os.path.join(tomePathRoot, 'OEBPS', 'Images')
os.makedirs(tomePath) os.makedirs(tomePath)
return tomePath, tomePathRoot return tomePath, tomePathRoot
@@ -700,7 +701,7 @@ def walkLevel(some_dir, level=1):
del dirs[:] del dirs[:]
def splitDirectory(path, mode): def splitDirectory(path, mode, parentPath):
output = [] output = []
currentSize = 0 currentSize = 0
currentTarget = path currentTarget = path
@@ -709,7 +710,7 @@ def splitDirectory(path, mode):
for name in files: for name in files:
size = os.path.getsize(os.path.join(root, name)) size = os.path.getsize(os.path.join(root, name))
if currentSize + size > 262144000: if currentSize + size > 262144000:
currentTarget, pathRoot = createNewTome() currentTarget, pathRoot = createNewTome(parentPath)
output.append(pathRoot) output.append(pathRoot)
currentSize = size currentSize = size
else: else:
@@ -721,7 +722,7 @@ def splitDirectory(path, mode):
for name in dirs: for name in dirs:
size = getDirectorySize(os.path.join(root, name)) size = getDirectorySize(os.path.join(root, name))
if currentSize + size > 262144000: if currentSize + size > 262144000:
currentTarget, pathRoot = createNewTome() currentTarget, pathRoot = createNewTome(parentPath)
output.append(pathRoot) output.append(pathRoot)
currentSize = size currentSize = size
else: else:
@@ -734,7 +735,7 @@ def splitDirectory(path, mode):
if root != path: if root != path:
size = getDirectorySize(os.path.join(root, name)) size = getDirectorySize(os.path.join(root, name))
if currentSize + size > 262144000: if currentSize + size > 262144000:
currentTarget, pathRoot = createNewTome() currentTarget, pathRoot = createNewTome(parentPath)
output.append(pathRoot) output.append(pathRoot)
currentSize = size currentSize = size
else: else:
@@ -761,7 +762,7 @@ def preSplitDirectory(path):
GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href=' GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'Click for more details.</a>', 'warning') 'More details.</a>', 'warning')
GUI.emit(QtCore.SIGNAL("addMessage"), '') GUI.emit(QtCore.SIGNAL("addMessage"), '')
return [path] return [path]
detectedSubSubdirectories = False detectedSubSubdirectories = False
@@ -776,7 +777,7 @@ def preSplitDirectory(path):
GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href=' GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'Click for more details.</a>', 'warning') 'More details.</a>', 'warning')
GUI.emit(QtCore.SIGNAL("addMessage"), '') GUI.emit(QtCore.SIGNAL("addMessage"), '')
return [path] return [path]
if len(files) != 0: if len(files) != 0:
@@ -793,11 +794,11 @@ def preSplitDirectory(path):
GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href=' GUI.emit(QtCore.SIGNAL("addMessage"), 'Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'Click for more details.</a>', 'warning') 'More details.</a>', 'warning')
GUI.emit(QtCore.SIGNAL("addMessage"), '') GUI.emit(QtCore.SIGNAL("addMessage"), '')
return [path] return [path]
# Split directories # Split directories
split = splitDirectory(os.path.join(path, 'OEBPS', 'Images'), mode) split = splitDirectory(os.path.join(path, 'OEBPS', 'Images'), mode, os.path.join(path, '..'))
path = [path] path = [path]
for tome in split: for tome in split:
path.append(tome) path.append(tome)
+1 -1
View File
@@ -29,7 +29,7 @@ class PdfJpgExtract:
def __init__(self, origFileName): def __init__(self, origFileName):
self.origFileName = origFileName self.origFileName = origFileName
self.filename = os.path.splitext(origFileName) self.filename = os.path.splitext(origFileName)
self.path = self.filename[0] self.path = self.filename[0] + "-KCC-TMP"
def getPath(self): def getPath(self):
return self.path return self.path