def add_transaction(request, doc, feed, entry, first): """Each transaction is an entry. We have non-trivial content, so we can omit summary elements. """ e = doc.createElement("entry") pfmri, op_type, op_time, metadata = entry # Generate a 'tag' uri, to uniquely identify the entry, using the fmri. i = xmini.Text() i.replaceWholeText(fmri_to_taguri(pfmri)) eid = doc.createElement("id") eid.appendChild(i) e.appendChild(eid) # Attempt to determine the operation that was performed and generate # the entry title and content. if op_type == catalog.CatalogUpdate.ADD: if pfmri != first: # XXX renaming, obsoletion? # If this fmri is not the same as the oldest one # for the FMRI's package stem, assume this is a # newer version of that package. op_title, op_content = update_op else: op_title, op_content = add_op elif op_type == catalog.CatalogUpdate.REMOVE: op_title, op_content = add_op else: # XXX Better way to reflect an error? (Aborting will make a # non-well-formed document.) op_title = "Unknown Operation" op_content = "{0} was changed in the repository." # Now add a title for our entry. etitle = doc.createElement("title") ti = xmini.Text() ti.replaceWholeText(" ".join([op_title, pfmri.get_pkg_stem()])) etitle.appendChild(ti) e.appendChild(etitle) # Indicate when the entry was last updated (in this case, when the # package was added). eu = doc.createElement("updated") ut = xmini.Text() ut.replaceWholeText(dt_to_rfc3339_str(op_time)) eu.appendChild(ut) e.appendChild(eu) # Link to the info output for the given package FMRI. e_uri = misc.get_rel_path(request, "info/0/{0}".format(quote(str(pfmri)))) l = doc.createElement("link") l.setAttribute("rel", "alternate") l.setAttribute("href", e_uri) e.appendChild(l) # Using the description for the operation performed, add the FMRI and # tag information. content_text = op_content.format(pfmri) co = xmini.Text() co.replaceWholeText(content_text) ec = doc.createElement("content") ec.appendChild(co) e.appendChild(ec) feed.appendChild(e)
def add_transaction(request, scfg, rcfg, doc, feed, txn, fmris): """Each transaction is an entry. We have non-trivial content, so we can omit summary elements. """ e = doc.createElement("entry") tag, fmri_str = txn["catalog"].split() f = fmri.PkgFmri(fmri_str) # Generate a 'tag' uri, to uniquely identify the entry, using the fmri. i = xmini.Text() i.replaceWholeText(fmri_to_taguri(rcfg, f)) eid = doc.createElement("id") eid.appendChild(i) e.appendChild(eid) # Attempt to determine the operation that was performed and generate # the entry title and content. if txn["operation"] in operations: op_title, op_content = operations[txn["operation"]] else: # XXX Better way to reflect an error? (Aborting will make a # non-well-formed document.) op_title = "Unknown Operation" op_content = "%s was changed in the repository." if txn["operation"] == "+": # Get all FMRIs matching the current FMRI's package name. matches = fmris[f.pkg_name] if len(matches["versions"]) > 1: # Get the oldest fmri. of = matches[str(matches["versions"][0])][0] # If the current fmri isn't the oldest one, then this # is an update to the package. if f != of: # If there is more than one matching FMRI, and # it isn't the same version as the oldest one, # we can assume that this is an update to an # existing package. op_title, op_content = operations["U"] # Now add a title for our entry. etitle = doc.createElement("title") ti = xmini.Text() ti.replaceWholeText(" ".join([op_title, fmri_str])) etitle.appendChild(ti) e.appendChild(etitle) # Indicate when the entry was last updated (in this case, when the # package was added). eu = doc.createElement("updated") ut = xmini.Text() ut.replaceWholeText(ults_to_rfc3339_str(txn["timestamp"])) eu.appendChild(ut) e.appendChild(eu) # Link to the info output for the given package FMRI. e_uri = get_rel_path(request, 'info/0/%s' % f.get_url_path()) l = doc.createElement("link") l.setAttribute("rel", "alternate") l.setAttribute("href", e_uri) e.appendChild(l) # Using the description for the operation performed, add the FMRI and # tag information. content_text = op_content % fmri_str if tag == "C": content_text += " This version is tagged as critical." co = xmini.Text() co.replaceWholeText(content_text) ec = doc.createElement("content") ec.appendChild(co) e.appendChild(ec) feed.appendChild(e)
def add_transaction(request, doc, feed, entry, first): """Each transaction is an entry. We have non-trivial content, so we can omit summary elements. """ e = doc.createElement("entry") pfmri, op_type, op_time, metadata = entry # Generate a 'tag' uri, to uniquely identify the entry, using the fmri. i = xmini.Text() i.replaceWholeText(fmri_to_taguri(pfmri)) eid = doc.createElement("id") eid.appendChild(i) e.appendChild(eid) # Attempt to determine the operation that was performed and generate # the entry title and content. if op_type == catalog.CatalogUpdate.ADD: if pfmri != first: # XXX renaming, obsoletion? # If this fmri is not the same as the oldest one # for the FMRI's package stem, assume this is a # newer version of that package. op_title, op_content = update_op else: op_title, op_content = add_op elif op_type == catalog.CatalogUpdate.REMOVE: op_title, op_content = add_op else: # XXX Better way to reflect an error? (Aborting will make a # non-well-formed document.) op_title = "Unknown Operation" op_content = "%s was changed in the repository." # Now add a title for our entry. etitle = doc.createElement("title") ti = xmini.Text() ti.replaceWholeText(" ".join([op_title, pfmri.get_pkg_stem()])) etitle.appendChild(ti) e.appendChild(etitle) # Indicate when the entry was last updated (in this case, when the # package was added). eu = doc.createElement("updated") ut = xmini.Text() ut.replaceWholeText(dt_to_rfc3339_str(op_time)) eu.appendChild(ut) e.appendChild(eu) # Link to the info output for the given package FMRI. e_uri = get_rel_path(request, "info/0/%s" % urllib.quote(str(pfmri))) l = doc.createElement("link") l.setAttribute("rel", "alternate") l.setAttribute("href", e_uri) e.appendChild(l) # Using the description for the operation performed, add the FMRI and # tag information. content_text = op_content % pfmri co = xmini.Text() co.replaceWholeText(content_text) ec = doc.createElement("content") ec.appendChild(co) e.appendChild(ec) feed.appendChild(e)