Ejemplo n.º 1
0
def createIndicoLink(IndicoID, CDSID):
    """Create a link in Indico to the CDS record."""

#    Logger.get('RecMan').debug("in createIndicoLink()")
    # From IndicoID, get info
    try:
        talkInfo = parseIndicoID(IndicoID)
    except NoReportError:
        return False
    obj = talkInfo["object"]

    # Only one link per talk allowed.
    if doesExistIndicoLink(obj):
        return True # consider it a success anyway
    else:
#        Logger.get('RecMan').info("creating a new link in Indico for talk %s, CDS record %s" % (IndicoID, CDSID))

        # material object holds link object.
        # First create a material object with title "Video in CDS" or whatever the current text is.
        material = conference.Material()
        material.setTitle(CollaborationTools.getOptionValue("RecordingManager", "videoLinkName"))
        videoLink = Link()
        videoLink.setOwner(material)
#    I don't think this stuff is necessary:
#        videoLink.setName("Name goes here")
#        videoLink.setDescription("Description goes here")
        videoLink.setURL(CollaborationTools.getOptionValue("RecordingManager", "CDSBaseURL") % str(CDSID))
        material.addResource(videoLink)
        material.setMainResource(videoLink)
        obj.addMaterial(material)
        return True
Ejemplo n.º 2
0
def createIndicoLink(IndicoID, CDSID):
    """Create a link in Indico to the CDS record."""

    #    Logger.get('RecMan').debug("in createIndicoLink()")
    # From IndicoID, get info
    try:
        talkInfo = parseIndicoID(IndicoID)
    except NoReportError:
        return False
    obj = talkInfo["object"]

    # Only one link per talk allowed.
    if doesExistIndicoLink(obj):
        return True  # consider it a success anyway
    else:
        #        Logger.get('RecMan').info("creating a new link in Indico for talk %s, CDS record %s" % (IndicoID, CDSID))

        # material object holds link object.
        # First create a material object with title "Video in CDS" or whatever the current text is.
        material = conference.Material()
        material.setTitle(
            CollaborationTools.getOptionValue("RecordingManager",
                                              "videoLinkName"))
        videoLink = Link()
        videoLink.setOwner(material)
        #    I don't think this stuff is necessary:
        #        videoLink.setName("Name goes here")
        #        videoLink.setDescription("Description goes here")
        videoLink.setURL(
            CollaborationTools.getOptionValue("RecordingManager", "CDSBaseURL")
            % str(CDSID))
        material.addResource(videoLink)
        material.setMainResource(videoLink)
        obj.addMaterial(material)
        return True
Ejemplo n.º 3
0
    def _addMaterialType(self, text, user):

        from MaKaC.common.fossilize import fossilize
        from MaKaC.fossils.conference import ILocalFileExtendedFossil, ILinkFossil

        Logger.get('requestHandler').debug('Adding %s - request %s' %
                                           (self._uploadType, request))

        mat, newlyCreated = self._getMaterial()

        # if the material still doesn't exist, create it
        if newlyCreated:
            protectedAtResourceLevel = False
        else:
            protectedAtResourceLevel = True

        resources = []
        if self._uploadType in ['file', 'link']:
            if self._uploadType == "file":
                for fileEntry in self._files:
                    resource = LocalFile()
                    resource.setFileName(fileEntry["fileName"])
                    resource.setFilePath(fileEntry["filePath"])
                    resource.setDescription(self._description)
                    if self._displayName == "":
                        resource.setName(resource.getFileName())
                    else:
                        resource.setName(self._displayName)

                    if not type(self._target) is Category:
                        log_info = {
                            "subject":
                            "Added file %s%s" % (fileEntry["fileName"], text)
                        }
                        self._target.getConference().getLogHandler().logAction(
                            log_info, log.ModuleNames.MATERIAL)
                    resources.append(resource)
                    # in case of db conflict we do not want to send the file to conversion again, nor re-store the file

            elif self._uploadType == "link":

                for link in self._links:
                    resource = Link()
                    resource.setURL(link["url"])
                    resource.setDescription(self._description)
                    if self._displayName == "":
                        resource.setName(resource.getURL())
                    else:
                        resource.setName(self._displayName)

                    if not type(self._target) is Category:
                        log_info = {
                            "subject":
                            "Added link %s%s" % (resource.getURL(), text)
                        }
                        self._target.getConference().getLogHandler().logAction(
                            log_info, log.ModuleNames.MATERIAL)
                    resources.append(resource)

            status = "OK"
            info = resources
        else:
            status = "ERROR"
            info = "Unknown upload type"
            return mat, status, info

        # forcedFileId - in case there is a conflict, use the file that is
        # already stored
        repoIDs = []
        for i, resource in enumerate(resources):
            if self._repositoryIds:
                mat.addResource(resource, forcedFileId=self._repositoryIds[i])
            else:
                mat.addResource(resource, forcedFileId=None)

            #apply conversion
            if self._topdf and not isinstance(resource, Link):
                file_ext = os.path.splitext(
                    resource.getFileName())[1].strip().lower()
                if fileConverter.CDSConvFileConverter.hasAvailableConversionsFor(
                        file_ext):
                    # Logger.get('conv').debug('Queueing %s for conversion' % resource.getFilePath())
                    fileConverter.CDSConvFileConverter.convert(
                        resource.getFilePath(), 'pdf', mat)
                    resource.setPDFConversionRequestDate(nowutc())

            # store the repo id, for files
            if isinstance(resource, LocalFile) and self._repositoryIds is None:
                repoIDs.append(resource.getRepositoryId())

            if protectedAtResourceLevel:
                protectedObject = resource
            else:
                protectedObject = mat
                mat.setHidden(self._visibility)
                mat.setAccessKey(self._password)

                protectedObject.setProtection(self._statusSelection)

            for userElement in self._userList:
                if 'isGroup' in userElement and userElement['isGroup']:
                    avatar = GroupHolder().getById(userElement['id'])
                else:
                    avatar = AvatarHolder().getById(userElement['id'])
                protectedObject.grantAccess(avatar)

        self._topdf = False
        if self._repositoryIds is None:
            self._repositoryIds = repoIDs

        return mat, status, fossilize(
            info, {
                "MaKaC.conference.Link": ILinkFossil,
                "MaKaC.conference.LocalFile": ILocalFileExtendedFossil
            })
