Ejemplo n.º 1
0
 def unregisterResource(self, dimdimID, resourceID):
     
     meeting  = self.getMeeting(dimdimID)
     resource = self.getResourceByID(dimdimID, resourceID)
     if not resource:
         return
     
     resourceList = meeting.get('resources')
     regularList = resourceList.get('regular')
     preloadedList = resourceList.get('preloaded')
     
     self.stateLock.acquire()        
     if meeting.get('currentResource') == resourceID:
         meeting.update({'currentResource' : None})        
     if regularList.has_key(resourceID):
         regularList.pop(resourceID)
         resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'regular'), resourceID)
     else:
         preloadedList.pop(resourceID)
         resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'preloaded'), resourceID)        
     try:
         shutil.rmtree(resourcePath)
     except:
         pass        
     self.stateLock.release()
     
     self.exportStateMachine(dimdimID)
     return
Ejemplo n.º 2
0
    def unregisterResource(self, dimdimID, resourceID):

        meeting = self.getMeeting(dimdimID)
        resource = self.getResourceByID(dimdimID, resourceID)
        if not resource:
            return

        resourceList = meeting.get('resources')
        regularList = resourceList.get('regular')
        preloadedList = resourceList.get('preloaded')

        self.stateLock.acquire()
        if meeting.get('currentResource') == resourceID:
            meeting.update({'currentResource': None})
        if regularList.has_key(resourceID):
            regularList.pop(resourceID)
            resourcePath = os.path.join(
                os.path.join(os.path.join(osconfig.cobArchive(), dimdimID),
                             'regular'), resourceID)
        else:
            preloadedList.pop(resourceID)
            resourcePath = os.path.join(
                os.path.join(os.path.join(osconfig.cobArchive(), dimdimID),
                             'preloaded'), resourceID)
        try:
            shutil.rmtree(resourcePath)
        except:
            pass
        self.stateLock.release()

        self.exportStateMachine(dimdimID)
        return
Ejemplo n.º 3
0
 def bookmarkCurrentPage(self, dimdimID, newResourceID):
     
     meeting = self.getMeeting(dimdimID)
     resourceList = meeting.get('resources')
     
     currentResourceID = meeting.get('currentResource')
     currentResourceCopy = self.getCurrentResource(dimdimID)
     currentResourceType = self.getResourceType(dimdimID, currentResourceID)
     
     currentPageNum = currentResourceCopy.get('currentPage')
     currentPageCopy = self.getCurrentPage(dimdimID)
     
     newResource = {'currentPage':0, 'lastPage':0, 'pages': {0:currentPageCopy}}
     
     sourcePath = os.path.join(os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), \
                                            currentResourceType), currentResourceID), str(currentPageNum))
     destPath = os.path.join(os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), \
                                            currentResourceType), newResourceID), '0')
     try:
         shutil.rmtree(destPath)
     except:
         pass
     
     dir_util.copy_tree(sourcePath, destPath)
     typeList = resourceList.get(currentResourceType)
     
     self.stateLock.acquire()
     typeList.update({newResourceID : newResource})
     self.exportStateMachine(dimdimID)
     self.stateLock.release()
     
     return
Ejemplo n.º 4
0
    def trimResourceToCurrentPage(self, dimdimID):
        # this needs to be used if the user goes back to a previous page
        # and then decides moves to a different page, it would all later pages invalid
        # so before letting him move on, we cleanup all pages > currentPage

        # this is only ever required on the current shared resource.

        meeting = self.getMeeting(dimdimID)
        resource = self.getCurrentResource(dimdimID)
        resourceID = meeting.get('currentResource')
        lastPage = resource.get('lastPage')
        currentPage = resource.get('currentPage')

        pageList = resource.get('pages')

        for pageNum in range(currentPage + 1, lastPage + 1):
            pageList.pop(pageNum)
            resourcePath = os.path.join(
                os.path.join(os.path.join(osconfig.cobArchive(), dimdimID),
                             self.getResourceType(dimdimID, resourceID)),
                resourceID)
            pagePath = os.path.join(resourcePath, str(pageNum))
            try:
                shutil.rmtree(pagePath)
            except:
                pass

        resource.update({'lastPage': currentPage})
        self.exportStateMachine(dimdimID)
        return
