#
###
# Application: Pycadia
# File:        config.py
# Description: Pycadia Config Class
# Copyright (c) 2002-2003   Andy Balcombe <http://www.anti-particle.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 Library 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 ConfigParser
import os
import sys
import shutil

#constants
_version = '0.5.1'
_sGladeFile = 'pycadia.glade'

def PycadiaConfig():
    """Return a Pycadia config object"""
    sFile = 'pycadia.conf'
    #which platform?
    if sys.platform != 'win32':
        #not win32 platform so...
        #is default config file writable?
        if not os.access(sFile, os.W_OK):           
            #no, do we have a user config file?
            sFile = os.path.expanduser('~/.pycadia.conf')
            if not os.path.isfile(sFile):
                #no, so create one
                #print "config: copying conf to", sFile
                shutil.copy('pycadia.conf', sFile)
        
    config = ConfigParser.ConfigParser()
    #print "config: reading", sFile
    config.read(sFile)
    #return the config filename and the config object
    return sFile, config

