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