Beispiel #1
0
 def create_widget(self, name=""):
     """
     cretes a widget of this module and returns it
     """
     if name == "":
         raise ModuleCoreException(ModuleCoreException.get_msg(10))
     w = Widget(self._core, self)
     w.set_name(name)
     w.store()
Beispiel #2
0
 def download_template(self, nr):
     """
     downloads a template, verifies its signature and returns its data
     """
     result = self._http_call({'c': 9, 'id': int(nr)})
     data = base64.b64decode(result['r'])
     if not self.verify_module(data, result['signature']):
         raise ModuleCoreException(ModuleCoreException.get_msg(3))
     else:
         return data
Beispiel #3
0
    def delete(self):
        """
        deletes this repo from database
        """
        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(4))
        db = self._core.get_db()

        stmnt = "DELETE FROM REPOSITORIES WHERE REP_ID = ? ;"
        db.query(self._core, stmnt, (self._id, ), commit=True)
        self._core.get_poke_manager.add_activity(ActivityType.REPOSITORY)
Beispiel #4
0
 def _http_call(self, msg, timeout=5):
     if self._jsondecoder is None:
         self._jsondecoder = JSONDecoder()
     if self._jsonencoder is None:
         self._jsonencoder = JSONEncoder()
     url = self.get_host() + "?j=" + quote(
         self._jsonencoder.encode(msg).encode('utf-8'))
     try:
         http = urlopen(url, timeout=timeout)
     except URLError:
         raise ModuleCoreException(ModuleCoreException.get_msg(9))
     return self._jsondecoder.decode(http.read())
Beispiel #5
0
 def _get_module_from_widget_id(self, widget_id):
     """
     returns the module that belongs to a widget with the given id
     """
     db = self._core.get_db()
     stmnt = "SELECT WGT_MOD_ID FROM WIDGETS WHERE WGT_ID = ? ;"
     cur = db.query(self._core, stmnt, (widget_id, ))
     row = cur.fetchonemap()
     if row is not None:
         return self.get_module(row["WGT_MOD_ID"])
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(7))
Beispiel #6
0
 def _get_module_id_from_name(self, module_name):
     """
     returns the module id of the given module_name
     """
     module_name = str(module_name)
     db = self._core.get_db()
     stmnt = "SELECT MOD_ID FROM MODULES WHERE MOD_NAME = ? ;"
     cur = db.query(self._core, stmnt, (module_name, ))
     row = cur.fetchonemap()
     if row is not None:
         return int(row["MOD_ID"])
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(6))
Beispiel #7
0
    def get_widget(self, widget_id):
        """
        returns an instance of thre requested module with a set instanceId
        """
        db = self._core.get_db()
        stmnt = "SELECT WGT_ID, WGT_NAME, WGT_VIE_BASEVIEW, WGT_SPA_BASESPACE FROM WIDGETS WHERE WGT_MOD_ID = ? AND WGT_ID = ? ;"
        cur = db.query(self._core, stmnt, (self._id, widget_id))

        row = cur.fetchonemap()
        if row is not None:
            widget = Widget(self._core, self, row["WGT_ID"])
            widget.set_name(row["WGT_NAME"])
            widget.set_baseview_id(row["WGT_VIE_BASEVIEW"])
            widget.set_baseview_space_id(row["WGT_SPA_BASESPACE"])
            return widget
        else:
            raise ModuleCoreException(ModuleCoreException.get_msg(7))
Beispiel #8
0
 def get_module(self, module_id):
     """
     returns an instance of the requested module
     """
     module_id = int(module_id)
     db = self._core.get_db()
     stmnt = "SELECT MOD_NAME, MOD_VERSIONMAJOR, MOD_VERSIONMINOR, MOD_VERSIONREV FROM MODULES WHERE MOD_ID = ? ;"
     cur = db.query(self._core, stmnt, (module_id, ))
     row = cur.fetchonemap()
     if row is not None:
         exec "from %s.v%d_%d_%d import Module as ModuleImplementation" % (
             row["MOD_NAME"], row["MOD_VERSIONMAJOR"],
             row["MOD_VERSIONMINOR"], row["MOD_VERSIONREV"])
         module = ModuleImplementation(self._core)
         module.set_id(module_id)
         return module
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(6))
Beispiel #9
0
    def delete(self):
        db = self._core.get_db()

        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))

        action_manager = self._core.get_action_manager()
        action_manager.delete_actions_with_widget(self)

        view_manager = self._core.get_view_manager()
        view_manager.delete_mappings_with_widget(self)

        css_manager = self._core.get_css_manager()
        css_manager.delete_definitions_with_widget(self)

        stmnt = "DELETE FROM WIDGETS WHERE WGT_ID = ? ;"
        db.query(self._core, stmnt, (self._id, ), commit=True)
        self._core.get_poke_manager().add_activity(ActivityType.WIDGET)
