#!/usr/bin/env python3

# This script parses the Master-Index.xml file, using the ifarchivexml
# module. (ifarchivexml.py must be in the current directory, or in your
# Python path.)
#
# Two handy ways to use this:
#
#   python3 -i parse-ifarchive.py Master-Index.xml
#
# Starts Python in interactive mode, with rootdir set to the root directory,
# dirs set to a dictionary of directories, and files set to a dictionary
# of files.
#
#   python3 parse-ifarchive.py Master-Index.xml Master-Index.pik
#
# Creates a pickle file containing the pickled tuple (rootdir, dirs, files).
# This can then be loaded with the Python commands:
#   import pickle
#   fl = open('Master-Index.pik', 'r')
#   (rootdir, dirs, files) = pickle.load(fl)
#   fl.close()
#
# Dec 2019: Updated to Python 3.

import sys
import pickle
import ifarchivexml

if (len(sys.argv) < 2):
    print('usage: parse-ifarchive.py file.xml [file.pik]')
    sys.exit()

result = ifarchivexml.parse(sys.argv[1])
(rootdir, dirs, files) = result

if (len(sys.argv) > 2):
    fl = open(sys.argv[2], 'wb')
    pickle.dump(result, fl)
    fl.close()