Ejemplo n.º 5
0
 def syncToPresenterContext(self, dimdimID, roomID, sessionID, pageNum = -1):
     
     # Presenter is a bit tricky.
     # pageNum parameter basically suggests that
     # it is the last known good configuration for the presenter.
     # so trim any resources till pageNum and then
     # sync to pageNum
     
     meeting = self.stateEngine.getMeeting(dimdimID)
     if not meeting:
         response = self.jsonObj.encode({'result':False})
         return response.encode()
     resource = self.stateEngine.getCurrentResource(dimdimID)
     if (pageNum > -1):
         if resource.get('lastPage') >= pageNum:
             resource.update({'currentPage' : pageNum})
             self.stateEngine.trimResourceToCurrentPage(dimdimID)
     
     # prepare presenter cache with current state
     resourceID = meeting.get('currentResource')
     resourceType = self.stateEngine.getCurrentResourceType(dimdimID)
     currentPageNum = resource.get('currentPage')
     
     # prepare cache
     presenterLocation = resourceType + '/' + resourceID + '/' + str(currentPageNum) + '/presenter/content.html'
     presenterCache = string.replace(self.presenterCacheBuffer, 'DIMDIMSL_COB_CONTENT_SRC', presenterLocation)
     
     pCacheLocation = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'p_cache.html')
     pCacheHandle = open(pCacheLocation, 'wb')
     pCacheHandle.write(presenterCache)
     pCacheHandle.close()
     
     response = self.jsonObj.encode({'result' : True, 'pageNum' : currentPageNum, 'location' : '/content/' + str(dimdimID) + '/p_cache.html'})
     return response.encode()
Ejemplo n.º 6
0
 def registerMeeting(self, dimdimID, bookmarkAction):
     # FORMAT: {dimdimID: {bmAction: bookmarkAction, currentResource: resourceID, locked : False, resources : {RESOURCEDICT}}}
     ## bmAction is required for bookmarking functionality. stateMachine doesn't care what the action is.
     ## The caller should make sure it is valid and handle it appropriately.
     ## Default Values : currentResource : None, locked : False, resources : {'regular':{}, 'preloaded':{}}
     
     # NOTE: registerMeeting is for external usage only. importStateEngine shouldn't use registerMeeting
     # If there is a meeting that is already registered, registerMeeting ignores any further registrations
     
     if self.getMeeting(dimdimID):
         return
     
     meetingPath = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID))
     if os.path.isdir(meetingPath):
         try:
             shutil.rmtree(meetingPath)
         except:
             pass            
     os.makedirs(meetingPath)
     
     self.stateLock.acquire()        
     meeting = {dimdimID : {'bmAction' : bookmarkAction, 'currentResource' : None, 'locked' : False, 'resources' : {'regular':{}, 'preloaded':{}}}}
     self.stateMachine.update(meeting)        
     self.stateLock.release()
     
     self.exportStateMachine(dimdimID)
     logManager.log('meeting ' + dimdimID + ' registered', logging.INFO)
     return