Beispiel #10
0
    def store(self):
        db = self._core.get_db()

        if self._id is None:
            self._id = db.get_seq_next('WGT_GEN')

        if self._module is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(1))

        stmnt = "UPDATE OR INSERT INTO WIDGETS (WGT_ID, WGT_NAME, WGT_SIT_ID, WGT_MOD_ID, WGT_VIE_BASEVIEW, WGT_SPA_BASESPACE) \
                    VALUES (?,?,?,?,?,?) MATCHING (WGT_ID) ;"

        db.query(self._core,
                 stmnt,
                 (self._id, self._name, self._site_id, self._module.get_id(),
                  self._baseview_id, self._baseview_space_id),
                 commit=True)
        self._core.get_poke_manager().add_activity(ActivityType.WIDGET)
Beispiel #11
0
 def create_widget(self, name=""):
     """
     cretes a widget of this module and returns it
     """
     if name=="":
         raise ModuleCoreException(ModuleCoreException.get_msg(10))
     w = Widget(self)
     w.set_name(name)
     w.store()
Beispiel #12
0
 def download_template(self, nr):
     """
     downloads a template, verifies its signature and returns its data
     """
     result = self._http_call({'c':9,'id':int(nr)})
     data = base64.b64decode(result['r'])
     if not self.verify_module(data, result['signature']):
         raise ModuleCoreException(ModuleCoreException.get_msg(3))
     else:
         return data
Beispiel #13
0
    def delete(self):
        """
        deletes this repo from database
        """
        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(4))
        db = Database()

        stmnt = "DELETE FROM REPOSITORIES WHERE REP_ID = ? ;"
        db.query(stmnt,(self._id,),commit=True)
        PokeManager.add_activity(ActivityType.REPOSITORY)
Beispiel #14
0
 def _http_call(self,msg, timeout=5):
     if self._jsondecoder is None:
         self._jsondecoder = JSONDecoder()
     if self._jsonencoder is None:
         self._jsonencoder = JSONEncoder()
     url = self.get_host()
     try:
         http = urlopen(url,timeout=timeout, data="j="+quote(self._jsonencoder.encode(msg).encode('utf-8')))
     except URLError:
         raise ModuleCoreException(ModuleCoreException.get_msg(9))
     return self._jsondecoder.decode(http.read())
Beispiel #15
0
 def _get_module_from_widget_id(cls, widget_id):
     """
     returns the module that belongs to a widget with the given id
     """
     db = Database()
     stmnt = "SELECT WGT_MOD_ID FROM WIDGETS WHERE WGT_ID = ? ;"
     cur = db.query(stmnt,(widget_id,))
     row = cur.fetchonemap()
     if row is not None:
         return cls.get_module(row["WGT_MOD_ID"])
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(7))
Beispiel #16
0
    def download_module(self,module):
        """
        downloads a module and
        returns the data directly!
        """
        if type(module) != dict:
            module = ModuleManager.get_meta_from_module(module)
        result = self._http_call({'c':5,'m':module},timeout=1800)
        if result is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))
        data = base64.b64decode(result["data"])
        if not self.verify_module(data, result["r"]["signature"]):
            raise ModuleCoreException(ModuleCoreException.get_msg(3))

        datapath = "/tmp/"+result["r"]["name"]+"_v"+ \
                                str(result["r"]["version_major"])+"_"+ \
                                str(result["r"]["version_minor"])+"_"+ \
                                str(result["r"]["revision"])+".tar.gz"
        datafile = open(datapath,"w")
        datafile.write(data)
        datafile.close()
        return datapath
