Пример #1
0
def main():

    from class_macro import Macros
    from widget_macro import WidgetMacros
    from class_plugins import Plugins

    macros_id = request.shared_variables["macro_id"]
    plugin_id = request.shared_variables["plugin_id"]
    if macros_id:
        macros = Macros.get_by_id(macros_id)
        macros.delete()

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()
    config_is_exist = False
    for m in macros:
        if m.name == "config":
            config_is_exist = True

    if config_is_exist == True:
        self.button_config.visible = "1"
        self.button_create_config.visible = "0"
    else:
        self.button_config.visible = "0"
        self.button_create_config.visible = "1"

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()

    widget_macros = WidgetMacros()
    widget_macros.set_data(macros)
    widget_macros.render(self.datatable_macros)

    self.dialog_delete_macro.action("hide", [])
    response.shared_variables["macro_id"] = ""
Пример #2
0
def main():

    from class_plugins import Plugins
    from class_macro import Macros
    from VEE_resources import create_plugin_dir

    def invoke_dispather(macros):

        from VEE_vmacro_dispatcher import InvokeDispatcher
        from VEE_std_lib import v_currentpage

        invoke_disp = InvokeDispatcher()
        invoke_disp.page = self
        invoke_disp.growl = self.growl
        invoke_disp.xmldialog = self.xmldialog
        invoke_disp.macros = macros

        current_page = v_currentpage()
        current_page.page_name = self.name

        invoke_disp.current_page = current_page
        invoke_disp.run()

    plugin_id = session["plugin_id"] = request.arguments.get("keyField", "")
    cell_name = request.arguments.get("headerData", "")

    if plugin_id:
        plugin = Plugins.get_by_id(plugin_id)

        if cell_name and plugin:

            if cell_name == "Update":
                self.dialog_update_plugin.text_description.action(
                    "setText", ["Plugin to update - %s" % (plugin.name)])
                self.dialog_update_plugin.form.formtext_pluginid.action(
                    "setValue", [plugin.id])
                self.dialog_update_plugin.action("show", [""])

            elif cell_name == "Export":
                self.action("goTo", ["/plugins?op=export"])

            elif cell_name == "Open":
                create_plugin_dir(plugin.guid)
                self.action("goTo", ["/plugin_details?id=%s" % plugin_id])

            elif cell_name == "Delete":
                session["plugin_id"] = plugin_id
                self.dialog_uninstall.action("show", [])

            elif cell_name == "MD5":
                self.dialog_md5.text_md5.action("setText", [plugin.get_md5()])
                self.dialog_md5.action("show", [])

            elif cell_name == "Config":
                from class_macro import Macros
                macros = Macros.get_config_macro(plugin.guid)
                if macros:
                    invoke_dispather(macros)
Пример #3
0
def main():

	#macros invoked from macros
	object_guid = request.arguments.get( "macros_id" )
	if object_guid:
		from class_macro import Macros
		macros = Macros.get_by_guid( object_guid )
		if macros:
			invoke_dispather( macros )
Пример #4
0
    def export(self):
        from StringIO import StringIO
        import base64

        from class_xml_plugin import XMLPlugin
        xml_plugin = XMLPlugin()

        xml_plugin.picture = base64.b64encode(
            application.storage.readall(self.picture)) if self.picture else ''
        xml_plugin.description = self.description if self.description else ''
        xml_plugin.name = self.name if self.name else ''
        xml_plugin.version = self.version if self.version else ''
        xml_plugin.author = self.author if self.author else ''
        xml_plugin.guid = self.guid

        #raise Exception(name, description, author)
        #outp.write(xml_plugin"<plugin guid='" + self.guid + "' name='" + name + "' description='" + description + "' picture='" + picture + "' author='" + author + "' version='"+ version +"'>")

        timers = self.get_timer()
        for timer in timers:
            from class_timer import Timer
            t = Timer.get_by_id(timer.id)
            xml_plugin.append_child(t.get_xmlnode())

        custom_events = self.get_custom_event()
        for cevent in custom_events:
            from class_custom_event import CustomEvent
            ce = CustomEvent.get_by_id(cevent.id)
            xml_plugin.append_child(ce.get_xmlnode())

        from VEE_sqlite3 import DatabaseManager
        from VEE_resources import ResourceFolderManager

        db_list = DatabaseManager(self.guid).databaselist
        for db in db_list:
            from class_plugin_db import PluginDB
            plugin_db = PluginDB(db, DatabaseManager(self.guid).export_db(db))
            xml_plugin.append_child(plugin_db.get_xmlnode())

        res_list = ResourceFolderManager(self.guid).resourcelist
        for res in res_list:
            from class_resource import Resource
            resource = Resource(
                res,
                ResourceFolderManager(self.guid).export_res(res))
            xml_plugin.append_child(resource.get_xmlnode())

        macros = self.get_macros()
        for macro in macros:
            from class_macro import Macros
            m = Macros.get_by_id(macro.id)
            xml_plugin.append_child(m.get_xmlnode())

        outp = StringIO()
        outp.write(xml_plugin.toprettyxml().encode('utf8'))
        return outp
