Browse Source

fix: 文件夹结构的entity

tuon 1 year ago
parent
commit
9dccfe2e2c
2 changed files with 11 additions and 4 deletions
  1. 8 3
      task.py
  2. 3 1
      tools/image.py

+ 8 - 3
task.py

@@ -82,11 +82,16 @@ class Interface:
             count += 1
             logger.info("PROGRESS", extra={'event_type': EventType.PROGRESS, 'total': files_in_total, 'current': count})
             try:
+                real_path = os.path.dirname(path)
+                real_path = os.path.relpath(real_path, self.input)
+                output = os.path.join(self.result, real_path)
+                if not os.path.exists(output):
+                    os.makedirs(output)
+
                 params = copy.deepcopy(self.params)
-                params.set_path(path)
+                params.set_path(path, output)
                 if not tools.processor(params):
-                    real_path = os.path.relpath(path, self.input)
-                    shutil.copy(path, os.path.join(self.result, real_path))
+                    shutil.copy(path, os.path.join(output, os.path.basename(path)))
 
             except Exception as e:
                 logger.info(e, extra={'event_type': EventType.TASK_CRASHED, 'traceback': traceback.format_exc()})

+ 3 - 1
tools/image.py

@@ -42,8 +42,10 @@ class ProcessorParams:
         self.out_dir = out_dir
         self.path = path
 
-    def set_path(self, path):
+    def set_path(self, path, out_dir):
         self.path = path
+        self.out_dir = out_dir
+
 
 
 def processor(params: ProcessorParams):