Exemple #1
0
				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)
Exemple #2
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"