#!/usr/bin/python

import sys
import syslog
import traceback
import isi.sys.disk as disk
import isi.sys.bootdisk as bootdisk

if __name__ == '__main__':
    try:
        # Do nothing unless this is a GPT system.
        if (not bootdisk.current_system_is_geom() and
            not bootdisk.future_system_is_geom()):
            sys.exit(0)
        if sys.argv[1] == '--all':
            bootdisk.newfs_journal_backup()
            disk.pre_newfs_disks()
        else:
            ret = disk.pre_newfs_disk(sys.argv[1])
            sys.exit(ret)
    # Ignore exceptions from sys.exit() calls
    except SystemExit as e:
        sys.exit(e)
    except:
        syslog.openlog("isi_pre_newfs")
        etype, evalue, etb = sys.exc_info()
        lines = traceback.format_exception(etype, evalue, etb)
        for line in lines:
            syslog.syslog(syslog.LOG_ERR, line.strip())
        raise

