[pp:classify] use temppath

This commit is contained in:
Mike Fährmann
2018-06-06 21:10:28 +02:00
parent 97189e50cd
commit 37d97ff02c

View File

@@ -6,7 +6,7 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
"""Categorize files by media type"""
"""Categorize files by file extension"""
from .common import PostProcessor
import os
@@ -24,9 +24,9 @@ class ClassifyPP(PostProcessor):
def __init__(self, options):
PostProcessor.__init__(self)
mapping = options.get("map", self.DEFAULT_MAP)
mapping = options.get("mapping", self.DEFAULT_MAP)
self.map = {
self.mapping = {
ext: directory
for directory, exts in mapping.items()
for ext in exts
@@ -35,17 +35,10 @@ class ClassifyPP(PostProcessor):
def run(self, pathfmt):
ext = pathfmt.keywords["extension"]
if ext in self.map:
directory = self.map[ext]
path = os.path.join(pathfmt.realdirectory, directory)
try:
os.mkdir(path)
except FileExistsError:
pass
os.replace(
pathfmt.realpath,
os.path.join(path, pathfmt.filename)
)
if ext in self.mapping:
path = pathfmt.realdirectory + os.sep + self.mapping[ext]
pathfmt.realpath = path + os.sep + pathfmt.filename
os.makedirs(path, exist_ok=True)
__postprocessor__ = ClassifyPP