def deletePreloadedDocuments(self, meetingID, strictJSON = False): if sys.platform.startswith('win'): archiveDirectory = string.rstrip(osconfig.slidedeckArchive(), '\\') else: archiveDirectory = osconfig.slidedeckArchive() preloadedDocDir = os.path.join(os.path.join(archiveDirectory, meetingID), 'Preloaded') try: shutil.rmtree(preloadedDocDir) except: pass if not strictJSON: # JSON Response BEGIN jsondata = jsonObject() jsondata.clearResponse() jsondata.add('result','true') jsondata.add('method','deletePreloadedDocuments') jsondata.add('meetingID', meetingID) jsondata.add('error', '7200') #JSON Response END return jsondata.jsonResponse() else: jsondata = {'result' : 'true', 'method' : 'deletePreloadedDocuments', 'meetingID': meetingID, 'error' : 7200} response = self.demHelper.encode(jsondata) return response.encode()
def closeMeeting(self, meetingID): # JSON Response BEGIN (error message) jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result','false') jsonError.add('method','closeMeeting') jsonError.add('meetingID',meetingID) jsonError.add('error','7404') #JSON Response END # Do meetingID-related input verification if (meetingID == ''): return jsonError.jsonResponse() if sys.platform.startswith('win'): archiveDirectory = string.rstrip(osconfig.slidedeckArchive(), '\\') else: archiveDirectory = string.rstrip(osconfig.slidedeckArchive(), '/') localMeetingDir = os.path.join(archiveDirectory, meetingID) if not os.path.isdir(localMeetingDir): return jsonError.jsonResponse() docList = os.listdir(localMeetingDir) if len(docList) == 0: return jsonError.jsonResponse() for i in range (0, len(docList)): if docList[i] == 'Preloaded': # we don't delete preloaded directories continue docPath = os.path.join(localMeetingDir, docList[i]) try: shutil.rmtree(docPath) except: pass docList = os.listdir(localMeetingDir) if len(docList) == 0: try: os.rmdir(localMeetingDir) except: pass # JSON Response BEGIN jsonSuccess = jsonObject() jsonSuccess.clearResponse() jsonSuccess.add('result','true') jsonSuccess.add('method','closeMeeting') jsonSuccess.add('meetingID',meetingID) jsonSuccess.add('error', '7200') #JSON Response END return jsonSuccess.jsonResponse()
def uploadPPTXSlide(self, docFile, meetingID, docID, docName, pageNo, noOfPages): # 'Type' will be 'regular', becuase PPTX slides are uploaded by the presenter # There is no conversion involved in this operation. We just need to commit this file to archive iPageNo = string.atoi(pageNo) iNoOfPages = string.atoi(noOfPages) jsonComplete = jsonObject() jsonComplete.clearResponse() jsonComplete.add('result', 'true') jsonComplete.add('method', 'uploadPPTXSlide') jsonComplete.add('docID', docID) slidedeckArchive = osconfig.slidedeckArchive() specArchive = os.path.join(slidedeckArchive, meetingID) if docID == 'GENERATE' or docID == '': docID = idgen.gen() specArchive = os.path.join(specArchive, docID) if not os.path.isdir(specArchive): os.makedirs(specArchive) storedFileName = os.path.join(specArchive, pageNo) storedFileName += ".jpg" if sys.platform.startswith('win'): storedFile = open(storedFileName, 'wb') else: storedFile = open(storedFileName, 'w') while True: data = docFile.file.read(8192) if not data: break storedFile.write(data) storedFile.close() if (iPageNo == iNoOfPages - 1): # store some details for probable future use storeObject = filehelper.serialObject() storeObject.clearBuffer() storeObject.add('docName', docName) storeObject.add('docID',docID) storeObject.add('noOfPages',noOfPages) dataStore = os.path.join(specArchive, 'documentData.txt'); storeObject.exportData(dataStore) jsonComplete.add('complete', 'true') return jsonComplete.jsonResponse() jsonComplete.add('complete', 'false') return jsonComplete.jsonResponse()
def copyAllPreloaded(self, sourceMeetingRoom, destinationMeetingRoom, strictJSON = False): slidedeckArchive = osconfig.slidedeckArchive() sourcePath = os.path.join(os.path.join(slidedeckArchive, sourceMeetingRoom), 'Preloaded') if not os.path.isdir(sourcePath): if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'false') jsonError.add('method', 'copyAllPreloaded') jsonError.add('error', '7404') return jsonError.jsonResponse() else: jsonError = {'result':'false', 'method':'copyAllPreloaded', 'error':7404} response = self.demHelper.encode(jsonError) return response.encode() for entry in os.listdir(sourcePath): sourcePath = os.path.join(os.path.join(os.path.join(slidedeckArchive, sourceMeetingRoom), 'Preloaded'), entry) destPath = os.path.join(os.path.join(os.path.join(slidedeckArchive, destinationMeetingRoom), 'Preloaded'), entry) try: # in case the destination directory doesn't exist os.makedirs(destPath) except: pass try: fileList = dir_util.copy_tree(sourcePath, destPath) except: if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'false') jsonError.add('method', 'copyAllPreloaded') jsonError.add('error', '7500') return jsonError.jsonResponse() else: jsonError = {'result':'false', 'method':'copyAllPreloaded', 'error':7500} response = self.demHelper.encode(jsonError) return response.encode() if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'true') jsonError.add('method', 'copyAllPreloaded') jsonError.add('error', '7200') return jsonError.jsonResponse() else: jsonError = {'result':'true', 'method':'copyAllPreloaded', 'error':7200} response = self.demHelper.encode(jsonError) return response.encode()
def getDocumentData(self, meetingID, docID, strictJSON=False): slidedeckArchive = osconfig.slidedeckArchive() [installationID, dimdimID] = osconfig.splitIdentity(meetingID) meetingID = installationID + '____' + dimdimID jsonSuccess = jsonObject() jsonSuccess.clearResponse() jsonSuccess.add('result', 'true') jsonSuccess.add('method', 'getDocumentData') jsonSuccess.add('meetingID', meetingID) entries = self.findDocuments(slidedeckArchive, meetingID, docID) strictSuccess = {'result' : 'true', 'method' : 'getDocumentData', 'meetingID' : meetingID} if len(entries) == 0: if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'false') jsonError.add('method', 'getDocumentData') jsonError.add('meetingID', meetingID) jsonError.add('docID', docID) jsonError.add('error', '7404') return jsonError.jsonResponse() else: strictError = {'result':'false', 'method':'getDocumentData', 'meetingID':meetingID, 'docID':docID, 'error':7404} response = self.demHelper.encode(strictError) return response.encode() if not strictJSON: for i in range(0, len(entries)): fp = serialObject() fp.clearBuffer() fp.importData(entries[i]) #jsonSuccess.add('docName', fp.get('docName')) jsonSuccess.add('docID', docID) jsonSuccess.add('docName', fp.get('docName')) jsonSuccess.add('noOfPages', string.atoi(fp.get('noOfPages'))) jsonSuccess.add('width', fp.get('width')) jsonSuccess.add('height', fp.get('height')) jsonSuccess.add('error', '7200') return jsonSuccess.jsonResponse() else: for i in range(0, len(entries)): fp = serialObject() fp.clearBuffer() fp.importData(entries[i]) strictSuccess.update({'docID':docID, 'docName':fp.get('docName'), 'noOfPages' : string.atoi(fp.get('noOfPages')), \ 'width': string.atoi(fp.get('width')), 'height': string.atoi(fp.get('height'))}) response = self.demHelper.encode(strictSuccess) return response.encode()
def copyPreloadedDocument(self, sourceMeetingRoom, docID, destinationMeetingRoom, strictJSON=False): slidedeckArchive = osconfig.slidedeckArchive() sourcePath = os.path.join(os.path.join(os.path.join(slidedeckArchive, sourceMeetingRoom), 'Preloaded'), docID) destPath = os.path.join(os.path.join(os.path.join(slidedeckArchive, destinationMeetingRoom), 'Preloaded'), docID) if not os.path.isdir(sourcePath): if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'false') jsonError.add('method', 'copyPreloadedDocument') jsonError.add('error', '7404') return jsonError.jsonResponse() else: jsonError = {'result':'false', 'method':'copyPreloadedDocument', 'error':7404} response = self.demHelper.encode(jsonError) return response.encode() try: fileList = dir_util.copy_tree(sourcePath, destPath) except: if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'false') jsonError.add('method', 'copyPreloadedDocument') jsonError.add('error', '7500') return jsonError.jsonResponse() else: jsonError = {'result':'false', 'method':'copyPreloadedDocument', 'error':7500} response = self.demHelper.encode(jsonError) return response.encode() if not strictJSON: jsonError = jsonObject() jsonError.clearResponse() jsonError.add('result', 'true') jsonError.add('method', 'copyPreloadedDocument') jsonError.add('error', '7200') return jsonError.jsonResponse() else: jsonError = {'result':'true', 'method':'copyPreloadedDocument', 'error':7200} response = self.demHelper.encode(jsonError) return response.encode()
import shutil import cherrypy from threading import Timer from threading import BoundedSemaphore #import win32com.client, pythoncom from toolkit import osconfig from toolkit import filehelper from toolkit.dThread import dThread selfDestructTime = 360.0 # in seconds mediaArchive = osconfig.mediaDirectory() oopath = osconfig.ooPath() slidedeckArchive = osconfig.slidedeckArchive() mailboxURL = osconfig.mailboxURL() if sys.platform.startswith('win'): import win32process import win32file import win32com.client, pythoncom else: sys.path.append(oopath) import uno import unohelper from com.sun.star.beans import PropertyValue class scopedLock(object):
import shutil import cherrypy from threading import Timer from threading import BoundedSemaphore #import win32com.client, pythoncom from toolkit import osconfig from toolkit import filehelper from toolkit.dThread import dThread selfDestructTime = 360.0 # in seconds mediaArchive = osconfig.mediaDirectory() oopath = osconfig.ooPath() slidedeckArchive = osconfig.slidedeckArchive() mailboxURL = osconfig.mailboxURL() if sys.platform.startswith('win'): import win32process import win32file import win32com.client, pythoncom else: sys.path.append(oopath) import uno import unohelper from com.sun.star.beans import PropertyValue class scopedLock(object): # A simple scoped lock class.
def deleteDocument(self, docID, meetingID, strictJSON = False): # JSON Response BEGIN (error message) strictdata = {'result' : 'false', 'method' : 'deleteDocument', 'docID' : docID, 'meetingID' : meetingID, 'error' : 7404} jsondata = jsonObject() jsondata.clearResponse() jsondata.add('result','false') jsondata.add('method','deleteDocument') jsondata.add('docID', docID) jsondata.add('meetingID', meetingID) jsondata.add('error', '7404') #JSON Response END if (docID == ''): if not strictJSON: return jsondata.jsonResponse() else: response = self.demHelper.encode(strictdata) return response.encode() if sys.platform.startswith('win'): archiveDirectory = string.rstrip(osconfig.slidedeckArchive(), '\\') else: archiveDirectory = osconfig.slidedeckArchive() # check if the directory exists, in global, preloaded and local localDocDir = os.path.join(os.path.join(archiveDirectory, meetingID), docID) preloadedDocDir = os.path.join(os.path.join(os.path.join(archiveDirectory, meetingID), 'Preloaded'), docID) globalDocDir = os.path.join(os.path.join(archiveDirectory, 'global-meeting'), docID) docPath = None if os.path.isdir(localDocDir): docPath = localDocDir if os.path.isdir(preloadedDocDir): docPath = preloadedDocDir if os.path.isdir(globalDocDir): if meetingID != 'global-meeting': # we have already taken care of this docPath = globalDocDir if not docPath: return jsondata.jsonResponse() try: shutil.rmtree(docPath) except: pass if not strictJSON: # JSON Response BEGIN jsondata = jsonObject() jsondata.clearResponse() jsondata.add('result','true') jsondata.add('method','deleteDocument') jsondata.add('docID', docID) jsondata.add('meetingID', meetingID) jsondata.add('error', '7200') #JSON Response END return jsondata.jsonResponse() else: strictdata = {'result' : 'true', 'method' : 'deleteDocument', 'docID' : docID, 'meetingID' : meetingID, 'error' : 7200} response = self.demHelper.encode(strictdata) return response.encode()
def retrieveDocument(self, docID, meetingID, pageNo): [installationID, dimdimID] = osconfig.splitIdentity(meetingID) meetingID = installationID + '____' + dimdimID # JSON Response BEGIN (error message) jsondata = jsonObject() jsondata.clearResponse() jsondata.add('result','false') jsondata.add('method','retrieveDocument') jsondata.add('docID',docID) jsondata.add('meetingID',meetingID) jsondata.add('error', '7404') #JSON Response END if (docID == ''): return jsondata.jsonResponse() if sys.platform.startswith('win'): archiveDirectory = string.rstrip(osconfig.slidedeckArchive(), '\\') else: archiveDirectory = osconfig.slidedeckArchive() localDocDir = os.path.join(os.path.join(archiveDirectory, meetingID), docID) preloadedDocDir = os.path.join(os.path.join(os.path.join(archiveDirectory, meetingID), 'Preloaded'), docID) globalDocDir = os.path.join(os.path.join(archiveDirectory, 'global-meeting'), docID) docPath = None if os.path.exists(localDocDir): docPath = localDocDir if os.path.exists(preloadedDocDir): docPath = preloadedDocDir if os.path.exists(globalDocDir): docPath = globalDocDir if not docPath: self.collator.registerRetrieveFailure() return jsondata.jsonResponse() fileList = os.listdir(docPath) if len(fileList) <= 1: # we need *atleast* 2 files. i.e. atleast 1 swf and 1 meta data file self.collator.registerRetrieveFailure() return jsondata.jsonResponse() swfpath = docPath jpgpath = docPath if sys.platform.startswith('win'): jpgpath += '\\' + pageNo + '.jpg' swfpath += '\\' + pageNo + '.swf' else: jpgpath += '/' + pageNo + '.jpg' swfpath += '/' + pageNo + '.swf' path = '' if os.path.isfile(swfpath): path = swfpath elif os.path.isfile(jpgpath): path = jpgpath else: self.collator.registerRetrieveFailure() return jsondata.jsonResponse() self.collator.resetRetrieveFailures() return static.serve_file(path,"application/octet-stream","inline",os.path.basename(path))
def listDocuments(self, meetingID, strictJSON = False): slidedeckArchive = osconfig.slidedeckArchive() [installationID, dimdimID] = osconfig.splitIdentity(meetingID) meetingID = installationID + '____' + dimdimID jsondata = jsonObject() jsondata.clearResponse() entries = self.findMeetingDocuments(slidedeckArchive, meetingID) if len(entries) == 0: if not strictJSON: jsondata.add('result', 'false') jsondata.add('method', 'listDocuments') jsondata.add('error', '7404') jsondata.add('meetingID', meetingID) return jsondata.jsonResponse() else: jsondata = {'result':'false', 'method':'listDocuments', 'error':7404, 'meetingID':meetingID} response = self.demHelper.encode(jsondata) return response.encode() if not strictJSON: jsondata.add('result', 'true') jsondata.add('method', 'listDocuments') jsondata.add('meetingID', meetingID) jsondata.add('error', '7200') entryJSONValue = '[' for i in range(0, len(entries)): entryJSON = jsonObject() entryJSON.clearResponse() fp = serialObject() fp.clearBuffer() fp.importData(entries[i]) entryJSON.add('docName',fp.get('docName')) entryJSON.add('docID',fp.get('docID')) entryJSON.add('width', fp.get('width')) entryJSON.add('height', fp.get('height')) entryJSON.add('noOfPages',string.atoi(fp.get('noOfPages'))) if entries[i].find('global-meeting') >= 0: entryJSON.add('Type', "global") else: entryJSON.add('Type', "preloaded") entryJSONValue += entryJSON.jsonResponse() if i < len(entries) -1: entryJSONValue += ',' entryJSONValue += ']' jsondata.add('docs',entryJSONValue) return jsondata.jsonResponse() else: jsondata = {'result':'true', 'method':'listDocuments', 'meetingID':meetingID, 'error':7200} entryList = [] for i in range(0, len(entries)): fp = serialObject() fp.clearBuffer() fp.importData(entries[i]) entryMap = {'docName' : fp.get('docName'), 'docID' : fp.get('docID'), 'width' : string.atoi(fp.get('width')), \ 'height': string.atoi(fp.get('height')), 'noOfPages' : string.atoi(fp.get('noOfPages')) } if entries[i].find('global-meeting') >= 0: entryMap.update({'Type':'global'}) else: entryMap.update({'Type' : 'preloaded'}) entryList.append(entryMap) jsondata.update({'docs':entryList}) response = self.demHelper.encode(jsondata) return response.encode()