Ejemplo n.º 7
0
 def trimResourceToCurrentPage(self, dimdimID):
     # this needs to be used if the user goes back to a previous page
     # and then decides moves to a different page, it would all later pages invalid
     # so before letting him move on, we cleanup all pages > currentPage
     
     # this is only ever required on the current shared resource.
     
     meeting = self.getMeeting(dimdimID)
     resource = self.getCurrentResource(dimdimID)
     resourceID = meeting.get('currentResource')
     lastPage = resource.get('lastPage')
     currentPage = resource.get('currentPage')
     
     pageList = resource.get('pages')
     
     for pageNum in range(currentPage + 1, lastPage + 1):
         pageList.pop(pageNum)
         resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), self.getResourceType(dimdimID, resourceID)), resourceID)
         pagePath = os.path.join(resourcePath, str(pageNum))
         try:
             shutil.rmtree(pagePath)
         except:
             pass
     
     resource.update({'lastPage' : currentPage})
     self.exportStateMachine(dimdimID)
     return
Ejemplo n.º 8
0
    def handleMeetingClose(self, dimdimID):
        # when a meeting closes, all 'regular' resources
        # should be cleaned up both from the disk and the stateMachine

        logManager.log('meeting ' + dimdimID + ' is getting closed',
                       logging.INFO)

        meeting = self.getMeeting(dimdimID)
        if not meeting:
            return

        resourceList = meeting.get('resources')
        preloadedList = resourceList.get('preloaded')
        if len(preloadedList) == 0:
            # get rid of the entire meeting record
            self.unregisterMeeting(dimdimID)
            try:
                # get rid of meta data
                os.remove(
                    os.path.join(
                        os.path.join(osconfig.cobArchive(), 'META-INF'),
                        dimdimID))
            except:
                pass
            try:
                # get rid of the files
                shutil.rmtree(os.path.join(osconfig.cobArchive(), dimdimID))
            except:
                pass
            return

        self.stateLock.acquire()
        resourceList.update({'regular': {}})
        self.stateLock.release()

        try:
            # delete the 'regular' folder
            shutil.rmtree(
                os.path.join(os.path.join(osconfig.cobArchive(), dimdimID),
                             'regular'))
        except:
            pass

        self.exportStateMachine(dimdimID)
        return
Ejemplo n.º 9
0
 def __init__(self):
 
     self.jsonObj = demjson.JSON()
     self.curlHandle = CurlWrapper()
     self.stateEngine = sl_stateMachine()
     
     # fill up cache buffer
     presenterCacheHandle = open(os.path.join(osconfig.cobArchive(), 'presenter.template'), 'r')
     self.presenterCacheBuffer = presenterCacheHandle.read()
     presenterCacheHandle.close()
     
     attendeeCacheHandle = open(os.path.join(osconfig.cobArchive(), 'attendee.template'), 'r')
     self.attendeeCacheBuffer = attendeeCacheHandle.read()
     attendeeCacheHandle.close()
     
     self.presenterCacheBuffer = string.replace(self.presenterCacheBuffer, 'DIMDIMSL_SCRIPTSERVER_URL', osconfig.scriptServerURL())
     self.attendeeCacheBuffer = string.replace(self.attendeeCacheBuffer, 'DIMDIMSL_SCRIPTSERVER_URL', osconfig.scriptServerURL())
     
     return