Пример #5
0
def main():

	from class_plugins import Plugins

	plugin_id = request.shared_variables[ "plugin_id" ]
	plugin = Plugins.get_by_id( plugin_id )
	if plugin:
		from class_macro import Macros
		macros = Macros.get_config_macro( plugin.guid )
		if macros:
			invoke_dispather( macros )
    def delete(self):
        from class_macro import Macros

        macros_list = Macros.get_macros_by_custom_event_guid(self.guid)
        for macros in macros_list:
            macros.class_name = "NULL"
            macros.custom_event = "NULL"
            macros.is_button_macros = "1"
            macros.on_board = "0"
            macros.save()

        self.unregister()
        Database.macrosdb().commit("""DELETE FROM custom_event WHERE id=?""",
                                   (self.id, ))
Пример #7
0
def main():

    from class_macro import Macros

    #click on macros\plugiuns panel
    object_guid = request.arguments.get("id")
    if object_guid:

        if object_guid.find("_", 0) == 1:
            #parse guid
            prefix, object_guid = object_guid.split("_", 1)
            #check prefix value

            if prefix == "p":  #it is plugin guid

                from widget_macros_datatable import WidgetMacrosDatatable
                widget_macro_table = WidgetMacrosDatatable(
                    object_guid, self.name)
                widget_macro_table.render(  self.dialog_plugin_macros.datatable,\
                       self.dialog_plugin_macros )

                self.dialog_plugin_macros.show = "1"
                return

            elif prefix <> "m":
                raise Exception("Unknown GUID")

    #click from dialog_plugin_macros.datatable
    elif request.arguments.get("keyField"):
        object_guid = request.arguments.get("keyField")

    #macros invoked from macros
    elif request.arguments.get("macros_id"):
        object_guid = request.arguments.get("macros_id")

    else:
        raise Exception("Bad GUID")

    macros = Macros.get_by_guid(object_guid)
    if not macros:
        raise Exception("Bad GUID")

    invoke_dispather(macros)
Пример #8
0
	def set_data(self, data):
		plugins = []
		for plugin in data:
			config_macros = Macros.get_config_macro(plugin.guid)
			plugins.append({"id": plugin.id,
					"Picture" : "<img src='/get_image?id="+plugin.picture+"' width='48'/>" if plugin.picture else "<img src='/abfbe7cf-76ac-46ba-9ba8-6c89933d7cae.png' />",
					"Plugin_info" : "<h1>" +plugin.name + "</h1><h2>by " + plugin.author + "</h2><p class='clearfix'></p><p>" + plugin.description + "</p><p>Version " + plugin.version + "</p>",
					"Update" : "<a href=''><img src='/7452291d-f0c0-444c-997f-ba3064ddc0c7.res'/>Update</a>",
					"Export" : "<a href=''><img src='/cb4d01af-36f7-418d-94d8-e8a0546e5877.res'/>Export</a>",
					"Open" : "<a href=''><img src='/3827f2ea-edca-491a-bc5f-a765776dd109.res'/>Open</a>",
					"Delete" : "<a href=''>Uninstall</a>",
					"MD5" : "<a href=''>Get MD5</a>",
					"Config" : ("<a href=''>Config</a>" if config_macros else "")} if not plugin.protected else {"id": plugin.id,
					"Picture" : "<img src='/get_image?id="+plugin.picture+"' width='48'/>" if plugin.picture else "<img src='/abfbe7cf-76ac-46ba-9ba8-6c89933d7cae.png' />",
					"Plugin_info" : "<h1>" +plugin.name + "</h1><h2>by " + plugin.author + "</h2><p class='clearfix'></p><p>" + plugin.description + "</p><p>Version " + plugin.version + "</p><p>Protected</p>" ,
					"Update" : "<a href=''><img src='/7452291d-f0c0-444c-997f-ba3064ddc0c7.res'/>Update</a>",
					"Export" : "",
					"Open" : "",
					"Delete" : "<a href=''>Uninstall</a>",
					"MD5" : "<a href=''>Get MD5</a>",
					"Config" : ("<a href=''>Config</a>" if config_macros else "")})

		self.__plugins_list = json.dumps(plugins)
