main.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #-*- coding: utf-8 -*-
  2. # File System rebuilder for Sony Xperia DBK backup file
  3. # Copyright (C) 2018 Benjamin - EWFT <benjamin@ewft.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. import os
  20. import shutil
  21. from xml.etree import ElementTree
  22. # Output folder for the reconstruction
  23. top_root = "../result2/"
  24. # Path to the FileSystem.xml
  25. FileSystemXML = "../FileSystem.xml"
  26. # Path to the Content Folder
  27. ContentFolder = "../Content"
  28. # Dry Run
  29. DryRun = True
  30. def folder_walk(folder, indent, root):
  31. indent += "\t"
  32. for folder_un in folder.findall('Folder'):
  33. print indent + u"⊢ " + folder_un.get('Name')
  34. folderpath = os.path.join(root, folder_un.get('Name'))
  35. if DryRun:
  36. print indent + " make dir " + folderpath
  37. else:
  38. os.mkdir(folderpath)
  39. folder_walk(folder_un, indent, folderpath)
  40. for file_elmt in folder.findall('File'):
  41. if file_elmt.get('Content-Id') is not None:
  42. print indent + u"⊢ " + file_elmt.get('Name') + " - " + file_elmt.get('Content-Id')
  43. if DryRun:
  44. print indent + " move " + os.path.join(ContentFolder, file_elmt.get('Content-Id')) + " to " + os.path.join(root, file_elmt.get('Name'))
  45. else:
  46. shutil.move(os.path.join(ContentFolder, file_elmt.get('Content-Id')), os.path.join(root, file_elmt.get('Name')))
  47. doc = ElementTree.parse(FileSystemXML).getroot()
  48. if DryRun:
  49. print "make dir " + top_root
  50. else:
  51. os.mkdir(top_root)
  52. for content in doc.findall('Volume')[0].findall('Content'):
  53. print content.tag
  54. folder_walk(content, " ", top_root)