Ejemplo n.º 10
0
 def syncToResource(self, dimdimID, roomID, sessionID, resourceID, returnType):
     
     # navigate to the given resource first
     self.stateEngine.navigateToResource(dimdimID, resourceID)
     self.stateEngine.resetCurrentResource(dimdimID)
     self.stateEngine.trimResourceToCurrentPage(dimdimID)
     
     # prepare attendee and presenter cache with current state
     resource = self.stateEngine.getCurrentResource(dimdimID)
     resourceType = self.stateEngine.getCurrentResourceType(dimdimID)
     
     currentPageNum = resource.get('currentPage')
     
     # prepare cache
     presenterLocation = resourceType + '/' + resourceID + '/' + str(currentPageNum) + '/presenter/content.html'
     presenterCache = string.replace(self.presenterCacheBuffer, 'DIMDIMSL_COB_CONTENT_SRC', presenterLocation)
     
     attendeeLocation = resourceType + '/' + resourceID + '/' + str(currentPageNum) + '/attendee/content.html'
     attendeeCache = string.replace(self.attendeeCacheBuffer, 'DIMDIMSL_COB_CONTENT_SRC', attendeeLocation)
     
     pCacheLocation = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'p_cache.html')
     pCacheHandle = open(pCacheLocation, 'wb')
     pCacheHandle.write(presenterCache)
     pCacheHandle.close()
     
     aCacheLocation = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'a_cache.html')
     aCacheHandle = open(aCacheLocation, 'wb')
     aCacheHandle.write(attendeeCache)
     aCacheHandle.close()
     
     if returnType == 'method':
         return 'cobCallback(\''+str(dimdimID) + '\')'
     
     jsonSuccess = jsonObject()
     jsonSuccess.clearResponse()
     jsonSuccess.add('result', 'true')
     jsonSuccess.add('method', 'syncToURLResource')
     jsonSuccess.add('error', '7200')
     jsonSuccess.add('location', '/content/' + str(dimdimID))
     
     logManager.log('Meeting ' + dimdimID + ' synced to resource ' + resourceID, logging.INFO)
     
     return jsonSuccess.jsonResponse()
Ejemplo n.º 11
0
 def exportStateMachine(self, dimdimID):
     
     metaDir = os.path.join(osconfig.cobArchive(), 'META-INF')
     if not os.path.isdir(metaDir):
         os.makedirs(metaDir)
     metaFileLocation = os.path.join(metaDir, dimdimID)
     meeting = self.getMeeting(dimdimID)
     metaFileHandle = open(metaFileLocation, 'wb')
     metaFileHandle.write(self.jsonObj.encode(meeting))
     metaFileHandle.close()
     return    
Ejemplo n.º 12
0
    def exportStateMachine(self, dimdimID):

        metaDir = os.path.join(osconfig.cobArchive(), 'META-INF')
        if not os.path.isdir(metaDir):
            os.makedirs(metaDir)
        metaFileLocation = os.path.join(metaDir, dimdimID)
        meeting = self.getMeeting(dimdimID)
        metaFileHandle = open(metaFileLocation, 'wb')
        metaFileHandle.write(self.jsonObj.encode(meeting))
        metaFileHandle.close()
        return
Ejemplo n.º 13
0
    def handleMeetingClose(self, dimdimID):
        # when a meeting closes, all 'regular' resources
        # should be cleaned up both from the disk and the stateMachine
        
        logManager.log('meeting ' + dimdimID + ' is getting closed', logging.INFO)
        
        meeting = self.getMeeting(dimdimID)
        if not meeting:
            return
        
        resourceList = meeting.get('resources')
        preloadedList = resourceList.get('preloaded')
        if len(preloadedList) == 0:
            # get rid of the entire meeting record
            self.unregisterMeeting(dimdimID)
            try:
                # get rid of meta data
                os.remove(os.path.join(os.path.join(osconfig.cobArchive(), 'META-INF'), dimdimID))
            except:
                pass
            try:
                # get rid of the files
                shutil.rmtree(os.path.join(osconfig.cobArchive(), dimdimID))
            except:
                pass
            return
        
        self.stateLock.acquire()
        resourceList.update({'regular':{}})
        self.stateLock.release()
        
        try:
            # delete the 'regular' folder
            shutil.rmtree(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'regular'))
        except:
            pass

        self.exportStateMachine(dimdimID)
        return
