#! /usr/bin/python -OOt
# -*- python -*-
# -*- coding: UTF-8 -*-
#
#  ntfs-config : NTFS Configuration Tool
#  Copyright (C) 2007 Mertens Florent <flomertens@gmail.com>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import os
import sys
import ConfigParser
import gettext
from optparse import OptionParser
from gettext import gettext as _

from NtfsConfig.NtfsConfig import *
from NtfsConfig import Utility
from NtfsConfig.Config import Config

def main(args, opts) :
    
    Utility.DEBUG_MODE = opts.debug
    
    if opts.query :
        if not os.getuid() == 0 :
            warningmsg("Query database without root privilege.")
            warningmsg("Result might be incomplete.\n")
        print info.export(opts.query)
        return 0
        
    if not os.getuid() == 0 :
        warning_dial(_("<big><b>Unsufficient privileges</b></big>"), \
            _("You need administritive privilege to start this application."), \
            "", None)
        return 0
        
    # Check for ntfs-3g 
    if not "ntfs-3g" in info.get_extra("NTFS_DRIVER") :
        warning_dial(_("Read/Write NTFS driver not installed"), \
            _("In order to enable write support for your NTFS devices, "
              "you'll need first to install the ntfs-3g driver.\n"
              "If your distribution don't provide it, you can get it from :\n"
              "http://www.ntfs-3g.org"), \
              "", None)
        return 0
        
    app = NtfsConfig()
    app.run()
        
def get_opt_args() :

    parser = OptionParser()
    parser.add_option ("-q", "--query-database", type="string", 
                       dest="query", default="", metavar="DEVICE",
                       help="Query database for DEVICE.\nSet DEVICE to all to print full database.")
    parser.add_option ("-d", "--debug", action="store_true",
                       dest="debug", default=False,
                       help="Print debugging information.")                 
                                             
    return parser.parse_args()

if __name__ == '__main__' :

    gettext.bindtextdomain("ntfs-config",localedir)
    gettext.textdomain("ntfs-config")
    (opts, args) = get_opt_args()
    sys.exit(main(args, opts))

