Exemplo n.º 1
0
    def __createGadget(self, gadgetData, storage):

        metadata = gadgetData['metadata']

        if metadata.has_key('platforms'):
            if (type(metadata['platforms']) is str) or (type(
                    metadata['platforms']) is unicode):
                metadata['platforms'] = [str(metadata['platforms'])]
        else:
            raise Exception('Invalid destination platform list')

        gadgetRelativePath = str(storage.pk)
        gadgetPath = path.join(STORAGE_DIR, gadgetRelativePath)
        if (not path.isdir(gadgetPath)):
            mkdir(gadgetPath)
        else:
            raise Exception('Gadget already exists')

        origin = path.join(GADGET_ZIP_DIR, STORAGE_GADGET_ZIP_NAME)
        gadgetZipFileName = path.join(gadgetPath, STORAGE_GADGET_ZIP_NAME)
        shutil.copyfile(origin, gadgetZipFileName)

        zipFile = zipfile.ZipFile(gadgetZipFileName, 'a')

        directory_name = tempfile.mkdtemp(dir=gadgetPath)

        gadgets = {}
        for platform in metadata['platforms']:
            if platform == 'ezweb':
                templateFileName = str(platform + '.xml')
                htmlFileName = str('index_' + platform + '.html')
                ezWebTemplate = getEzWebTemplate(gadgetData)
                ezWebTemplateFile = open(
                    path.join(directory_name, templateFileName), 'w')
                ezWebTemplateFile.write(ezWebTemplate.encode('utf-8'))
                ezWebTemplateFile.close()
                zipFile.write(ezWebTemplateFile.name,
                              path.join('.', templateFileName))

                if isLocalStorage():
                    ezWebHTML = getEzWebHTML(gadgetData)
                    ezWebHTMLFile = open(
                        path.join(directory_name, htmlFileName), 'w')
                    ezWebHTMLFile.write(ezWebHTML.encode('utf-8'))
                    ezWebHTMLFile.close()
                    zipFile.write(ezWebHTMLFile.name,
                                  path.join('.', htmlFileName))
                    gadgets[platform] = '/'.join(
                        [metadata['gadgetUri'], templateFileName])

            elif platform == 'google':
                templateFileName = str(platform + '.xml')
                googleTemplate = getGoogleTemplate(gadgetData)
                googleTemplateFile = open(
                    path.join(directory_name, templateFileName), 'w')
                googleTemplateFile.write(googleTemplate.encode('utf-8'))
                googleTemplateFile.close()
                zipFile.write(googleTemplateFile.name,
                              path.join('.', templateFileName))
                gadgets[platform] = '/'.join(
                    [metadata['gadgetUri'], templateFileName])

            elif platform == 'player':
                if isLocalStorage():
                    htmlFileName = str(platform + '.html')
                    playerHTML = getPlayerHTML(gadgetData,
                                               metadata['gadgetUri'])
                    playerHTMLFile = open(
                        path.join(directory_name, htmlFileName), 'w')
                    playerHTMLFile.write(playerHTML.encode('utf-8'))
                    playerHTMLFile.close()
                    zipFile.write(playerHTMLFile.name,
                                  path.join('.', htmlFileName))
                    gadgets[platform] = '/'.join(
                        [metadata['gadgetUri'], htmlFileName])

        if isLocalStorage():
            metadata['gadgets'] = gadgets
        else:
            htmlFileName = 'index.html'
            html = getUnboundHTML(gadgetData, metadata['gadgetUri'])
            htmlFile = open(path.join(directory_name, htmlFileName), 'w')
            htmlFile.write(html.encode('utf-8'))
            htmlFile.close()
            zipFile.write(htmlFile.name, path.join('.', htmlFileName))

        #Copying APIs
        for platform in metadata['platforms']:
            if platform != "beemboard":
                apiFileName = str('fastAPI_' + platform + '.js')
                zipFile.write(path.join(GADGET_API_DIR, apiFileName),
                              path.join(API_DIR, apiFileName))

        shutil.rmtree(directory_name)
        zipFile.close()

        metadata['gadgetRelativePath'] = gadgetRelativePath
