<commit_before>#!/usr/bin/python
#-*- coding: utf-8 -*-

###########################################################
# Copyright 2011 Daniel 'grindhold' Brendle and Team
#
# This file is part of Scoville.
#
# Scoville 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.
#
# Scoville 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 Scoville. 
# If not, see http://www.gnu.org/licenses/.
###########################################################

from ServerPropertyWindow import ServerPropertyWindow
from NewScoville import NewScoville
from gui.database.NewDatabase import NewDatabase
from gui.database.NewSchema import NewSchema
from gui.database.RegisterSchema import RegisterSchema
from InputBox import InputBox
from YesNoDialog import YesNoDialog
import IconStock 

class ActionRenderContext(object):
    """
    An action render context defines wich actions
    can be performed by or with this object.
    """
    def __init__(self, parent, obj):
        self.actions = []
        self.obj = obj
        self.par = parent

    def addAction(self, name, icon, callback):
        if name not in [a.getName() for a in self.actions]:
            self.actions.append(Action(name, icon, callback))

    def removeAction(self, name):
        for action in self.actions:
            if action.getName() == name:
                self.actions.remove(action)

    def getActions(self):
        return self.actions

    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()

class Action(object):
    def __init__(self, name, icon, cb):
        self.name = name
        self.icon = icon
        self.callback = cb

    def getName(self):
        return self.name

    def getIcon(self):
        return self.icon

    def getCallback(self):
        return self.callback


class ServerARC(ActionRenderContext):
    def __init__(self, par, server):
        ActionRenderContext.__init__(self, par, server)

        self.addAction('Remove', IconStock.DELETE, self.removeServer)
        self.addAction('Connect', IconStock.WIDGET, self.connectServer)
        self.addAction('Properties', IconStock.SERVER, self.Properties)
        self.addAction('Create Instance', IconStock.MODULE, self.createInstance)
        self.addAction('Register Database', IconStock.DATABASE, self.registerDatabase)

    def removeServer(self,data=None):
        def execute():
            self.obj.destroy()
        YesNoDialog(self.getApplication().mainwin, "Do you really want to remove this Server?", execute)
  
    def connectServer(self,data=None):
        self.obj.establishConnections()
        
    def Properties(self,data=None):
        ServerPropertyWindow(self.getPar().getPar(),server=self.obj)
    
    def createInstance(self,data=None):
        NewScoville(self.getPar().getPar(),server=self.obj)
    
    def registerDatabase(self, data=None):
        NewDatabase(self.getPar().getPar(), self.obj)

class ScovilleARC(ActionRenderContext):
    def __init__(self, par, scoville):
        ActionRenderContext.__init__(self, par,scoville)

        self.addAction('Destroy', IconStock.DELETE, self.destroyInstance)
        self.addAction('Remove', IconStock.DELETE, self.destroyInstance)
        self.addAction('CSS Editor', IconStock.CSS, self.destroyInstance)
        self.addAction('Update Modules', IconStock.MODULE_UPDATEABLE, self.updateModules)

    def destroyInstance(self,data=None):
        pass

    def removeInstance(self,data=None):
        def execute():
            self.obj.getServer().removeInstance(self.obj)
        YesNoDialog(self.getApplication().mainwin, "Do you really want to delete this Instance?", execute)
    
    def cssEditor(self,data=None):
        self.getApplication().mainwin.openCssEditor(self.obj)

    def updateModules(self, data=None):
        self.obj.updateModules()


class UsersARC(ActionRenderContext):
    def __init__(self, par, users):
        ActionRenderContext.__init__(self, par,users)

        self.addAction('Create User', IconStock.USER, self.createUser)<commit_msg>fixed erroneous functions and some icons<commit_after>#!/usr/bin/python
#-*- coding: utf-8 -*-

###########################################################
# Copyright 2011 Daniel 'grindhold' Brendle and Team
#
# This file is part of Scoville.
#
# Scoville 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.
#
# Scoville 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 Scoville. 
# If not, see http://www.gnu.org/licenses/.
###########################################################

from ServerPropertyWindow import ServerPropertyWindow
from NewScoville import NewScoville
from gui.database.NewDatabase import NewDatabase
from gui.database.NewSchema import NewSchema
from gui.database.RegisterSchema import RegisterSchema
from InputBox import InputBox
from YesNoDialog import YesNoDialog
import IconStock 

class ActionRenderContext(object):
    """
    An action render context defines wich actions
    can be performed by or with this object.
    """
    def __init__(self, parent, obj):
        self.actions = []
        self.obj = obj
        self.par = parent

    def addAction(self, name, icon, callback):
        if name not in [a.getName() for a in self.actions]:
            self.actions.append(Action(name, icon, callback))

    def removeAction(self, name):
        for action in self.actions:
            if action.getName() == name:
                self.actions.remove(action)

    def getActions(self):
        return self.actions

    def getPar(self):
        return self.par

    def getApplication(self):
        return self.par.getApplication()

class Action(object):
    def __init__(self, name, icon, cb):
        self.name = name
        self.icon = icon
        self.callback = cb

    def getName(self):
        return self.name

    def getIcon(self):
        return self.icon

    def getCallback(self):
        return self.callback


class ServerARC(ActionRenderContext):
    def __init__(self, par, server):
        ActionRenderContext.__init__(self, par, server)

        self.addAction('Remove', IconStock.DELETE, self.removeServer)
        self.addAction('Connect', IconStock.WIDGET, self.connectServer)
        self.addAction('Properties', IconStock.SERVER, self.Properties)
        self.addAction('Create Instance', IconStock.SCOVILLE, self.createInstance)
        self.addAction('Register Database', IconStock.DATABASE, self.registerDatabase)

    def removeServer(self,data=None):
        def execute():
            self.obj.destroy()
        YesNoDialog(self.getApplication().mainwin, "Do you really want to remove this Server?", execute)
  
    def connectServer(self,data=None):
        self.obj.establishConnections()
        
    def Properties(self,data=None):
        ServerPropertyWindow(self.getPar().getPar(),server=self.obj)
    
    def createInstance(self,data=None):
        NewScoville(self.getPar().getPar(),server=self.obj)
    
    def registerDatabase(self, data=None):
        NewDatabase(self.getPar().getPar(), self.obj)

class ScovilleARC(ActionRenderContext):
    def __init__(self, par, scoville):
        ActionRenderContext.__init__(self, par,scoville)

        self.addAction('Destroy', IconStock.DELETE, self.destroyInstance)
        self.addAction('Remove', IconStock.DELETE, self.removeInstance)
        self.addAction('CSS Editor', IconStock.CSS, self.cssEditor)
        self.addAction('Update Modules', IconStock.MODULE_UPDATEABLE, self.updateModules)

    def destroyInstance(self,data=None):
        pass

    def removeInstance(self,data=None):
        def execute():
            self.obj.getServer().removeInstance(self.obj)
        YesNoDialog(self.getApplication().mainwin, "Do you really want to delete this Instance?", execute)
    
    def cssEditor(self,data=None):
        self.getApplication().mainwin.openCssEditor(self.obj)

    def updateModules(self, data=None):
        self.obj.updateModules()


class UsersARC(ActionRenderContext):
    def __init__(self, par, users):
        ActionRenderContext.__init__(self, par,users)

        self.addAction('Create User', IconStock.USER, self.createUser)
{'fraction_non_alphanumeric': 0.12088397790055248, 'fraction_numerical': 0.0013259668508287293, 'mean_word_length': 3.4237536656891496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6421261', 'n_tokens_mistral': 2515, 'n_tokens_neox': 2435, 'n_words': 698}