chenjunkai 6 年之前
父节点
当前提交
ba1bfb436a
共有 1 个文件被更改,包括 34 次插入33 次删除
  1. 34 33
      Controller/OTAEquipment.py

+ 34 - 33
Controller/OTAEquipment.py

@@ -392,41 +392,42 @@ class getUploadFiletoDirView(TemplateView):
             else:
                 return response.json(903)
 
+    def getDir(self, fileType, fileName, fileCode, fileVersion, response):
+        try:
+            if fileCode != None and fileVersion != None:
+                path = '/'.join((BASE_DIR, 'static/Upgrade', fileType, fileCode, fileVersion)).replace('\\', '/') + '/'
+            else:
+                if fileType != 'IPC' and fileType != 'DVR' and fileType != 'NVR' and fileType != 'XVR':
+                    path = '/'.join((BASE_DIR, "static/Upgrade", 'Other')).replace('\\', '/') + '/'
 
-def getDir(self, fileType, fileName, fileCode, fileVersion, response):
-    try:
-        if fileCode != None and fileVersion != None:
-            path = '/'.join((BASE_DIR, 'static/Upgrade', fileType, fileCode, fileVersion)).replace('\\', '/') + '/'
-        else:
-            if fileType != 'IPC' and fileType != 'DVR' and fileType != 'NVR' and fileType != 'XVR':
-                path = '/'.join((BASE_DIR, "static/Upgrade", 'Other')).replace('\\', '/') + '/'
-
-        if not os.path.exists(path):
-            os.makedirs(path)
-            file_name = path + str(fileName)
-            if os.path.exists(file_name):
-                os.remove(file_name)
-            destination = open(file_name, 'wb+')
-            for chunk in fileName.chunks():
-                destination.write(chunk)
-            destination.close()
+            if not os.path.exists(path):
+                os.makedirs(path)
+                file_name = path + str(fileName)
+                if os.path.exists(file_name):
+                    os.remove(file_name)
+                destination = open(file_name, 'wb+')
+                for chunk in fileName.chunks():
+                    destination.write(chunk)
+                destination.close()
+            else:
+                file_name = path + str(fileName)
+                if os.path.exists(file_name):
+                    os.remove(file_name)
+
+                destination = open(file_name, 'wb+')
+                for chunk in fileName.chunks():
+                    destination.write(chunk)
+                destination.close()
+        except Exception as e:
+            errorInfo = traceback.format_exc()
+            print('上传文件错误: %s' % errorInfo)
+            return response.json(700, {'details': repr(e)})
         else:
-            file_name = path + str(fileName)
-            if os.path.exists(file_name):
-                os.remove(file_name)
-
-            destination = open(file_name, 'wb+')
-            for chunk in fileName.chunks():
-                destination.write(chunk)
-            destination.close()
-    except Exception as e:
-        errorInfo = traceback.format_exc()
-        print('上传文件错误: %s' % errorInfo)
-        return response.json(700, {'details': repr(e)})
-    else:
-        index = file_name.find('static/')
-        filePath = file_name[index:]
-        return response.json(0, {'filePath': filePath})
+            index = file_name.find('static/')
+            filePath = file_name[index:]
+            return response.json(0, {'filePath': filePath})
+
+
 
 
 @csrf_exempt