Changeset 0cb016 in indico


Ignore:
Timestamp:
06/10/10 18:11:38 (3 years ago)
Author:
Jeremy Herr <jeremy.herr@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, new-webex, v0.97-series, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
2349da
Parents:
18bdc4
git-author:
Jeremy Herr <jeremy.herr@…> (05/06/10 18:33:15)
git-committer:
Jeremy Herr <jeremy.herr@…> (06/10/10 18:11:38)
Message:

[IMP] implemented web upload to micala server

  • Got web upload working to micala server
  • Added micalaUploadURL to options.py
  • Found bug ... whenever there are double quotes in a talk title, it caused a JavaScript? error because I am passing the list RMTalkList to JavaScript?. I did string.replace('"', '%22') to fix it
  • In services.py, added conditional, so submitMicalaMetadata is only called if the talk in question is a web_lecture
  • edited micala_lecture_conference.xsl, making it conform more closely to the standard
  • added micala_lecture_session.xsl, micala_lecture_contribution.xsl, micala_lecture_subcontribution.xsl
Location:
indico/MaKaC
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/plugins/Collaboration/RecordingManager/common.py

    r18bdc4 r0cb016  
    383383    a conference, subcontribution etc, and return that info with the individual IDs.""" 
    384384 
     385    # regular expressions to match IndicoIDs for conference, session, contribution, subcontribution 
    385386    pConference      = re.compile('(\d+)$') 
    386387    pSession         = re.compile('(\d+)s(\d+)$') 
     
    388389    pSubcontribution = re.compile('(\d+)c(\d+)sc(\d+)$') 
    389390 
     391    # perform the matches (match searches from the beginning of the string, 
     392    # unlike search, which matches anywhere in the string) 
    390393    mE  = pConference.match(IndicoID) 
    391394    mS  = pSession.match(IndicoID) 
     
    393396    mSC = pSubcontribution.match(IndicoID) 
    394397 
     398    # Depending on which talk type it is, populate a dictionary containing the name of 
     399    # the type of talk, the actual object, and the individual conference, session, contribution, 
     400    # subcontribution IDs. 
    395401    if mE: 
    396402        Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'conference')) 
     
    472478    # Defining the dictionary 'tags' is how we identify ourselves to the outputGenerator 
    473479    # methods. 
     480    # Call ConfToXML with different args depending on talk type. 
     481    # includeSession - descend into each session. 
     482    #                  This is necessary for sessions, contributions, and subcontributions, 
     483    #                  since contributions and subcontributions are children of sessions. 
     484    # includeContribution - necessary for contributions and subcontributions 
     485    # includeMaterial - this is always set to "1". 
     486    # showSession - create XML for a particular session, identified by ID 
     487    # showContribution - create XML for a particular contribution, identified by ID 
     488    # showSubContribution - create XML for a particular subcontribution, identified by ID 
     489    # forceCache - True means force it NOT to use the cache, the opposite of what you would expect. 
     490    # recordingManagerTags - this is how we pass along all the necessary RecordingManager args to the outputGenerator methods. 
     491    # 
    474492    # Nobody outside CERN should have access to CERN access lists. 
    475493    # OAI harvesters outside CERN call the same methods we'll be calling, 
     
    524542    xmlGen.closeTag("event") 
    525543 
    526     # Get base XML 
     544    # Retrieve the entire basic XML string 
    527545    return xmlGen.getXml() 
    528546 
     
    629647        except Exception, e: 
    630648            flagSuccess = False 
    631             result += "Unknown error occured when updating task information in micala database: %s\n." % e 
     649            result += _("Unknown error occured when updating task information in micala database: ") + e + "\n" 
    632650 
    633651    return {"success": flagSuccess, "result": result} 
    634652 
    635 def submitMicalaMetadata(aw, IndicoID, contentType, videoFormat, languages): 
     653def submitMicalaMetadata(aw, IndicoID, contentType, LOID, videoFormat, languages): 
    636654    '''Generate a lecture.xml file for the given event, then web upload it to the micala server.''' 
    637655 
    638     basexml = getBasicXMLRepresentation(aw, IndicoID, contentType, videoFormat, languages) 
    639  
    640     from MaKaC.common import Config 
    641  
    642     micalaxml = "" 
    643  
    644     # Given the IndicoID, retrieve the type of talk and IDs, so we know which XSL file to use. 
    645     parsed = parseIndicoID(IndicoID) 
    646  
    647     # Choose the appropriate stylesheet: 
    648     # - micala_lecture_conference.xsl 
    649     # - micala_lecture_session.xsl 
    650     # - micala_lecture_contribution.xsl 
    651     # - micala_lecture_subcontribution.xsl 
    652     styleSheet = "%s_%s.xsl" % ('cds_marcxml_video', parsed["type"]) 
    653     stylePath = os.path.join(Config.getInstance().getStylesheetsDir(), styleSheet) 
    654  
    655     if os.path.exists(stylePath): 
    656         try: 
    657             Logger.get('RecMan').info("Trying to do XSLT using path %s" % stylePath) 
    658             parser = XSLTransformer(stylePath) 
    659             micalaxml = parser.process(basexml) 
    660         except Exception: 
    661             micalaxml = "Cannot parse stylesheet: %s" % sys.exc_info()[0] 
    662     else: 
    663         micalaxml = basexml 
     656    Logger.get('RecMan').debug('in submitMicalaMetadata()') 
     657 
     658    # Initialize success flag, and result string to which we will append any errors. 
     659    flagSuccess = True 
     660    result = "" 
     661 
     662    # First, update the micala Tasks table that the submission has started 
    664663 
    665664    # pattern to match for the signal file 
     
    674673 
    675674    # Update the micala database with our current task status 
    676     idMachine = MicalaCommunication.getIdMachine(CollaborationTools.getOptionValue("RecordingManager", "micalaDBMachineName")) 
    677     idTask    = MicalaCommunication.getIdTask(CollaborationTools.getOptionValue("RecordingManager", "micalaDBStatusExportCDS")) 
    678     idLecture = MicalaCommunication.getIdLecture(IndicoID, pattern_cern, pattern_umich) 
    679     if idLecture == '': 
    680         idLecture = MicalaCommunication.createNewMicalaLecture(IndicoID, contentType, pattern_cern, pattern_umich) 
    681     MicalaCommunication.reportStatus('START', '', idMachine, idTask, idLecture) 
     675    try: 
     676        Logger.get('RecMan').debug('calling getIdMachine...') 
     677        idMachine = MicalaCommunication.getIdMachine(CollaborationTools.getOptionValue("RecordingManager", "micalaDBMachineName")) 
     678        Logger.get('RecMan').debug('calling getIdTask...') 
     679        idTask    = MicalaCommunication.getIdTask(CollaborationTools.getOptionValue("RecordingManager", "micalaDBStatusExportMicala")) 
     680        Logger.get('RecMan').debug('calling getIdLecture...') 
     681        idLecture = MicalaCommunication.getIdLecture(IndicoID, pattern_cern, pattern_umich) 
     682        Logger.get('RecMan').debug('calling reportStatus...') 
     683        if idLecture == '': 
     684            idLecture = MicalaCommunication.createNewMicalaLecture(IndicoID, contentType, pattern_cern, pattern_umich) 
     685        MicalaCommunication.reportStatus('START', '', idMachine, idTask, idLecture) 
     686    except Exception, e: 
     687        flagSuccess = False 
     688        result += _("Unknown error occured when updating MICALA START task information in micala database: %s\n." % e) 
     689 
     690    basexml = getBasicXMLRepresentation(aw, IndicoID, contentType, videoFormat, languages) 
     691 
     692    from MaKaC.common import Config 
     693 
     694    micalaxml = "" 
     695 
     696    # Given the IndicoID, retrieve the type of talk and IDs, so we know which XSL file to use. 
     697    parsed = parseIndicoID(IndicoID) 
     698 
     699    # Choose the appropriate stylesheet: 
     700    # - micala_lecture_conference.xsl 
     701    # - micala_lecture_session.xsl 
     702    # - micala_lecture_contribution.xsl 
     703    # - micala_lecture_subcontribution.xsl 
     704    styleSheet = "%s_%s.xsl" % ('micala_lecture', parsed["type"]) 
     705    stylePath = os.path.join(Config.getInstance().getStylesheetsDir(), styleSheet) 
     706 
     707    if os.path.exists(stylePath): 
     708        try: 
     709            Logger.get('RecMan').info("Trying to do XSLT using path %s" % stylePath) 
     710            parser = XSLTransformer(stylePath) 
     711            micalaxml = parser.process(basexml) 
     712        except Exception, e: 
     713            flagSuccess = False 
     714            result += "Cannot parse stylesheet: %s" % sys.exc_info()[0] 
     715    else: 
     716        flagSuccess = False 
     717        result += "Stylesheet does not exist: %s" % stylePath 
    682718 
    683719    # temporary, for my own debugging 
    684     f = open('/tmp/lecture.xml', 'w') 
     720    f = open('/tmp/micala.xml', 'w') 
    685721    f.write(micalaxml) 
    686722    f.close() 
    687723 
    688     # Submit XML record to micala server 
    689     data = urlencode({ 
    690         "file": micalaxml, 
    691         "mode": "-ir" 
    692     }) 
     724    # Web upload metadata to micala server 
     725    if flagSuccess == True: 
     726        # encode the LOID and the XML file as POST variables 
     727        data = urlencode({ "LOID": LOID, "micalaxml": micalaxml }) 
     728        # use the header to identify ourselves 
     729        headers = {"User-Agent": "micala_webupload"} 
     730        # build the request 
     731        request = Request(CollaborationTools.getOptionValue("RecordingManager", "micalaUploadURL"), data, headers) 
     732 
     733        Logger.get('RecMan').debug("micala request = %s" % str(request)) 
     734 
     735        # submit the request, and append caught exceptions to the result string, 
     736        # to be displayed by services.py 
     737        try: 
     738            f = urlopen(request) 
     739            request_result = f.read() 
     740            if request_result == 'no data': 
     741                result += _("micala web upload returned an unknown error when submitting to ") + "%s\n" % \ 
     742                    (CollaborationTools.getOptionValue("RecordingManager", "micalaUploadURL")) 
     743            Logger.get('RecMan').debug("micala result = %s" % str(request_result)) 
     744        except HTTPError, e: 
     745            flagSuccess = False 
     746            result += _("micala web upload returned an error when submitting to ") + "%s: %s\n" % \ 
     747                (CollaborationTools.getOptionValue("RecordingManager", "micalaUploadURL"), e) 
     748        except Exception, e: 
     749            flagSuccess = False 
     750            result += _("Unknown error occured when submitting micala metadata: ") + e + "\n" 
     751 
     752    # Update the micala database showing the task has started, but only if 
     753    # the submission actually succeeded. 
     754    if flagSuccess == True: 
     755        # pattern to match for the signal file 
     756        # Here we are looking for 
     757        # CONFID 
     758        # or CONFIDcCONTRID 
     759        # or CONFIDcCONTRIDscSCONTRID 
     760        # or CONFIDsSESSID 
     761        pattern_cern  = re.compile('([sc\d]+)$') 
     762        # Here we are looking for YYYYMMDD-DEVICENAME-HHMMSS 
     763        pattern_umich = re.compile('(\d+\-[\w\d]+\-\d)$') 
     764 
     765        # Update the micala database with our current task status 
     766        try: 
     767            if idLecture == '': 
     768                idLecture = MicalaCommunication.createNewMicalaLecture(IndicoID, contentType, pattern_cern, pattern_umich) 
     769            MicalaCommunication.reportStatus('COMPLETE', '', idMachine, idTask, idLecture) 
     770        except Exception, e: 
     771            flagSuccess = False 
     772            result += _("Unknown error occured when updating COMPLETE MICALA task information in micala database: %s\n." % e) 
     773 
     774    return {"success": flagSuccess, "result": result} 
    693775 
    694776def getCDSRecords(confId): 
     
    706788    # if this CDS query needs to be changed (thanks jerome.caffaro@cern.ch): 
    707789    # http://invenio-demo.cern.ch/help/hacking/search-engine-api 
    708     # NB: We replace the string INDICO_ID manually instead of using %s because 
     790    # NB: We replace the string REPLACE_WITH_INDICO_ID manually instead of using %s because 
    709791    # there are also url-encoded chars containing the % char. 
    710792    optionsCDSQueryURL = CollaborationTools.getOptionValue("RecordingManager", "CDSQueryURL") 
    711793    escapedOptionsCDSQueryURL = optionsCDSQueryURL.replace("REPLACE_WITH_INDICO_ID", id_plus_wildcard) 
    712     Logger.get('RecMan').debug("optionsCDSQueryURL = " + optionsCDSQueryURL) 
    713794    Logger.get('RecMan').debug("escapedOptionsCDSQueryURL = " + escapedOptionsCDSQueryURL) 
    714795    url = escapedOptionsCDSQueryURL 
  • indico/MaKaC/plugins/Collaboration/RecordingManager/options.py

    r18bdc4 r0cb016  
    113113               "visible": True} ), 
    114114 
     115    ("micalaUploadURL", {"description" : _("URL for micala web upload"), 
     116               "type": str, 
     117               "defaultValue": "http://lectureprocessing01.cern.ch/micala_monitor/test.py", 
     118               "editable": True, 
     119               "visible": True} ), 
     120 
    115121    ("CDSQueryURL", {"description" : _("CDS query URL (put the string REPLACE_WITH_INDICO_ID where you want the Indico ID to be)"), 
    116122               "type": str, 
  • indico/MaKaC/plugins/Collaboration/RecordingManager/services.py

    r5f9652 r0cb016  
    2222from MaKaC.services.implementation.collaboration import CollaborationPluginServiceBase 
    2323from MaKaC.plugins.Collaboration.RecordingManager.exceptions import RecordingManagerException 
    24 from MaKaC.plugins.Collaboration.RecordingManager.common import createIndicoLink, createCDSRecord 
     24from MaKaC.plugins.Collaboration.RecordingManager.common import createIndicoLink, createCDSRecord, submitMicalaMetadata 
    2525from MaKaC.plugins.Collaboration.RecordingManager.micala import MicalaCommunication 
    2626 
     
    4848        self._IndicoID    = self._params.get('IndicoID',    None) 
    4949        self._LOID        = self._params.get('LOID',        None) 
     50        self._LODBID      = self._params.get('LODBID',      None) 
    5051        self._confId      = self._params.get('conference',  None) 
    5152        self._videoFormat = self._params.get('videoFormat', None) 
     
    5960 
    6061        if self._contentType == 'web_lecture': 
    61             if not self._LOID: 
    62                 raise RecordingManagerException("No LOID supplied") 
     62            if not self._LODBID: 
     63                raise RecordingManagerException("No LODBID supplied") 
    6364        elif self._contentType == 'plain_video': 
    6465            if not self._videoFormat: 
     
    7273 
    7374    def _getAnswer(self): 
    74         # Get the MARC XML and submit it to CDS 
     75        # Get the MARC XML and submit it to CDS, 
     76        # then update micala database Status table showing task completed 
    7577        resultCreateCDSRecord = createCDSRecord(self._aw, 
    7678                                                self._IndicoID, 
     
    8385            return "CDS record creation aborted." 
    8486 
    85         # Update the micala database 
     87        # Create lecture.xml and submit to micala server, 
     88        # then update micala database Status table showing task completed 
     89        # (this only makes sense if it is a web lecture) 
     90        if self._contentType == 'web_lecture': 
     91            resultSubmitMicalaMetadata = submitMicalaMetadata(self._aw, 
     92                                                              self._IndicoID, 
     93                                                              self._contentType, 
     94                                                              self._params.get('LOID', None), 
     95                                                              self._videoFormat, 
     96                                                              self._languages) 
     97 
     98            if resultSubmitMicalaMetadata["success"] == False: 
     99                raise RecordingManagerException("CDS record creation failed.\n%s" % resultSubmitMicalaMetadata["result"]) 
     100                return "micala metadata creation aborted." 
     101 
     102        # Update the micala database to match the LODBID with the IndicoID 
     103        # This only makes sense for web lectures, so if contentType is plain_video, 
     104        # this method does nothing. 
    86105        resultUpdateMicala = MicalaCommunication.updateMicala(self._IndicoID, 
    87106                                          self._contentType, 
    88                                           self._params.get('LOID', None)) 
     107                                          self._params.get('LODBID', None)) 
    89108 
    90109        if resultUpdateMicala["success"] == False: 
     
    100119        CollaborationPluginServiceBase._checkParams(self) #puts the Conference in self._conf 
    101120        self._IndicoID = self._params.get('IndicoID',   None) 
    102         self._LOID     = self._params.get('LOID',       None) 
    103121        self._confId   = self._params.get('conference', None) 
    104122        self._CDSID    = self._params.get('CDSID',      None) 
  • indico/MaKaC/plugins/Collaboration/RecordingManager/tpls/Extra.js

    r18bdc4 r0cb016  
    459459                        conference: '<%= ConferenceId %>', 
    460460                        IndicoID: RMselectedTalkId, 
    461                         LOID: RMselectedLODBID, 
     461                        LOID: RMLOList[RMselectedLODBID]["LOID"], 
     462                        LODBID: RMselectedLODBID, 
    462463                        videoFormat: RMvideoFormat, 
    463464                        contentType: RMviewMode, 
     
    505506                conference: '<%= ConferenceId %>', 
    506507                IndicoID: RMselectedTalkId, 
    507                 LOID: RMselectedLODBID, 
    508508                CDSID: RMTalkList[RMselectedTalkId]["CDSID"] 
    509509            }, 
  • indico/MaKaC/plugins/Collaboration/RecordingManager/tpls/NewBookingForm.tpl

    r18bdc4 r0cb016  
    221221 
    222222    // Pass the metadata we need for each talk to JavaScript 
     223    // replacing any double-quotes " with the encoded char %22, 
     224    // (otherwise any quotes in the title will cause a JavaScript error) 
    223225    var RMTalkList = { 
    224226    <% for talk in Talks: %> 
    225227    "<%= talk["IndicoID"]   %>": { 
    226         "title":      "<%= talk["title"]      %>", 
    227         "titleshort": "<%= talk["titleshort"] %>", 
    228         "type":       "<%= talk["type"]       %>", 
    229         "CDSID":      "<%= talk["CDSID"]      %>", 
    230         "CDSURL":     "<%= talk["CDSURL"]     %>", 
    231         "type":       "<%= talk["type"]       %>", 
    232         "speakers":   "<%= talk["speakers"]   %>", 
    233         "date":       "<%= talk["date"]       %>", 
    234         "date_nice":  "<%= talk["date_nice"]  %>", 
    235         "LOID":       "<%= talk["LOID"]       %>", 
    236         "IndicoLink": "<%= talk["IndicoLink"] %>" 
     228        "title":      "<%= talk["title"].replace('"', '%22')      %>", 
     229        "titleshort": "<%= talk["titleshort"].replace('"', '%22') %>", 
     230        "type":       "<%= talk["type"]                           %>", 
     231        "CDSID":      "<%= talk["CDSID"]                          %>", 
     232        "CDSURL":     "<%= talk["CDSURL"]                         %>", 
     233        "type":       "<%= talk["type"]                           %>", 
     234        "speakers":   "<%= talk["speakers"]                       %>", 
     235        "date":       "<%= talk["date"]                           %>", 
     236        "date_nice":  "<%= talk["date_nice"]                      %>", 
     237        "LOID":       "<%= talk["LOID"]                           %>", 
     238        "IndicoLink": "<%= talk["IndicoLink"]                     %>" 
    237239    }, 
    238240    <% end %> 
  • indico/MaKaC/webinterface/stylesheets/micala_lecture_conference.xsl

    r5f9652 r0cb016  
    2525<xsl:template match="event"> 
    2626 
    27 <!DOCTYPE LECTURE SYSTEM "http://www.wlap.org/dtd/lecture.dtd"> 
    28 <LECTURE TITLE="<xsl:value-of select="./title"/>"> 
    29 <xsl:for-each select="./chair/user"> 
    30 <AUTHOR><xsl:apply-templates select="./name"/></AUTHOR> 
    31 </xsl:for-each> 
    32 <DATE><xsl:value-of select="./startDate" disable-output-escaping="yes"/></DATE> 
    33 <LANGUAGE> 
    34   <xsl:choose> 
    35     <xsl:when test="./languages != ''"> 
    36       <xsl:for-each select="./languages/code"> 
    37         <LANGUAGE><xsl:value-of select="." /></LANGUAGE> 
    38       </xsl:for-each> 
    39     </xsl:when> 
    40     <xsl:otherwise> 
    41       <LANGUAGE>eng</LANGUAGE> 
    42     </xsl:otherwise> 
    43   </xsl:choose> 
    44 </LANGUAGE> 
    45 <DURATION><xsl:value-of select="./duration"/></DURATION> 
    46 <TIME><xsl:value-of select="./startDate" disable-output-escaping="yes"/></TIME> 
    47 <PAR> 
    48 <VIDEO REGION="speaker-face"> 
    49 <SWITCH> 
    50 <REF SRC="media/master.flv" TYPE="video/flash" WIDTH="240" HEIGHT="160" AUDIO="Yes" VIDEO="Yes" AVERAGERATE="" ADAPTIVE="No"/> 
    51 </SWITCH> 
    52 </VIDEO> 
    53 <SEQ TITLE="Sequence of slides" REGION="slide" > 
    54 </SEQ> 
    55 </PAR> 
     27<!--  <!DOCTYPE LECTURE SYSTEM "http://www.wlap.org/dtd/lecture.dtd">  --> 
     28<LECTURE> 
     29  <TITLE><xsl:value-of select="./title" /></TITLE> 
     30  <xsl:for-each select="./chair/user"> 
     31    <AUTHOR><xsl:apply-templates select="./name"/></AUTHOR> 
     32  </xsl:for-each> 
     33  <DATE><xsl:value-of select="substring(./startDate, 0, 11)" /></DATE> 
     34  <LANGUAGE> 
     35    <xsl:choose> 
     36      <xsl:when test="./languages != ''"> 
     37        <xsl:for-each select="./languages/code"> 
     38          <xsl:value-of select="." /> 
     39        </xsl:for-each> 
     40      </xsl:when> 
     41      <xsl:otherwise> 
     42        <LANGUAGE>eng</LANGUAGE> 
     43      </xsl:otherwise> 
     44    </xsl:choose> 
     45  </LANGUAGE> 
     46  <DURATION><xsl:value-of select="./duration"/></DURATION> 
     47  <TIME><xsl:value-of select="substring(./startDate, 12, 8)" disable-output-escaping="yes"/></TIME> 
     48  <PAR> 
     49    <VIDEO REGION="speaker-face"> 
     50    <SWITCH> 
     51      <REF SRC="media/master.flv" TYPE="video/flash" WIDTH="240" HEIGHT="160" AUDIO="Yes" VIDEO="Yes" AVERAGERATE="" ADAPTIVE="No"/> 
     52    </SWITCH> 
     53    </VIDEO> 
     54    <SEQ TITLE="Sequence of slides" REGION="slide" > 
     55      <SLIDE TYPE="DUMMY" /> 
     56    </SEQ> 
     57  </PAR> 
    5658</LECTURE> 
     59 
     60</xsl:template> 
     61 
     62<xsl:template match="name"> 
     63  <xsl:value-of select="./@last" disable-output-escaping="yes"/> 
     64  <xsl:if test="./@first!='' and ./@last!=''"> 
     65  <xsl:text disable-output-escaping="yes">, </xsl:text> 
     66  </xsl:if> 
     67  <xsl:value-of select="./@first" disable-output-escaping="yes"/> 
     68</xsl:template> 
     69 
     70</xsl:stylesheet> 
Note: See TracChangeset for help on using the changeset viewer.