dedump.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # This file is part of asmc, a bootstrapping OS with minimal seed
  4. # Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  5. # https://gitlab.com/giomasce/asmc
  6. # This file was ported from files in M2-Planet,
  7. # which have the following copyright notices:
  8. # Copyright (C) 2016 Jeremiah Orians
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. import sys
  20. import codecs
  21. import os
  22. def main():
  23. for line in sys.stdin:
  24. line = line.strip()
  25. if line.startswith("--DUMP--"):
  26. filename = line.split(' ', 1)[1]
  27. print("> dumping {}".format(filename))
  28. assert filename[0] == '/'
  29. filename = filename[1:]
  30. line = sys.stdin.readline().strip()
  31. content = codecs.decode(line.replace(' ', ''), 'hex')
  32. #print(repr(content))
  33. dump_path = os.path.join("dump", filename)
  34. os.makedirs(os.path.dirname(dump_path), exist_ok=True)
  35. with open(dump_path, 'wb') as fout:
  36. fout.write(content)
  37. line = sys.stdin.readline().strip()
  38. assert line == '--END_DUMP--'
  39. else:
  40. print(line)
  41. if __name__ == '__main__':
  42. main()