Пример #9
0
def main():

    from class_timer import Timer
    from class_custom_event import CustomEvent
    from class_macro import Macros
    import json, localization
    from class_plugins import Plugins
    from config import config
    from VEE_events import event_map

    lang = localization.get_lang()

    macros_id = request.shared_variables["macro_id"]
    plugin_id = request.shared_variables["plugin_id"]
    plugin = Plugins.get_by_id(plugin_id)

    macro_type = request.arguments.get("itemValue", Macros.MacrosType.UNKNOWN)

    def setup_event_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "1"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "1"
        self.dialog_create_macro.form_macro.container_back.formlist_page.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_timer.visible = "0"

        event_dict = {}
        for event in event_map:
            event_dict[event] = lang[event_map[event].__name__]

        for timer in Timer.get_timer_by_plugin_guid(plugin.guid):
            event_dict[timer.guid] = timer.name

        for cevent in CustomEvent.get_custom_event_by_plugin_guid(plugin.guid):
            event_dict[cevent.guid] = cevent.name

        self.dialog_create_macro.form_macro.container_back.formlist_event.value = json.dumps(
            event_dict)

    def setup_button_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = config[
            "plugin_page_dict"].keys()[0]
        self.dialog_create_macro.form_macro.container_back.formlist_page.value = json.dumps(
            config["plugin_page_dict"])
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "1"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "1"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_location.value = json.dumps(
            {
                "1": "On panel",
                "2": "In plugin menu"
            })

    def setup_library_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_page.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_timer.visible = "0"

    if macros_id and macro_type == Macros.MacrosType.UNKNOWN:

        macros = Macros.get_by_id(macros_id)

        self.dialog_create_macro.form_macro.formtext_id.value = macros_id
        self.dialog_create_macro.form_macro.formtext_name.value = macros.name
        self.dialog_create_macro.form_macro.formtextarea_description.value = macros.description
        macro_type = macros.type

        if macros.type == Macros.MacrosType.EVENT:
            setup_event_type_controls()

            if macros.timer_guid:
                self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = macros.timer_guid
            elif macros.custom_event_guid:
                self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = macros.custom_event_guid
            elif macros.class_name:
                for event in event_map:
                    if event_map[event].__name__ == macros.class_name:
                        self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = event
                        break

        elif macros.type == Macros.MacrosType.BUTTON:
            setup_button_type_controls()
            self.dialog_create_macro.form_macro.container_back.formlist_location.selectedvalue = "1" if macros.on_board == "1" else "2"
            self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = macros.page

        else:
            setup_library_type_controls()

    self.dialog_create_macro.form_macro.container_back.formlist_type.value = json.dumps(
        {
            Macros.MacrosType.EVENT: "Event macro",
            Macros.MacrosType.BUTTON: "Button macro",
            Macros.MacrosType.LIBRARY: "Library"
        })

    if macro_type == Macros.MacrosType.UNKNOWN:
        macro_type = Macros.MacrosType.EVENT

    self.dialog_create_macro.form_macro.container_back.formlist_type.selectedvalue = macro_type

    if macro_type == Macros.MacrosType.BUTTON:
        setup_button_type_controls()

    elif macro_type in Macros.MacrosType.EVENT:
        setup_event_type_controls()

    else:
        setup_library_type_controls()