Beispiel #17
0
 def _get_module_id_from_name(module_name):
     """
     returns the module id of the given module_name
     """
     module_name = str(module_name)
     db = Database()
     stmnt = "SELECT MOD_ID FROM MODULES WHERE MOD_NAME = ? ;"
     cur = db.query(stmnt,(module_name,))
     row = cur.fetchonemap()
     if row is not None:
         return int(row["MOD_ID"])
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(6))
Beispiel #18
0
    def store(self):
        db = Database()

        if self._id is None:
            self._id = db.get_seq_next('WGT_GEN')

        if self._module is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(1))

        stmnt = "UPDATE OR INSERT INTO WIDGETS (WGT_ID, WGT_NAME, WGT_SIT_ID, WGT_MOD_ID, WGT_VIE_BASEVIEW, WGT_SPA_BASESPACE) \
                    VALUES (?,?,?,?,?,?) MATCHING (WGT_ID) ;"
        db.query(stmnt,(self._id,self._name, self._site_id,self._module.get_id(), self._baseview_id, self._baseview_space_id ),commit=True)
        PokeManager.add_activity(ActivityType.WIDGET)
Beispiel #19
0
    def download_module(self, module):
        """
        downloads a module and
        returns the data directly!
        """
        if type(module) != dict:
            modulemanager = self._core.get_module_manager()
            module = modulemanager.get_meta_from_module(module)
        result = self._http_call({'c': 5, 'm': module}, timeout=1800)
        if result is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))
        data = base64.b64decode(result["data"])
        if not self.verify_module(data, result["r"]["signature"]):
            raise ModuleCoreException(ModuleCoreException.get_msg(3))

        datapath = "/tmp/"+result["r"]["name"]+"_v"+ \
                                str(result["r"]["version_major"])+"_"+ \
                                str(result["r"]["version_minor"])+"_"+ \
                                str(result["r"]["revision"])+".tar.gz"
        datafile = open(datapath, "w")
        datafile.write(data)
        datafile.close()
        return datapath
Beispiel #20
0
 def get_module(module_id):
     """
     returns an instance of the requested module
     """
     module_id = int(module_id)
     db = Database()
     stmnt = "SELECT MOD_NAME, MOD_VERSIONMAJOR, MOD_VERSIONMINOR, MOD_VERSIONREV FROM MODULES WHERE MOD_ID = ? ;"
     cur = db.query(stmnt,(module_id,))
     row = cur.fetchonemap()
     if row is not None:
         exec "from skarphedcore.modules.%s.v%d_%d_%d import Module as ModuleImplementation"%(row["MOD_NAME"], row["MOD_VERSIONMAJOR"], row["MOD_VERSIONMINOR"], row["MOD_VERSIONREV"])
         module = ModuleImplementation() 
         module.set_id(module_id)
         return module
     else:
         raise ModuleCoreException(ModuleCoreException.get_msg(6))
Beispiel #21
0
    def delete(self):
        db = Database()

        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))

        Action.delete_actions_with_widget(self)

        View.delete_mappings_with_widget(self)

        css_manager = CSSManager()
        css_manager.delete_definitions_with_widget(self)

        stmnt = "DELETE FROM WIDGETS WHERE WGT_ID = ? ;"
        db.query(stmnt,(self._id,),commit=True)
        PokeManager.add_activity(ActivityType.WIDGET)
Beispiel #22
0
    def get_widget(self,widget_id):
        """
        returns an instance of thre requested module with a set instanceId
        """
        db = Database()
        stmnt = "SELECT WGT_ID, WGT_NAME, WGT_VIE_BASEVIEW, WGT_SPA_BASESPACE FROM WIDGETS WHERE WGT_MOD_ID = ? AND WGT_ID = ? ;"
        cur = db.query(stmnt, (self._id,widget_id))

        row = cur.fetchonemap()
        if row is not None:
            widget = Widget(self, row["WGT_ID"])
            widget.set_name(row["WGT_NAME"])
            widget.set_baseview_id(row["WGT_VIE_BASEVIEW"])
            widget.set_baseview_space_id(row["WGT_SPA_BASESPACE"])
            return widget
        else:
            raise ModuleCoreException(ModuleCoreException.get_msg(7))
Beispiel #23
0
    def delete(self):
        db = self._core.get_db()

        if self._id is None:
            raise ModuleCoreException(ModuleCoreException.get_msg(2))

        action_manager = self._core.get_action_manager()
        action_manager.delete_actions_with_widget(self)

        view_manager = self._core.get_view_manager()
        view_manager.delete_mappings_with_widget(self)

        css_manager = self._core.get_css_manager()
        css_manager.delete_definitions_with_widget(self)

        stmnt = "DELETE FROM WIDGETS WHERE WGT_ID = ? ;"
        db.query(self._core,stmnt,(self._id,),commit=True)
        self._core.get_poke_manager().add_activity(ActivityType.WIDGET)