Browse Source

Update main.py for DBK

Signed-off-by: ewft <bnj@ewft.org>
ewft 6 years ago
parent
commit
b33884c1e7
1 changed files with 55 additions and 10 deletions
  1. 55 10
      main.py

+ 55 - 10
main.py

@@ -1,23 +1,68 @@
 #-*- coding: utf-8 -*-
+#  File System rebuilder for Sony Xperia DBK backup file
+#  Copyright (C) 2018  Benjamin - EWFT <benjamin@ewft.org>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 3 of the License, or
+#  any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software Foundation,
+#   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+#
+
 
 import os
-from xml.etree import ElementTree as ET
+import shutil
+from xml.etree import ElementTree
+
+
+# Output folder for the reconstruction
+top_root = "../result2/"
+
+# Path to the FileSystem.xml
+FileSystemXML = "../FileSystem.xml"
 
-doc = ET.parse("template.xml").getroot()
+# Path to the Content Folder
+ContentFolder = "../Content"
+
+# Dry Run
+DryRun = True
 
 
 def folder_walk(folder, indent, root):
 	indent += "\t"
-	for folder_un in folder.findall('folder'):
-		print indent + u"⊢ " + folder_un.get('name')
-		folderpath = os.path.join(root, folder_un.get('name'))
-		os.mkdir(folderpath)
+	for folder_un in folder.findall('Folder'):
+		print indent + u"⊢ " + folder_un.get('Name')
+		folderpath = os.path.join(root, folder_un.get('Name'))
+		if DryRun:
+			print indent + "  make dir " + folderpath
+		else:
+			os.mkdir(folderpath)
 		folder_walk(folder_un, indent, folderpath)
-	for file_elmt in folder.findall('file'):
-		print indent + u"⊢ " + file_elmt.get('name') + " - " + file_elmt.get('data')
+	for file_elmt in folder.findall('File'):
+		if file_elmt.get('Content-Id') is not None:
+			print indent + u"⊢ " + file_elmt.get('Name') + " - " + file_elmt.get('Content-Id')
+			if DryRun:
+				print indent + "  move " + os.path.join(ContentFolder, file_elmt.get('Content-Id')) + " to " + os.path.join(root, file_elmt.get('Name'))
+			else:
+				shutil.move(os.path.join(ContentFolder, file_elmt.get('Content-Id')), os.path.join(root, file_elmt.get('Name')))
+
+
+doc = ElementTree.parse(FileSystemXML).getroot()
 
+if DryRun:
+	print "make dir " + top_root
+else:
+	os.mkdir(top_root)
 
-for content in doc.findall('content'):
+for content in doc.findall('Volume')[0].findall('Content'):
 	print content.tag
-	folder_walk(content, " ", "./")
+	folder_walk(content, " ", top_root)