Пример #10
0
            except Exception, ex:
                self.growl.title = lang["error"]
                self.growl.text = ex
                self.growl.show = "1"

    if "formbutton_import" in request.arguments:
        if request.arguments.get("uploader", "", castto=Attachment):
            file = request.arguments.get("uploader", "", castto=Attachment)
            xml_data = file.handler.read()
            dom = parseString(xml_data)
            node = XMLMacros(dom)

            for child in node.childs:
                child = XMLMacros(child)
                if child.name and child.source:
                    macros = Macros()
                    macros.name = child.name
                    macros.code = child.source
                    macros.class_name = child.class_name
                    macros.is_button_macros = child.is_button
                    macros.on_board = child.on_board

                    picture_name = ""
                    macros.macros_picture = ""
                    if child.macros_picture:
                        macros.macros_picture = picture_name = str(uuid4())
                        application.storage.write(
                            picture_name,
                            base64.b64decode(child.macros_picture))

                    macros.save()
Пример #11
0
def main():

    from class_macro import Macros
    from class_timer import Timer
    from class_custom_event import CustomEvent
    from widget_plugins import WidgetPlugins
    from widget_macro import WidgetMacros
    from class_plugins import Plugins
    import localization

    lang = localization.get_lang()

    from VEE_events import event_map

    name = self.dialog_create_macro.form_macro.formtext_name.value = request.arguments.get(
        "formtext_name", "")
    macros_type = self.dialog_create_macro.form_macro.container_back.formlist_type.selectedvalue = request.arguments.get(
        "formlist_type", Macros.MacrosType.LIBRARY)
    event = self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = request.arguments.get(
        "formlist_event", "")
    location = self.dialog_create_macro.form_macro.container_back.formlist_location.selectedvalue = request.arguments.get(
        "formlist_location", "")
    description = self.dialog_create_macro.form_macro.formtextarea_description.value = request.arguments.get(
        "formtextarea_description", "")
    macros_id = self.dialog_create_macro.form_macro.formtext_id.value = request.arguments.get(
        "formtext_id", "")
    page = self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = request.arguments.get(
        "formlist_page", "")

    import re
    guid_regex = re.compile(
        "^[a-zA-Z0-9]{8}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{12}$"
    )

    class_name = ""
    timer_guid = ""
    custom_event_guid = ""
    is_button = "0"
    on_board = "0"

    if macros_type == Macros.MacrosType.EVENT:
        is_button = "0"
        if guid_regex.match(event):
            if Timer.get_timer_by_guid(event):
                timer_guid = event
                class_name = "VEE_TimerEvent"
            elif CustomEvent.get_custom_event_by_guid(event):
                custom_event_guid = event
                class_name = "VEE_CustomEvent"
        else:
            for e in event_map:
                if e == int(event):
                    class_name = event_map[e].__name__

    elif macros_type == Macros.MacrosType.BUTTON:
        is_button = "1"
        on_board = "1" if location and location == "1" else "0"

    elif macros_type != Macros.MacrosType.LIBRARY:
        macros_type = Macros.MacrosType.LIBRARY

    plugin_id = request.shared_variables["plugin_id"]
    plugin = Plugins.get_by_id(plugin_id)
    macros = Macros.get_by_id(macros_id) if macros_id else Macros()
    macros.name = name
    macros.class_name = class_name
    macros.timer_guid = timer_guid
    macros.custom_event_guid = custom_event_guid
    macros.is_button_macros = is_button
    macros.on_board = on_board
    macros.description = description
    macros.plugin_guid = plugin.guid
    macros.page = page
    macros.type = macros_type
    macros.save()

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()

    widget_macros = WidgetMacros()
    widget_macros.set_data(macros)
    widget_macros.render(self.datatable_macros)
    self.dialog_create_macro.action("hide", [])