Ejemplo n.º 14
0
    def bookmarkCurrentPage(self, dimdimID, newResourceID):

        meeting = self.getMeeting(dimdimID)
        resourceList = meeting.get('resources')

        currentResourceID = meeting.get('currentResource')
        currentResourceCopy = self.getCurrentResource(dimdimID)
        currentResourceType = self.getResourceType(dimdimID, currentResourceID)

        currentPageNum = currentResourceCopy.get('currentPage')
        currentPageCopy = self.getCurrentPage(dimdimID)

        newResource = {
            'currentPage': 0,
            'lastPage': 0,
            'pages': {
                0: currentPageCopy
            }
        }

        sourcePath = os.path.join(os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), \
                                               currentResourceType), currentResourceID), str(currentPageNum))
        destPath = os.path.join(os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), \
                                               currentResourceType), newResourceID), '0')
        try:
            shutil.rmtree(destPath)
        except:
            pass

        dir_util.copy_tree(sourcePath, destPath)
        typeList = resourceList.get(currentResourceType)

        self.stateLock.acquire()
        typeList.update({newResourceID: newResource})
        self.exportStateMachine(dimdimID)
        self.stateLock.release()

        return
Ejemplo n.º 15
0
 def importStateMachine(self):
     
     metaDir = os.path.join(osconfig.cobArchive(), 'META-INF')
     if not os.path.isdir(metaDir):
         return
     dimdimIDList = os.listdir(metaDir)
     for dimdimID in dimdimIDList:
         try:
             logManager.log('Detected meeting ' + dimdimID, logging.INFO)
             metaFileLocation = os.path.join(metaDir, dimdimID)
             metaFileHandle = open(metaFileLocation, 'rb')
             meeting = self.jsonObj.decode(metaFileHandle.read())
             metaFileHandle.close()
             self.stateMachine.update({dimdimID : meeting})
         except:
             logManager.log('Exception in importing state information of meeting ' + dimdimID, logging.WARN)    
             pass
     return
Ejemplo n.º 16
0
    def importStateMachine(self):

        metaDir = os.path.join(osconfig.cobArchive(), 'META-INF')
        if not os.path.isdir(metaDir):
            return
        dimdimIDList = os.listdir(metaDir)
        for dimdimID in dimdimIDList:
            try:
                logManager.log('Detected meeting ' + dimdimID, logging.INFO)
                metaFileLocation = os.path.join(metaDir, dimdimID)
                metaFileHandle = open(metaFileLocation, 'rb')
                meeting = self.jsonObj.decode(metaFileHandle.read())
                metaFileHandle.close()
                self.stateMachine.update({dimdimID: meeting})
            except:
                logManager.log(
                    'Exception in importing state information of meeting ' +
                    dimdimID, logging.WARN)
                pass
        return
Ejemplo n.º 17
0
    def registerMeeting(self, dimdimID, bookmarkAction):
        # FORMAT: {dimdimID: {bmAction: bookmarkAction, currentResource: resourceID, locked : False, resources : {RESOURCEDICT}}}
        ## bmAction is required for bookmarking functionality. stateMachine doesn't care what the action is.
        ## The caller should make sure it is valid and handle it appropriately.
        ## Default Values : currentResource : None, locked : False, resources : {'regular':{}, 'preloaded':{}}

        # NOTE: registerMeeting is for external usage only. importStateEngine shouldn't use registerMeeting
        # If there is a meeting that is already registered, registerMeeting ignores any further registrations

        if self.getMeeting(dimdimID):
            return

        meetingPath = os.path.join(
            os.path.join(osconfig.cobArchive(), dimdimID))
        if os.path.isdir(meetingPath):
            try:
                shutil.rmtree(meetingPath)
            except:
                pass
        os.makedirs(meetingPath)

        self.stateLock.acquire()
        meeting = {
            dimdimID: {
                'bmAction': bookmarkAction,
                'currentResource': None,
                'locked': False,
                'resources': {
                    'regular': {},
                    'preloaded': {}
                }
            }
        }
        self.stateMachine.update(meeting)
        self.stateLock.release()

        self.exportStateMachine(dimdimID)
        logManager.log('meeting ' + dimdimID + ' registered', logging.INFO)
        return
