Пример #1
0
    def delete(self):
        minimap_bin = Binary.get_by_id(self._minimap_id)
        minimap_bin.delete()

        css_bin = Binary.get_by_id(self._css_id)
        css_bin.delete()

        db = Database()
        stmnt = "DELETE FROM SPACES WHERE SPA_SIT_ID = ? ;"
        db.query(stmnt, (self.get_id(),), commit=True)

        stmnt = "DELETE FROM SITES WHERE SIT_ID = ? ;"
        db.query(stmnt, (self.get_id(),), commit=True)
Пример #2
0
    def storeBinary(self, params):
        data = base64.b64decode(params[0])
        filename = str(params[1])

        #TODO: Care about mimetype recognition
        binary = Binary.create(data, "benis/unknown", filename)
        binary.store()
        return binary.get_id()
Пример #3
0
    def create(cls, name, internal_name, description, html_body, html_head, css, minimap=None):
        """
        Creates A Page (normally as a part of the installation process of a Template)
        in Database
        """

        placeholders = re.findall(r"<%[^%>]+%>",html_body)
        placeholders = [p.replace("<%","",1) for p in placeholders]
        placeholders = [p.replace("%>","",1) for p in placeholders]
        placeholders = [p.strip() for p in placeholders]

        if len(placeholders) < 1:
            pass # Eventually we need to check for Pages with no spaces. Not an error yet

        minimap_id = None
        if minimap is not None:
            minimap_binary = Binary.create("image/png", minimap)
            minimap_binary.set_filename(internal_name+"_minimap.png")
            minimap_binary.store()
            minimap_id = minimap_binary.get_id()

        css_binary = binary_manager.create("text/css", css)
        css_binary.set_filename(internal_name+".css")
        css_binary.store()
        css_id = css_binary.get_id()

        stmnt = "INSERT INTO SITES (SIT_ID, SIT_HTML, SIT_HTML_HEAD, SIT_DESCRIPTION, SIT_NAME, SIT_BIN_MINIMAP, SIT_BIN_CSS) \
                 VALUES (?,?,?,?,?,?,?) ;"

        db = Database()
        new_sit_id = db.get_seq_next("SIT_GEN")

        db.query(stmnt , (new_sit_id, html_body, html_head, description, name, minimap_id, css_id), commit=True)

        stmnt_space= "INSERT INTO SPACES (SPA_ID, SPA_SIT_ID, SPA_NAME ) VALUES (?,?,?) ; "
        stmnt_box = "INSERT INTO BOXES (BOX_ID, BOX_SIT_ID, BOX_NAME, BOX_ORIENTATION) VALUES (?,?,?,?) ;"

        for placeholder in placeholders:
            splitted = placeholder.split(":")
            typ = splitted[0]
            name = splitted[1]
            if typ == "space":
                new_space_id = db.get_seq_next("SPA_GEN")
                db.query(stmnt_space, (new_space_id, new_sit_id, name), commit=True )
            elif typ == "vbox" or typ == "hbox":
                new_box_id = db.get_seq_next("BOX_GEN")
                orientation = int(typ == "vbox")
                db.query(stmnt_box, (new_box_id, new_sit_id, name, orientation), commit=True)
Пример #4
0
    def uninstall(self):
        """
        Uninstalls this template
        """
        db = Database()

        for bin_id in self._binaries:
            bin = Binary.get_by_id(bin_id)
            bin.delete()
        stmnt = "DELETE FROM TEMPLATE_BINARIES ;"
        db.query(stmnt, commit=True)
        
        #Destroy Pages
        Page.delete_all_pages()

        #Set Page ID-Generator to 1
        db.set_seq_to('SIT_GEN',1)

        stmnt = "DELETE FROM TEMPLATE_INFO ;"
        db.query(stmnt, commit=True)

        PokeManager.add_activity(ActivityType.TEMPLATE)
Пример #5
0
                                page['desc'],
                                page['html_body'],
                                page['html_head'],
                                page['css'],
                                page['minimap'])    

        #put binary into database
        for bin_filename in os.listdir(temp_installpath+"/static"):
            binary=None
            try:
                bin_file = open(temp_installpath+"/static/"+bin_filename,"rb")
                bin_data = bin_file.read()
                bin_file.close()
                # TODO: Find more generic way to determine mimetype
                if bin_filename.endswith(".png"):
                    binary = Binary.create("image/png", bin_data)
                if bin_filename.endswith(".jpeg") or bin_filename.endswith(".jpg"):
                    binary = Binary.create("image/jpeg", bin_data)
                else:
                    binary = Binary.create("application/octet-stream", bin_data)
                if binary is not None:
                    binary.set_filename(bin_filename)
                    binary.store()

                    new_template.add_binary(binary.get_id())

            except IOError, e:
                errorlog.append({'severity':0,
                               'type':'PageFile',
                               'msg':'File seems broken static/'+bin_filename})
Пример #6
0
 def deleteBinaries(self, params):
     binary_ids = params[0]
     
     Binary.delete_binaries(binary_ids)
     return None
Пример #7
0
 def loadMedia(self, params):
     return Binary.get_binaries_for_gui()
Пример #8
0
 def get_css_filename(self):
     return Binary.get_by_id(self._css_id).get_filename()