Пример #12
0
def main():

    from class_macro import Macros
    from class_plugins import Plugins
    import cgi, localization

    lang = localization.get_lang()

    macros_id = request.arguments.get("id")
    response.shared_variables["macro_id"] = macros_id
    plugin = ""
    if macros_id:
        macros = Macros.get_by_id(macros_id)
        plugin = Plugins.get_by_guid(macros.plugin_guid)
        if plugin.protected:
            response.redirect("/plugins.vdom")
        self.form_macros.codeeditor_macros_body.value = macros.code if macros.code else ""

    if "formbutton_apply" in request.arguments:
        if plugin:
            source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
                "codeeditor_macros_body", "")
            macros = Macros.get_by_id(macros_id) if macros_id else Macros()
            macros.code = source
            macros.save()
            response.redirect("/plugin_details?id=" + str(plugin.id))
        else:
            self.growl.title = lang["error"]
            self.growl.text = "Unknown macro"
            self.growl.visible = "1"

    elif "formbutton_check" in request.arguments:
        if macros_id:
            source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
                "codeeditor_macros_body", "")
            if source:

                from VEE_tools import compile, VScriptComlipationError, PythonCompilationError
                try:
                    compile(source)
                except VScriptComlipationError as error:
                    self.growl.title = lang["error"]
                    self.growl.text = u"VScript Compilation Error (Line {line}): {msg}".format(
                        line=error.line, msg=error.message)
                    self.growl.visible = "1"

                except PythonCompilationError as error:
                    self.growl.title = lang["error"]
                    self.growl.text = u"Python Compilation Error: {msg}".format(
                        msg=error.message)
                    self.growl.visible = "1"

            else:
                self.growl.title = lang["error"]
                self.growl.text = lang["type_macros_code_error"]
                self.growl.visible = "1"

        else:
            self.growl.title = lang["error"]
            self.growl.text = lang["fill_macros_fields_error"]
            self.growl.visible = "1"

    elif "formbutton_cancel" in request.arguments:
        response.redirect("/plugin_details?id=" +
                          str(plugin.id)) if plugin else response.redirect(
                              "/plugins")
Пример #13
0
def check():
    from VEE_tools import compile, VScriptComlipationError, PythonCompilationError
    try:
        compile(source)
        return "Passed well."
        self.growl.action('show', ["Message", u"No errors in code."])
    except VScriptComlipationError as error:
        return u"VScript Compilation Error (Line {line}): {msg}".format(
            line=error.line, msg=error.message)
    except PythonCompilationError as error:
        return u"Python Compilation Error: {msg}".format(msg=error.message)


macro_id = request.shared_variables["macro_id"]
macro = Macros.get_by_id(macro_id)
plugin = Plugins.get_by_guid(macro.plugin_guid)
if plugin and macro:
    source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
        "codeeditor_macros_body", "")
    macro.code = source
    macro.save()
    result = check()
    self.growl.action(
        'show',
        ["Message", u"Your work is saved! Compilnig: {0}".format(result)])

else:
    self.growl.action('show', [
        "Error =(", u"Can't save code macro. Please, try to reload the page."
    ])
Пример #14
0
def main():

	from class_macro import Macros
	from widget_plugins import WidgetPlugins
	from widget_macro import WidgetMacros
	from class_plugins import Plugins

	plugin_id = request.shared_variables["plugin_id"]
	plugin = Plugins.get_by_id(plugin_id)

	macros = Macros()
	macros.name 		= "config"
	macros.class_name	= ""
	macros.timer_guid 	= ""
	macros.is_button_macros = "1"
	macros.on_board 	= "1"
	macros.description 	= "config macro"
	macros.plugin_guid = plugin.guid
	macros.save()

	plugin = Plugins.get_by_id(plugin_id)
	macros = plugin.get_macros()

	widget_macros = WidgetMacros()
	widget_macros.set_data(macros)
	widget_macros.render(self.datatable_macros)

	self.button_create_config.visible = "0"
	self.button_config.visible = "1"
Пример #15
0
			if child.tag == "timer":
				child = XMLTimer( child )
				if child.name:
					timer = Timer()
					timer.fill_from_xml( child, node.guid )

			elif child.tag == "custom_event":
				child = XMLCustomEvent( child )
				if child.name:
					custom_event = CustomEvent()
					custom_event.fill_from_xml( child, node.guid )

			elif child.tag == "macro":
				child = XMLMacros( child )
				if child.name and child.source:
					macros = Macros()
					macros.fill_from_xml( child, node.guid )

			elif child.tag == "database":
				child = XMLPluginDB( child )
				if child.name:
					dbManager.import_db( child.name, base64.b64decode( child.db_source ) )

			elif child.tag == "resource":
				child = XMLResource( child )
				if child.name:
					resManager.import_res( child.name, base64.b64decode( child.res_source ) )


	except Exception, ex:
		raise Exception(ex)
