def _process(self): params = self._getRequestParams() if not "cancel" in params: if (params.get("subcats", "")): subcat = True else: subcat = False if (params.get("modifyConfTZ", "")): modifyConfTZ = True else: modifyConfTZ = False tz = params.get("defaultTimezone", "UTC") self._target.setTimezone(tz) if modifyConfTZ: self._target.changeConfTimezones(tz) if params.get("name", "") != self._target.getName(): self._target.setName(params.get("name", "")) self._target.setDescription(params.get("description", "")) self._target.setDefaultStyle( "simple_event", params.get("defaultSimpleEventStyle", ""), subcat) self._target.setDefaultStyle("meeting", params.get("defaultMeetingStyle", ""), subcat) if self._target.getVisibility() != int( params.get("visibility", 999)): self._target.setVisibility(params.get("visibility", 999)) if self._getUser().isAdmin(): self._target.setSuggestionsDisabled( 'disableSuggestions' in request.form) if "delete" in params and self._target.getIcon() is not None: self._target.removeIcon() if "icon" in params and type(params["icon"]) != str and \ params["icon"].filename.strip() != "": if not hasattr(self, "_filePath"): # do not save the file again if it has already been done (db conflicts) self._filePath = self._saveFileToTemp(params["icon"]) self._tempFilesToDelete.append(self._filePath) self._fileName = params["icon"].filename f = conference.LocalFile() f.setName("Icon") f.setDescription("This is the icon for the category") f.setFileName(self._fileName) f.setFilePath(self._filePath) self._target.setIcon(f) if "tasksAllowed" in params: if params["tasksAllowed"] == "allowed": self._target.setTasksAllowed() else: self._target.setTasksForbidden() self._redirect(urlHandlers.UHCategoryModification.getURL(self._target))
def getFiles(mat, f):#adds the files associated with a conference/session/contribution and adds them #f[0]-id, f[1]-format, f[2]-category, f[3]-cd, f[4]-md, f[5]-name, f[6]-path, f[7]-description, f[8]-numPages #f[9]-size, f[10]-deleted, f[11]-fileID, f[12]-eventID #if file name ends in .link open file, get address, make link cf = agenda.cursor() cf.execute("select password from FILE_PASSWORD where fileID=" + str(f[0])) f = cf.fetchone() if f!=None: password = f[0] else: password = "" if password!="": mat.setAccessKey(password) mat.setProtection(True) if getfiles!=0: error = False if f[5][-4:] == 'link' or f[5][-8:] =='lnk.html': if f[2] == 'moreinfo' and f[6][-8:] != 'moreinfo': path = f[6].encode(sys.getfilesystemencoding()) + "/moreinfo/" + f[5].encode(sys.getfilesystemencoding()) else: path = f[6].encode(sys.getfilesystemencoding()) + "/" + f[5].encode(sys.getfilesystemencoding()) log("getFiles:link: path = %s"%path) if file_host != "localhost": os.system("scp 'tbaron@%s:%s' '/tmp/%s'" % (file_host,re.escape(path), f[5].encode(sys.getfilesystemencoding()))) path = "/tmp/%s" % f[5].encode(sys.getfilesystemencoding()) try: f = file(path, 'rb') address = f.read() address = getAddress(address) f.close() except IOError,e: log("ressource file not found : %s" %path) error = True address = '' res = conference.Link() res.setURL(address) else:#if not a link res = conference.LocalFile()#creates new file and sets the local file path res.setFileName(f[5]) if f[2] == 'moreinfo' and f[6][-8:] != 'moreinfo': path = f[6].encode(sys.getfilesystemencoding()) + "/moreinfo/" + f[5].encode(sys.getfilesystemencoding()) else: path = f[6].encode(sys.getfilesystemencoding()) + "/" + f[5].encode(sys.getfilesystemencoding()) log("getFiles:file: path = %s"%path) if file_host != "localhost": os.system("scp 'tbaron@%s:%s' '/tmp/%s'" % (file_host,re.escape(path), f[5].encode(sys.getfilesystemencoding()))) path = "/tmp/%s" % f[5].encode(sys.getfilesystemencoding()) try: res.setFilePath(path) except Exception,e: log("ressource file not found : %s" %path) error = True
def setUp(self): super(TestProtection, self).setUp() self._startDBReq() # Create a user ah = AvatarHolder() self._avatar = Avatar() self._avatar.setName("fake") self._avatar.setSurName("fake") self._avatar.setOrganisation("fake") self._avatar.setLang("en_GB") self._avatar.setEmail("*****@*****.**") self._avatar.setId("fake") ah.add(self._avatar) # Create a conference category = conference.CategoryManager().getById('0') self._conf = category.newConference(self._avatar) self._conf.setTimezone('UTC') sd = datetime(2011, 11, 1, 10, 0, tzinfo=timezone('UTC')) ed = datetime(2011, 11, 1, 18, 0, tzinfo=timezone('UTC')) self._conf.setDates(sd, ed) ch = ConferenceHolder() ch.add(self._conf) self._contrib1 = conference.Contribution() self._conf.addContribution(self._contrib1) self._session1 = conference.Session() self._conf.addSession(self._session1) self._session2 = conference.Session() self._conf.addSession(self._session2) self._contrib2 = conference.Contribution() self._session1.addContribution(self._contrib2) #Now we create the material (id=0) and attach it to the contrib self._material = conference.Material() self._contrib1.addMaterial(self._material) #Now we create a dummy file and attach it to the material filePath = os.path.join(os.getcwd(), "test.txt") fh = open(filePath, "w") fh.write("hola") fh.close() self._resource = conference.LocalFile() self._resource.setFilePath(filePath) self._resource.setFileName("test.txt") self._material.addResource(self._resource) self._stopDBReq()
def _process( self ): params = self._getRequestParams() f = conference.LocalFile() f.setDescription( params["description"] ) f.setFileName( self._fileName ) f.setFilePath( self._filePath ) title=f.getFileName() if params.get("title", "").strip() != "": title=params.get("title") f.setName( title) self._material.addResource( f ) #apply conversion if self._topdf and fileConverter.CDSConvFileConverter.hasAvailableConversionsFor(os.path.splitext(f.getFileName())[1].strip().lower()): fileConverter.CDSConvFileConverter.convert(f.getFilePath(), "pdf", self._material) self._redirect( urlHandlers.UHMaterialModification.getURL( self._material ) )
def storeConvertedFile(requestIP, params): """ returns the path to the temp file used in the process so that it can be deleted at a later stage """ # extract the server name from the url serverURL = Config.getInstance().getFileConverterServerURL() up = urlparse.urlparse(serverURL) ip_addrs = resolve_host(up[1]) # check that the request comes from the conversion server if requestIP not in ip_addrs: return if params["status"] == '1': locator = {} # python dicts come with ' instead of " by default # using a json encoder on the server side would help... locator = loads(params["directory"].replace('\'', '"')) mat = CDSConvFileConverter._getMaterial(locator) if mat is not None: filePath = CDSConvFileConverter._saveFileToTemp(params) fileName = params["filename"] for resource in mat.getResourceList(): # if the pdf name is the same as any of the resources, and the material does not have a PDF yet: if isinstance( resource, conference.LocalFile) and os.path.splitext( resource.fileName)[0] == os.path.splitext( fileName)[0] and not mat.hasFile(fileName): resource.setPDFConversionRequestDate(None) f = conference.LocalFile() f.setName(fileName) f.setFileName(fileName) f.setFilePath(filePath) mat.addResource(f) return filePath else: #writeLog("Locator does not exist for file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"])) pass else: #Here it should be processed the received error from the conversion server. #writeLog("Error converting file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"])) pass
def _process(self): url = urlHandlers.UHMaterialDisplay.getURL(self._target) errorList = [] if self._action == "CANCEL": self._redirect(url) return elif self._action == "SUBMIT_FILES": errorList = self._getErrorList() if len(errorList) == 0: f = conference.LocalFile() f.setName(self._matType) f.setDescription(self._fileDesc) f.setFileName(self._fileName) f.setFilePath(self._filePath) self._material.addResource(f) self._redirect(url) return p = material.WPMaterialDisplaySubmitResource(self, self._target) pars = self._getRequestParams() pars["errorList"] = errorList return p.display(**self._getRequestParams())
def setUp(self): super(TestProtection, self).setUp() with self._context("database"): # Create a conference category = conference.CategoryManager().getById('0') self._conf = category.newConference(self._dummy) self._conf.setTimezone('UTC') sd = datetime(2011, 11, 1, 10, 0, tzinfo=timezone('UTC')) ed = datetime(2011, 11, 1, 18, 0, tzinfo=timezone('UTC')) self._conf.setDates(sd, ed) ch = ConferenceHolder() ch.add(self._conf) self._contrib1 = conference.Contribution() self._conf.addContribution(self._contrib1) self._session1 = conference.Session() self._conf.addSession(self._session1) self._session2 = conference.Session() self._conf.addSession(self._session2) self._contrib2 = conference.Contribution() self._session1.addContribution(self._contrib2) #Now we create the material (id=0) and attach it to the contrib self._material = conference.Material() self._contrib1.addMaterial( self._material ) #Now we create a dummy file and attach it to the material filePath = os.path.join( os.getcwd(), "test.txt" ) fh = open(filePath, "w") fh.write("hola") fh.close() self._resource = conference.LocalFile() self._resource.setFilePath( filePath ) self._resource.setFileName( "test.txt" ) self._material.addResource( self._resource )
def storeConvertedFile(requestIP, params): """ returns the path to the temp file used in the process so that it can be deleted at a later stage """ # extract the server name from the url serverURL = Config.getInstance().getFileConverterServerURL() up = urlparse.urlparse(serverURL) # check that the request comes from the conversion server if socket.gethostbyname(up[1]) != requestIP: return if params["status"] == '1': locator = {} # python dicts come with ' instead of " by default # using a json encoder on the server side would help... locator = simplejson.loads(params["directory"].replace('\'', '"')) mat = CDSConvFileConverter._getMaterial(locator) if mat is not None: filePath = CDSConvFileConverter._saveFileToTemp(params) fileName = params["filename"] if not mat.hasFile(fileName): f = conference.LocalFile() f.setName(fileName) f.setFileName(fileName) f.setFilePath(filePath) mat.addResource(f) return filePath else: #writeLog("Locator does not exist for file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"])) pass else: #Here it should be processed the received error from the conversion server. #writeLog("Error converting file \"%s\": \n-locator:%s\nmessage:%s"%(params["filename"], params["directory"], params["error_message"])) pass