#!/usr/bin/python -O
# Copyright (C) 2007 Stefan J. Betz
#
# 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 3 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, see <http://www.gnu.org/licenses/>.

import os
import stat
import os.path
import ConfigParser
import pyneighborhood.config as config

if not os.path.isdir(config.homeconfdir()):
    os.mkdir(config.homeconfdir())

if not os.access(config.homeconfdir() + "/config", os.F_OK):
    f = file(config.homeconfdir() + "/config", "w")
    c = ConfigParser.SafeConfigParser()
    c.add_section("Main")
    c.set("Main", "mount_directory", os.environ["HOME"] + "/pyNeighborhood")
    if not os.path.isdir(os.environ["HOME"] + "/pyNeighborhood"):
        os.mkdir(os.environ["HOME"] + "/pyNeighborhood")
    c.set("Main", "cleanup_dirs", "True")
    c.set("Main", "enable_file_manager", "True")
    c.set("Main", "smbclient", "smbclient")
    c.set("Main", "nmblookup", "nmblookup")
    c.set("Main", "smbtree", "smbtree")
    c.set("Main", "username", "")
    c.set("Main", "password", "")
    c.set("Main", "filemanager", "xterm -e mc")
    c.add_section("SMB")
    c.set("SMB", "enable", "False")
    c.set("SMB", "mount", "smbmount")
    c.set("SMB", "unmount", "smbumount")
    c.set("SMB", "options", "")
    c.add_section("CIFS")
    c.set("CIFS", "enable", "True")
    c.set("CIFS", "mount", "/sbin/mount.cifs")
    c.set("CIFS", "unmount", "/sbin/umount.cifs")
    c.set("CIFS", "options", "")
    c.write(f)
    f.flush()
    f.close()
    del f
    del c

# Security Risk Fix:
os.chmod(config.homeconfdir() + "/config", stat.S_IRUSR + stat.S_IWUSR)

import pyneighborhood.pyneighborhood as pyneighborhood
# Start pyNeighborhood:
pyneighborhood.pyneighborhood()
