# Path: RapacheCore/Configuration.py
# SYSCONFDIR = '/etc/apache2'
# SITES_ENABLED_DIR = SYSCONFDIR + '/sites-enabled'
# SITES_AVAILABLE_DIR = SYSCONFDIR + '/sites-available'
# MODS_ENABLED_DIR = SYSCONFDIR + '/mods-enabled'
# MODS_AVAILABLE_DIR = SYSCONFDIR + '/mods-available'
# APPPATH = '/usr/bin' #please fill at run-time
# GLADEPATH = '/usr/share/rapache/Glade' #please fill at run-time
# NUMBER_OF_BACKUPS = 10
# TEST_CONNECTION_INTERVAL = 30
# 
# Path: RapacheCore/Shell.py
# class CommandLogEntry:
# class CommandHandler:
#     def __init__(self, command):
#     def __init__(self, ssh_server="localhost", ssh_port=None, ssh_username=None, ssh_password=None):
#     def __get_backup_path(self, path):
#     def get_backup_files(self, path):
#     def read_file_version(self, path, date_stamp):
#     def create_backup(self, path, new_content):
#     def read_file(self, path):
#     def write_file(self, path, content, backup=True):
#     def listdir(self, path):
#     def create_complete_path ( self, complete_path ):
#     def exists(self, path):
#     def readlink(self, path):
#     def move(self, source, destination):
#     def __get_password(self, description, prompt="Password: "):
#     def __sudo_popen (self, command, password ): 
#     def is_auth_needed (self):        
#     def execute(self, command, description = None ):
#     def __output (self, command, returncode, output, error ):
#     def sudo_reset (self):
#     def ask_password(self, description = "Super user priviledges are required to perform this operation"):
#     def sudo_execute(self, command, description = "Super user priviledges are required to perform this operation"):
#     def sudo_read_file(self, path):
#     def sudo_exists(self, path):
#     def sudo_listdir(self, path):


import sys
import os
import tempfile
import re
from RapacheCore import Configuration
from RapacheCore import Shell
from xml.dom.minidom import *
# 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/>.


def is_denormalized_module ( fname ):
    try:   
        flink = Shell.command.readlink( os.path.join(Configuration.MODS_ENABLED_DIR, fname) )
        flink = os.path.join(os.path.dirname( Configuration.MODS_AVAILABLE_DIR ), flink)                        
        #no exceptions ? Means it's a link
        return True
    except:
        return False
    return False
def is_not_normalizable( fname):
     dest = os.path.join(Configuration.MODS_AVAILABLE_DIR, fname)
     return Shell.command.exists( dest )

def blacklisted ( fname ):
    if re.match( '.*[~]\s*$', fname ) != None : return True
    if re.match( '.*.swp$', fname ) != None : return True
    return False 
def normalize_module( fname ):
    print "Normalizing:", fname
    orig = os.path.join(Configuration.MODS_ENABLED_DIR, fname)
    dest = os.path.join(Configuration.MODS_AVAILABLE_DIR, fname) 
    if ( Shell.command.exists( dest ) == True ):

# Path: RapacheCore/Configuration.py
# SYSCONFDIR = '/etc/apache2'
# SITES_ENABLED_DIR = SYSCONFDIR + '/sites-enabled'
# SITES_AVAILABLE_DIR = SYSCONFDIR + '/sites-available'
# MODS_ENABLED_DIR = SYSCONFDIR + '/mods-enabled'
# MODS_AVAILABLE_DIR = SYSCONFDIR + '/mods-available'
# APPPATH = '/usr/bin' #please fill at run-time
# GLADEPATH = '/usr/share/rapache/Glade' #please fill at run-time
# NUMBER_OF_BACKUPS = 10
# TEST_CONNECTION_INTERVAL = 30
# 
# Path: RapacheCore/Shell.py
# class CommandLogEntry:
# class CommandHandler:
#     def __init__(self, command):
#     def __init__(self, ssh_server="localhost", ssh_port=None, ssh_username=None, ssh_password=None):
#     def __get_backup_path(self, path):
#     def get_backup_files(self, path):
#     def read_file_version(self, path, date_stamp):
#     def create_backup(self, path, new_content):
#     def read_file(self, path):
#     def write_file(self, path, content, backup=True):
#     def listdir(self, path):
#     def create_complete_path ( self, complete_path ):
#     def exists(self, path):
#     def readlink(self, path):
#     def move(self, source, destination):
#     def __get_password(self, description, prompt="Password: "):
#     def __sudo_popen (self, command, password ): 
#     def is_auth_needed (self):        
#     def execute(self, command, description = None ):
#     def __output (self, command, returncode, output, error ):
#     def sudo_reset (self):
#     def ask_password(self, description = "Super user priviledges are required to perform this operation"):
#     def sudo_execute(self, command, description = "Super user priviledges are required to perform this operation"):
#     def sudo_read_file(self, path):
#     def sudo_exists(self, path):
#     def sudo_listdir(self, path):


# Path: RapacheCore/Module.py
import sys
import os
import tempfile
import re
from RapacheCore import Configuration
from RapacheCore import Shell
from xml.dom.minidom import *

# 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/>.


def is_denormalized_module ( fname ):
    try:   
        flink = Shell.command.readlink( os.path.join(Configuration.MODS_ENABLED_DIR, fname) )
        flink = os.path.join(os.path.dirname( Configuration.MODS_AVAILABLE_DIR ), flink)                        
        #no exceptions ? Means it's a link
        return True
    except:
        return False
    return False
def is_not_normalizable( fname):
     dest = os.path.join(Configuration.MODS_AVAILABLE_DIR, fname)
     return Shell.command.exists( dest )

def blacklisted ( fname ):
    if re.match( '.*[~]\s*$', fname ) != None : return True
    if re.match( '.*.swp$', fname ) != None : return True
    return False 
def normalize_module( fname ):
    print "Normalizing:", fname
    orig = os.path.join(Configuration.MODS_ENABLED_DIR, fname)
    dest = os.path.join(Configuration.MODS_AVAILABLE_DIR, fname) 
    if ( Shell.command.exists( dest ) == True ):

        print fname, "already exists in available dir. not even trying"