Ejemplo n.º 4
0
    def _process(self, rh, params):
        
        # We will need to pickle the data back into JSON
        from MaKaC.common.PickleJar import DictPickler
        
        errorList=[]
        user = rh.getAW().getUser()
        try:
            owner = self._target
            title = owner.getTitle()
            if type(owner) == Conference:
                ownerType = "event"
            elif type(owner) == Session:
                ownerType = "session"
            elif type(owner) == Contribution:
                ownerType = "contribution"
            elif type(owner) == SubContribution:
                ownerType = "subcontribution"
            else:
                ownerType = ""
            text = " in %s %s" % (ownerType,title)
        except:
            owner = None
            text = ""

        errorList=self._getErrorList()
        file = self._file
        link = self._link        
        resource = None
        
        if self._uploadType == "file":
            if len(errorList)==0:
                mat = self._getMaterial()
                
                if mat == None:
                    errorList.append("Unknown material");
                else:
                    resource = LocalFile()
                    resource.setFileName(file["fileName"])
                    resource.setName(resource.getFileName())
                    resource.setFilePath(file["filePath"])
                    resource.setDescription(self._description)
                    mat.addResource(resource)
                    #apply conversion
                    if self._topdf and fileConverter.CDSConvFileConverter.hasAvailableConversionsFor(os.path.splitext(resource.getFileName())[1].strip().lower()):
                        fileConverter.CDSConvFileConverter.convert(resource.getFilePath(), "pdf", mat)
                    if not type(self._target) is Category:
                        self._target.getConference().getLogHandler().logAction({"subject":"Added file %s%s" % (file["fileName"],text)},"Files",user)
                    # in case of db conflict we do not want to send the file to conversion again
                    self._topdf = False
    
            if len(errorList) > 0:
                status = "ERROR"
                info = errorList
            else:
                status = "OK"
                info = DictPickler.pickle(resource)
                info['material'] = mat.getId();
        
        elif self._uploadType == "link":
            if len(errorList)==0:
                mat = self._getMaterial()
                if mat == None:
                    mat = Material()
                    mat.setTitle(link["matType"])
                    self._target.addMaterial( mat )
                resource = Link()
                resource.setURL(link["url"])
                resource.setName(resource.getURL())
                resource.setDescription(self._description)
                mat.addResource(resource)
                if not type(self._target) is Category:
                    self._target.getConference().getLogHandler().logAction({"subject":"Added link %s%s" % (resource.getURL(),text)},"Files",user)
            
                status = "OK"
                info = DictPickler.pickle(resource)
                info['material'] = mat.getId();
            else:
                status = "ERROR"
                info = errorList
        
        else:
            status = "ERROR"
            info = "Unknown upload type"
          
        # hackish, because of mime types. Konqueror, for instance, would assume text if there were no tags,
        # and would try to open it
        from MaKaC.services.interface.rpc import json
        return "<html><head></head><body>"+json.encode({'status': status, 'info': info})+"</body></html>"