Exemplo n.º 2
0
    def POST(self):

        try:
            
            parameters = web.input()
            
            if (not parameters.has_key('screens')):
                return web.badrequest()
            screens = parameters.get('screens')
            if (parameters.has_key('gadgeturl')):
                url = urllib.unquote(parameters.get('gadgeturl'))
            else:
                url = "http://piccolo.ls.fi.upm.es/gadgets"           
            if (parameters.has_key('name')):
                name = parameters.get('name')
            else:
                name = "FAST Gadget"
            if (parameters.has_key('vendor')):
                vendor = parameters.get('vendor')
            else:
                vendor = "Morfeo"
            if (parameters.has_key('version')):
                version = parameters.get('version')
            else:
                version = "1.0"
            if (parameters.has_key('info')):
                info = parameters.get('info')
            else:
                info = "Gadget information"
            if (parameters.has_key('author')):
                author = parameters.get('author')
            else:
                author = "author"   
            if (parameters.has_key('email')):
                email = parameters.get('email')
            else:
                email = "*****@*****.**"
            if (parameters.has_key('slots')):
                sls = parameters.get('slots')
            else:
                sls = ""
            if (parameters.has_key('events')):
                evs = parameters.get('events')
            else:
                evs = ""
            
            slots = parseWirings(sls)
            events = parseWirings(evs)

     
            list = screens.split(',')
            
            base = path.dirname(path.abspath(__file__))
            
            html = getEzWebHTML(base, url, name, list, slots, events)
            
            ezWebTemplate = getEzWebTemplate(base, url + '/FASTGadget.html', name, vendor, version, info, author, email, slots, events)

            templateFile = open (base + '/tmp/' + 'template.xml', 'w')
            templateFile.write (ezWebTemplate)
            templateFile.close()
            
            htmlFile = open (base + '/tmp/' + 'FASTGadget.html','w')
            htmlFile.write(html)
            htmlFile.close ()
            
            shutil.copyfile (base + '/gadget_base.zip', base + '/../static/gadget.zip')
            zipFile = zipfile.ZipFile (base + '/../static/gadget.zip','a')
            zipFile.write(base + '/tmp/FASTGadget.html','./FASTGadget.html')
            zipFile.write(base + '/tmp/template.xml','./template.xml')
            zipFile.close()
            web.http.redirect('static/gadget.zip')
        except Exception, e:
            web.ctx.status = "500 Internal Server Error"
            web.ctx.headers = [('Content-Type', 'text/html')]
            web.ctx.output = "Message not sent: %s." % e
Exemplo n.º 3
0
    def POST(self):

        try:
            
            parameters = web.input()
            
            if (not parameters.has_key('storeScreens')):
                return web.badrequest()
            screens = parameters.get('storeScreens')
            if (parameters.has_key('name')):
                name = parameters.get('name')
            else:
                name = "FAST Gadget"
            if (parameters.has_key('vendor')):
                vendor = parameters.get('vendor')
            else:
                vendor = "Morfeo"
            if (parameters.has_key('version')):
                version = parameters.get('version')
            else:
                version = "1.0"
            if (parameters.has_key('info')):
                info = parameters.get('info')
            else:
                info = "Gadget information"
            if (parameters.has_key('author')):
                author = parameters.get('author')
            else:
                author = "author"   
            if (parameters.has_key('email')):
                email = parameters.get('email')
            else:
                email = "*****@*****.**"  
            if (parameters.has_key('storeSlots')):
                sls = parameters.get('storeSlots')
            else:
                sls = ""
            if (parameters.has_key('storeEvents')):
                evs = parameters.get('storeEvents')
            else:
                evs = ""
            
            slots = parseWirings(sls)
            events = parseWirings(evs)
        
            base = path.dirname(path.abspath(__file__))
            
            gadget_name = (vendor + '-' + name + '-' + version).replace(' ', '_')
            
            gadget_path = base + '/../static/' + gadget_name + '/'
            
            if not path.isdir(gadget_path):
                mkdir(gadget_path)
            else:
                raise Exception ('Gadget already exists')
                      
            list = screens.split(',')
            
            #base_uri = web.ctx.homedomain + '/static'
            #FIXME
            base_uri = 'http://piccolo.ls.fi.upm.es/fastservice/static'
            url_path = base_uri + '/'+gadget_name
            html_uri = base_uri + '/'+gadget_name+'/' + gadget_name + '.html'
            template_uri = base_uri + '/'+gadget_name+'/' + gadget_name + '.xml'
            
            ezWebTemplate = getEzWebTemplate(base, html_uri, name, vendor, version, info, author, email, slots, events)
            templateFile = open (gadget_path + gadget_name + '.xml', 'w')
            templateFile.write (ezWebTemplate)
            templateFile.close()
            
            html = getEzWebHTML(base, url_path, name, list, slots, events)
            htmlFile = open (gadget_path + gadget_name + '.html','w')
            htmlFile.write(html)
            htmlFile.close()
            
            un = unzip.unzip()
            un.extract(base + '/gadget_base.zip', gadget_path)
            web.ctx.headers = [('Content-Type', 'text/html')]
            web.ctx.output =  getDeploymentHTML(base, template_uri)

            return 
        except Exception, e:
            web.ctx.status = "500 Internal Server Error"
            web.ctx.headers = [('Content-Type', 'text/plain')]
            web.ctx.output = e.message