Ejemplo n.º 18
0
    def formSubmit(self, paramDict):
        
        dimdimID = paramDict.pop('dimdimsl_dimdimID')
        roomID = paramDict.pop('dimdimsl_roomID')
        sessionID = paramDict.pop('dimdimsl_sessionID')
        method = paramDict.pop('dimdimsl_method')
        action = paramDict.pop('dimdimsl_action')
        
        
        originalAction = urllib.unquote(action)
        page = self.stateEngine.getCurrentPage(dimdimID)
        currentBaseURL = self.baseURL(page.get('url'))
        baseURL = self.baseURL(originalAction)
        
        if string.find(originalAction, osconfig.serverURL()) >= 0:
            # some pages don't have base injected (e.g. youtube)
            # these pages might give out relative links which
            # assume osconfig.serverURL() as the base URL.
            originalAction = string.lstrip(originalAction, osconfig.serverURL())
            
        # it is possible that originalAction isn't an absolute link
        if string.find(originalAction, 'http://') != 0:
            # the only way originalAction isn't an absolute link is if
            # it belongs to the existing server. so we can
            # safely set baseURL to existing currentBaseURL
            baseURL = currentBaseURL
            originalAction = urlparse.urljoin(baseURL, originalAction)
            action = urllib.quote(originalAction)
    
        meeting = self.stateEngine.getMeeting(dimdimID)
        resourceID = meeting.get('currentResource')
        resource = self.stateEngine.getCurrentResource(dimdimID)
        lastPageNum = resource.get('lastPage')
        currentPageNum = resource.get('currentPage')
        if (currentPageNum != lastPageNum):
            self.stateEngine.trimResourceToCurrentPage(dimdimID)
            
        resourceType = self.stateEngine.getResourceType(dimdimID, resourceID)
        currentPageNum = currentPageNum + 1
        
        # just create the page and return its location
        
        resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), resourceType), resourceID)
        pagePath = os.path.join(resourcePath, str(currentPageNum))
        presenterPagePath = os.path.join(pagePath, 'presenter')
        attendeePagePath = os.path.join(pagePath, 'attendee')
        
        if not os.path.isdir(presenterPagePath):
            os.makedirs(presenterPagePath)
        if not os.path.isdir(attendeePagePath):
            os.makedirs(attendeePagePath)
        
        tempStore = os.path.join(resourcePath, 'temp.html')
        try:
            os.remove(tempStore)
        except:
            pass
        
        retval = self.curlHandle.downloadToFileFromHTTPFormSubmit(action, method, paramDict, tempStore)
        if len(retval) < 3:
            try:
                os.remove(tempStore)
            except:
                pass
            try:
                shutil.rmtree(pagePath)
            except:
                pass

            response = self.jsonObj.encode({'result' : False, 'error' : 7500})
            return response.encode()
        
        if originalAction != retval:
            # must be a 302. this is our new URL
            originalAction = retval
            baseURL = self.baseURL(originalAction)
            encodedURL = urllib.quote(originalAction)
        
        htmlHandle = open(tempStore, 'r')
        htmlContent = htmlHandle.read()
        htmlHandle.close()
        
        # inject baseURL and jquery.noConflict
        # TODO - WHAT IF BASE URL IS ALREADY THERE ??
        htmlContent = contentMgr.sanitizeHTML(htmlContent, baseURL)
        
        self.prepareHtml(originalAction, htmlContent, presenterPagePath, attendeePagePath)
     
        try:
            os.remove(tempStore)
        except:
            pass
        
        # add this page to the stateMachine
        self.stateEngine.registerPage(dimdimID, originalAction)
        resource = self.stateEngine.getCurrentResource(dimdimID)
        lastPage = resource.get('lastPage')
        response = self.jsonObj.encode({'result' : True, 'lastPage' : str(lastPage), 'currentPage' : str(currentPageNum), 'error' : 7200})
        return response.encode()
