#!/usr/bin/env python

import os
import sys
from gettext import gettext as _
import gettext
gettext.textdomain("displayconfig-gtk")

from optparse import OptionParser

__version__ = "0.3.2"

def dump_pci_table(options):
    """Dump the current used pci table to a file"""
    from ScanPCI import PCIBus
    pci_bus = PCIBus("/usr/share/apps/guidance")
    pci_bus.detect()
    try:
        dump = open(options.dumpfile, "w")
        dump.write(str(pci_bus))
        dump.close()
    except:
        print "Failed to write PCI table to file"
        sys.exit(1)
    print "Wrote PCI table to %s" % options.dumpfile
    sys.exit(0)

if __name__ == "__main__":

    parser = OptionParser(version=__version__)
    parser.add_option("-c", "--xconfig",
                      default=None,
                      action="store", type="string", dest="xconfigpath",
                      #TRANSLATORS: command line option
                      help=_("Use an alternative X11 configuration"
                             "file"))
    parser.add_option("-p", "--pcitable",
                      default=None,
                      action="store", type="string", dest="pcitable",
                      #TRANSLATORS: command line option
                      help=_("Read device information from the given file"
                             "(Only needed by developers)"))
    parser.add_option("-w", "--write-pcitable",
                      default=None,
                      action="store", type="string", dest="dumpfile",
                      #TRANSLATORS: command line option
                      help=_("Write device information to the given file "
                             "(Only needed by developers)"))
    parser.add_option("", "--locations-config",
                      default="/var/lib/displayconfig-gtk/locations.conf",
                      action="store", type="string", dest="locationspath",
                      #TRANSLATORS: command line option
                      help=_("Use the locations config file (Only needed by "
                             "developers)"))
    parser.add_option("-d", "--data-dir",
                      default="/usr/share/displayconfig-gtk",
                      action="store", type="string", dest="datadir",
                      #TRANSLATORS: command line option
                      help=_("Use the given data dir (Only needed by "
                             "developers)"))
    parser.add_option("", "--no-instant-apply",
                      action="store_true", dest="instantapply",
                      #TRANSLATORS: command line option
                      help=_("Do not apply changes instantly"))
    parser.add_option("", "--failsafe-mode",
                      default=None,
                      action="store", type="string", dest="failsafemode",
                      #TRANSLATORS: command line option
                      help=_("Running in Failsafe X mode with this xorg.conf"))
    (options, args) = parser.parse_args()

    if options.dumpfile != None:
        dump_pci_table(options)
    from displayconfiggtk.DisplayConfig import DisplayConfig
    app = DisplayConfig(options)
    app.run()

    sys.exit(0)

# vim:ts=4:sw=4:et