Exemplo n.º 4
0
    def __createGadget(self, gadgetData, storage):

        metadata = gadgetData['metadata']

        if metadata.has_key('platforms'):
            if (type(metadata['platforms']) is str) or (type(metadata['platforms']) is unicode):
                metadata['platforms'] = [str(metadata['platforms'])]
        else:
            raise Exception('Invalid destination platform list')

        gadgetRelativePath = str(storage.pk)
        gadgetPath = path.join(STORAGE_DIR, gadgetRelativePath)
        if (not path.isdir(gadgetPath)):
            mkdir(gadgetPath)
        else:
            raise Exception ('Gadget already exists')

        origin = path.join(GADGET_ZIP_DIR, STORAGE_GADGET_ZIP_NAME)
        gadgetZipFileName = path.join(gadgetPath, STORAGE_GADGET_ZIP_NAME)
        shutil.copyfile (origin, gadgetZipFileName)

        zipFile = zipfile.ZipFile(gadgetZipFileName,'a')

        directory_name = tempfile.mkdtemp(dir=gadgetPath)

        gadgets = {}
        for platform in metadata['platforms']:
            if platform == 'ezweb':
                templateFileName = str(platform + '.xml')
                htmlFileName = str('index_' + platform + '.html')
                ezWebTemplate = getEzWebTemplate(gadgetData)
                ezWebTemplateFile = open (path.join(directory_name, templateFileName), 'w')
                ezWebTemplateFile.write(ezWebTemplate.encode('utf-8'))
                ezWebTemplateFile.close()
                zipFile.write(ezWebTemplateFile.name, path.join('.', templateFileName))

                if isLocalStorage():
                    ezWebHTML = getEzWebHTML(gadgetData)
                    ezWebHTMLFile = open (path.join(directory_name, htmlFileName), 'w')
                    ezWebHTMLFile.write(ezWebHTML.encode('utf-8'))
                    ezWebHTMLFile.close()
                    zipFile.write(ezWebHTMLFile.name, path.join('.', htmlFileName))
                    gadgets[platform] = '/'.join([metadata['gadgetUri'],  templateFileName])

            elif platform == 'google':
                templateFileName = str(platform + '.xml')
                googleTemplate = getGoogleTemplate(gadgetData)
                googleTemplateFile = open (path.join(directory_name, templateFileName), 'w')
                googleTemplateFile.write(googleTemplate.encode('utf-8'))
                googleTemplateFile.close()
                zipFile.write(googleTemplateFile.name,path.join('.', templateFileName))
                gadgets[platform] = '/'.join([metadata['gadgetUri'], templateFileName])

            elif platform == 'player':
                if isLocalStorage():
                    htmlFileName = str(platform + '.html')
                    playerHTML = getPlayerHTML(gadgetData, metadata['gadgetUri'])
                    playerHTMLFile = open (path.join(directory_name, htmlFileName), 'w')
                    playerHTMLFile.write(playerHTML.encode('utf-8'))
                    playerHTMLFile.close()
                    zipFile.write(playerHTMLFile.name, path.join('.', htmlFileName))
                    gadgets[platform] = '/'.join([metadata['gadgetUri'], htmlFileName])

        if isLocalStorage():
            metadata['gadgets'] = gadgets
        else:
            htmlFileName = 'index.html'
            html = getUnboundHTML(gadgetData, metadata['gadgetUri'])
            htmlFile = open (path.join(directory_name, htmlFileName), 'w')
            htmlFile.write(html.encode('utf-8'))
            htmlFile.close()
            zipFile.write(htmlFile.name, path.join('.', htmlFileName))

        #Copying APIs
        for platform in metadata['platforms']:
            if platform != "beemboard":
                apiFileName = str('fastAPI_' + platform + '.js')
                zipFile.write(path.join(GADGET_API_DIR, apiFileName), path.join(API_DIR, apiFileName))

        shutil.rmtree(directory_name)
        zipFile.close()


        metadata['gadgetRelativePath'] = gadgetRelativePath