Ejemplo n.º 19
0
 def navigateToURL(self, dimdimID, roomID, sessionID, encodedURL):
     
     # navigateToURL is called only from within a page.
     # so this is always for the 'current' resourceID
         
     originalURL = urllib.unquote(encodedURL)
     page = self.stateEngine.getCurrentPage(dimdimID)
     currentBaseURL = self.baseURL(page.get('url'))
     baseURL = self.baseURL(originalURL)
     
     if string.find(originalURL, osconfig.serverURL()) >= 0:
         # some pages don't have base injected (e.g. youtube)
         # these pages might give out relative links which
         # assume osconfig.serverURL() as the base URL.
         originalURL = string.lstrip(originalURL, osconfig.serverURL())
     
     # it is possible that originalURL isn't an absolute link
     if string.find(originalURL, 'http://') != 0:
         # the only way originalURL isn't an absolute link is if
         # it belongs to the existing server. so we can
         # safely set baseURL to existing currentBaseURL
         baseURL = currentBaseURL
         originalURL = urlparse.urljoin(baseURL, originalURL)
         encodedURL = urllib.quote(originalURL)
     
     meeting = self.stateEngine.getMeeting(dimdimID)
     resourceID = meeting.get('currentResource')
     resource = self.stateEngine.getCurrentResource(dimdimID)
     lastPageNum = resource.get('lastPage')
     currentPageNum = resource.get('currentPage')
     if (currentPageNum != lastPageNum):
         self.stateEngine.trimResourceToCurrentPage(dimdimID)
         
     resourceType = self.stateEngine.getResourceType(dimdimID, resourceID)
     currentPageNum = currentPageNum + 1
     
     # just create the page and return its location
     
     resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), resourceType), resourceID)
     pagePath = os.path.join(resourcePath, str(currentPageNum))
     presenterPagePath = os.path.join(pagePath, 'presenter')
     attendeePagePath = os.path.join(pagePath, 'attendee')
     
     if not os.path.isdir(presenterPagePath):
         os.makedirs(presenterPagePath)
     if not os.path.isdir(attendeePagePath):
         os.makedirs(attendeePagePath)
     
     tempStore = os.path.join(resourcePath, 'temp.html')
     try:
         os.remove(tempStore)
     except:
         pass
     
     retval = self.curlHandle.downloadToFileFromHTTPURL(encodedURL, tempStore)
     if len(retval) < 3:
         try:
             os.remove(tempStore)
         except:
             pass
         try:
             shutil.rmtree(pagePath)
         except:
             pass
             
         response = self.jsonObj.encode({'result' : False, 'error' : 7500})
         return response.encode()
     
     if originalURL != retval:
         # must be a 302. this is our new URL
         originalURL = retval
         baseURL = self.baseURL(originalURL)
         encodedURL = urllib.quote(originalURL)
         
     htmlHandle = open(tempStore, 'r')
     htmlContent = htmlHandle.read()
     htmlHandle.close()
     
     htmlContent = contentMgr.sanitizeHTML(htmlContent, baseURL)
     self.prepareHtml(originalURL, htmlContent, presenterPagePath, attendeePagePath)
     
     try:
         os.remove(tempStore)
     except:
         pass
     
     # add this page to the stateMachine
     self.stateEngine.registerPage(dimdimID, originalURL)
     resource = self.stateEngine.getCurrentResource(dimdimID)
     lastPage = resource.get('lastPage')
     response = self.jsonObj.encode({'result' : True, 'lastPage' : str(lastPage), 'currentPage' : str(currentPageNum), 'error' : 7200})
     return response.encode()