Пример #16
0
                plugin.delete()

                new_plugin.picture = ""
                if node.picture:
                    new_plugin.picture = str(uuid4())
                    application.storage.write(new_plugin.picture,
                                              base64.b64decode(node.picture))

                new_plugin.save()

                for child in node.childs:
                    if child.tag == "macro":
                        child = XMLMacros(child)

                        if child.name and child.source:
                            macros = Macros()
                            macros.fill_from_xml(child, node.guid)
                    elif child.tag == "timer":
                        child = XMLTimer(child)

                        if child.name:
                            timer = Timer()
                            timer.fill_from_xml(child, node.guid)
                    elif child.tag == "custom_event":
                        child = XMLCustomEvent(child)

                        if child.name:
                            custom_event = CustomEvent()
                            custom_event.fill_from_xml(child, node.guid)
                    elif child.tag == "database":
                        child = XMLPluginDB(child)
Пример #17
0
 def get_macros(self):
     from class_macro import Macros
     self.__macros = Macros.get_macros_by_plugin_guid(self.guid)
     return self.__macros
Пример #18
0
def main():

    import json, localization, base64
    from xml.dom.minidom import parseString
    from class_macro import Macros
    from class_plugins import Plugins
    from class_timer import Timer
    from class_custom_event import CustomEvent
    from class_xml_macro import XMLMacros
    from class_xml_timer import XMLTimer
    from class_xml_custom_event import XMLCustomEvent
    from class_xml_plugin import XMLPlugin
    from class_xml_plugin_db import XMLPluginDB
    from class_xml_resource import XMLResource
    from utils.uuid import uuid4
    from widget_localization import LocalizationWidget
    from widget_plugins import WidgetPlugins
    from VEE_resources import create_plugin_dir, ResourceFolderManager
    from VEE_sqlite3 import DatabaseManager

    lang = localization.get_lang()

    if "formbutton_save_plugin" in request.arguments:
        plugin = Plugins()
        plugin.guid = str(uuid4())
        plugin.name = request.arguments.get("formtext_name", "")
        plugin.author = request.arguments.get("formtext_author", "")
        plugin.description = request.arguments.get("formtextarea_description",
                                                   "")
        plugin.version = request.arguments.get("formtext_version", "")
        plugin.zindex = "1"

        if "uploader" in request.arguments:
            file = request.arguments.get("uploader", "", castto=Attachment)
            if file:
                plugin.picture = str(uuid4())
                application.storage.write(plugin.picture, file.handler.read())

        plugin.save()
        create_plugin_dir(plugin.guid)

    if "formbutton_upload_plugin" in request.arguments:
        if request.arguments.get("uploader", "", castto=Attachment):
            try:
                file = request.arguments.get("uploader", "", castto=Attachment)
                xml_data = file.handler.read()

                dom = parseString(xml_data)
                node = XMLPlugin(dom)

                if not Plugins.get_by_guid(node.guid):
                    plugin = Plugins()
                    plugin.name = node.name
                    plugin.description = node.description
                    plugin.guid = node.guid
                    plugin.version = node.version
                    plugin.author = node.author
                    plugin.protected = node.protected

                    plugin_picture_name = ""
                    plugin.picture = ""
                    if node.picture:
                        plugin.picture = plugin_picture_name = str(uuid4())
                        application.storage.write(
                            plugin_picture_name,
                            base64.b64decode(node.picture))
                    plugin.save()
                    create_plugin_dir(plugin.guid)

                    for child in node.childs:

                        if child.tag == "timer":
                            child = XMLTimer(child)

                            if child.name:
                                timer = Timer()
                                timer.fill_from_xml(child, node.guid)
                        elif child.tag == "custom_event":
                            child = XMLCustomEvent(child)

                            if child.name:
                                custom_event = CustomEvent()
                                custom_event.fill_from_xml(child, node.guid)
                        elif child.tag == "macro":
                            child = XMLMacros(child)
                            if child.name and child.source:
                                macros = Macros()
                                macros.fill_from_xml(child, node.guid)
                        elif child.tag == "database":
                            child = XMLPluginDB(child)
                            if child.name:
                                DatabaseManager(plugin.guid).import_db(
                                    child.name,
                                    base64.b64decode(child.db_source))
                        elif child.tag == "resource":
                            child = XMLResource(child)

                            if child.name:
                                ResourceFolderManager(plugin.guid).import_res(
                                    child.name,
                                    base64.b64decode(child.res_source))
                        else:
                            raise Exception(
                                lang.get("xml_not_correctr_error",
                                         "xml_not_correctr_error"))
                else:
                    raise Exception(lang.get("plugin_exist", "plugin_exist"))

            except Exception, ex:
                self.growl.title = lang["error"]
                self.growl.text = ex
                self.growl.show = "1"