Ejemplo n.º 20
0
 def createURLResource(self, dimdimID, roomID, sessionID, encodedURL, resourceID = '_default', resourceType = 'regular'):
     
     # createURLResource is only called for a fresh resource
     
     jsonError = jsonObject()
     jsonError.clearResponse()
     jsonError.add('result', 'false')
     jsonError.add('method', 'cacheURL')
     jsonError.add('error', '7500')
     
     meeting = self.stateEngine.getMeeting(dimdimID)
     if not meeting:
         # register the meeting first
         # ideally, this call should never come..
         # meeting should be registered in listURLResources
         logManager.log('Detected that meeting ' + dimdimID + ' was never registered. This could mean that listURLResources was not called', logging.WARN)
         self.stateEngine.registerMeeting(dimdimID, '')
         self.stateEngine.registerMeeting(dimdimID, 'http://webmeeting.dimdim.com:80/dimdim/BookmarkCobResource.action')
         #return jsonError.jsonResponse()
     
     if resourceType != 'regular':
         resourceType = 'preloaded'
         
     if resourceID == '_default':
         resourceType = 'regular'    # can't have preloaded resources with _default
         
     originalURL = urllib.unquote(encodedURL)
     baseURL = self.baseURL(originalURL)
     
     pageNum = '0'       # duh! this is a new resource
     
     resourcePath = os.path.join(os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), resourceType), resourceID)
     presenterPagePath = os.path.join(os.path.join(resourcePath, pageNum), 'presenter')
     attendeePagePath = os.path.join(os.path.join(resourcePath, pageNum), 'attendee')
     
     if not os.path.isdir(presenterPagePath):
         os.makedirs(presenterPagePath)
     if not os.path.isdir(attendeePagePath):
         os.makedirs(attendeePagePath)
     
     tempStore = os.path.join(resourcePath, 'temp.html')
     try:
         os.remove(tempStore)
     except:
         pass
     
     retval = self.curlHandle.downloadToFileFromHTTPURL(encodedURL, tempStore)
     
     if len(retval) < 3:
         try:
             shutil.rmtree(presenterPagePath)
             shutil.rmtree(attendeePagePath)
             os.remove(tempStore)
         except:
             pass
         return jsonError.jsonResponse()
     
     if originalURL != retval:
         # must be a 302. this is our new URL
         originalURL = retval
         baseURL = self.baseURL(originalURL)
         encodedURL = urllib.quote(originalURL)
         
     htmlHandle = open(tempStore, 'r')
     htmlContent = htmlHandle.read()
     htmlHandle.close()
     
     # inject baseURL
     htmlContent = contentMgr.sanitizeHTML(htmlContent, baseURL)
     self.prepareHtml(originalURL, htmlContent, presenterPagePath, attendeePagePath)
     
     # prepare cache
     presenterLocation = resourceType + '/' + resourceID + '/' + pageNum + '/presenter/content.html'
     presenterCache = string.replace(self.presenterCacheBuffer, 'DIMDIMSL_COB_CONTENT_SRC', presenterLocation)
     
     attendeeLocation = resourceType + '/' + resourceID + '/' + pageNum + '/attendee/content.html'
     attendeeCache = string.replace(self.attendeeCacheBuffer, 'DIMDIMSL_COB_CONTENT_SRC', attendeeLocation)
     
     pCacheLocation = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'p_cache.html')
     pCacheHandle = open(pCacheLocation, 'wb')
     pCacheHandle.write(presenterCache)
     pCacheHandle.close()
     
     aCacheLocation = os.path.join(os.path.join(osconfig.cobArchive(), dimdimID), 'a_cache.html')
     aCacheHandle = open(aCacheLocation, 'wb')
     aCacheHandle.write(attendeeCache)
     aCacheHandle.close()
     
     # clean up
     
     try:
         os.remove(tempStore)
     except:
         pass
     
     # register everything
     
     
     self.stateEngine.registerResource(dimdimID, resourceID, resourceType)
     self.stateEngine.registerPage(dimdimID, originalURL)
     
     jsonSuccess = jsonObject()
     jsonSuccess.clearResponse()
     jsonSuccess.add('result', 'true')
     jsonSuccess.add('method', 'cacheURL')
     jsonSuccess.add('error', '7200')
     jsonSuccess.add('location', '/content/' + str(dimdimID))
     
     return jsonSuccess.jsonResponse()