backup: reading script data + comments
authorJan Kupec <jkupec@suse.cz>
Fri, 18 May 2007 10:22:34 +0000 (10:22 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 18 May 2007 10:22:34 +0000 (10:22 +0000)
zypp/data/ResolvableData.h
zypp/parser/yum/PatchFileReader.cc
zypp/parser/yum/PatchFileReader.h

index 82e8462..f1fd1e8 100644 (file)
@@ -206,6 +206,9 @@ namespace data
       /** Does the patch affect the package manager itself? */
       DefaultIntegral<bool,false> affectsPkgManager;
 
+      /** TODO Don't know what this is, but it's defined in patch.rnc */
+      std::string updateScript;
+
       /**
        * The set of all atoms building the patch. These can be either
        * \ref Atom, \ref Message or \ref Script.
index f4dff09..b00a0e2 100644 (file)
@@ -34,6 +34,17 @@ namespace zypp
 
   // --------------------------------------------------------------------------
 
+  /*
+   * xpath and multiplicity of processed nodes are included in the code
+   * for convenience:
+   * 
+   * // xpath: <xpath> (?|*|+)
+   * 
+   * if multiplicity is ommited, then the node has multiplicity 'one'. 
+   */
+
+  // --------------------------------------------------------------------------
+
   bool PatchFileReader::consumeNode(Reader & reader_r)
   {
     if (isBeingProcessed(tag_atoms) && consumeAtomsNode(reader_r))
@@ -76,10 +87,11 @@ namespace zypp
         _patch->description.setText(reader_r.nodeText().asString(), locale);
         return true;
       }
-      
-      // xpath: /patch/licence-to-confirm
+
+      // xpath: /patch/licence-to-confirm (*)
       if (reader_r->name() == "license-to-confirm")
       {
+        // TODO support several licenses in several languages?
         Locale locale(reader_r->getAttribute("lang").asString());
         _patch->licenseToConfirm.setText(reader_r.nodeText().asString(), locale);
         return true;
@@ -105,29 +117,34 @@ namespace zypp
         return true;
       }
 
-      // xpath: /patch/reboot-needed
+      // xpath: /patch/reboot-needed (?)
       if (reader_r->name() == "reboot-needed")
       {
         _patch->rebootNeeded = true;
         return true;
       }
 
-      // xpath: /patch/package-manager
+      // xpath: /patch/package-manager (?)
       if (reader_r->name() == "package-manager")
       {
         _patch->affectsPkgManager = true;
         return true;
       }
 
-      // TODO xpath: /patch/update-script
+      // xpath: /patch/update-script (?)
+      if (reader_r->name() == "update-script")
+      {
+        _patch->updateScript = reader_r.nodeText().asString();
+      }
 
-      // xpath: /patch/atoms
+      // xpath: /patch/atoms (+)
       if (reader_r->name() == "atoms")
       {
         // remember that we are processing atoms from now on
         // xpath: /patch/atoms/*
         tag(tag_atoms);
-        // no need to further process this node so not calling consumeAtomsNode();
+        // no need to further process this node so not calling
+        // consumeAtomsNode() here
         return true;
       }
     }
@@ -208,7 +225,7 @@ namespace zypp
       if (reader_r->name() == "package")
       {
         data::Atom_Ptr atom_ptr = new data::Atom;
-        copyAtomFromTmpObj(atom_ptr); 
+        copyPackageAtomFromTmpObj(atom_ptr); 
         _patch->atoms.insert(atom_ptr);
 
         DBG << "Atom " << atom_ptr->name << " " << atom_ptr->edition << " successfully read." << endl;  
@@ -276,7 +293,7 @@ namespace zypp
 
   bool PatchFileReader::consumeMessageNode(Reader & reader_r)
   {
-    if (FileReaderBase::consumeDependency(reader_r, _tmpResObj->deps))
+    if (consumeDependency(reader_r, _tmpResObj->deps))
       return true;
 
     if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
@@ -325,8 +342,18 @@ namespace zypp
 
   bool PatchFileReader::consumeScriptNode(Reader & reader_r)
   {
+    if (consumeDependency(reader_r, _tmpResObj->deps))
+      return true;
+
     if (reader_r->nodeType() == XML_READER_TYPE_ELEMENT)
     {
+      data::Script_Ptr script = dynamic_pointer_cast<data::Script>(_tmpResObj);
+      if (!script)
+      {
+        WAR << "data::Script object expected, but not found" << endl;
+        return true;
+      }
+
       // xpath: /patch/atoms/script/yum:name
       if (reader_r->name() == "yum:name")
       {
@@ -342,6 +369,58 @@ namespace zypp
                                     reader_r->getAttribute("epoch").asString());
         return true;
       }
+
+      // xpath: /patch/atoms/script/do
+      if (reader_r->name() == "do")
+      {
+        script->doScript = reader_r.nodeText().asString();
+        return true;
+      }
+
+      // xpath: /patch/atoms/script/undo
+      if (reader_r->name() == "undo")
+      {
+        script->undoScript = reader_r.nodeText().asString();
+        return true;
+      }
+
+      // TODO xpath: /patch/atoms/script/do-location
+      if (reader_r->name() == "do-location")
+      {
+        // xsd:anyURI
+//        script->doScriptLocation.filepath = reader_r->getAttribute("xml:base").asString();
+        // xsd:anyURI
+//        script->doScriptLocation.? = reader_r->getAttribute("href").asString();
+        return true;
+      }
+
+      // xpath: /patch/atoms/script/do-checksum
+      if (reader_r->name() == "do-checksum")
+      {
+        script->doScriptLocation.fileChecksum = CheckSum(
+                            reader_r->getAttribute("type").asString(),
+                            reader_r.nodeText().asString());
+        return true;
+      }
+
+      // TODO xpath: /patch/atoms/script/undo-location
+      if (reader_r->name() == "undo-location")
+      {
+        // xsd:anyURI
+//        script->undoScriptLocation.filepath = reader_r->getAttribute("xml:base").asString();
+        // xsd:anyURI
+//        script->undoScriptLocation.? = reader_r->getAttribute("href").asString();
+        return true;
+      }
+
+      // xpath: /patch/atoms/script/undo-checksum
+      if (reader_r->name() == "undo-checksum")
+      {
+        script->undoScriptLocation.fileChecksum = CheckSum(
+                            reader_r->getAttribute("type").asString(),
+                            reader_r.nodeText().asString());
+        return true;
+      }
     }
 
     else if (reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT)
@@ -376,7 +455,7 @@ namespace zypp
 
   // --------------------------------------------------------------------------
 
-  void PatchFileReader::copyAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const
+  void PatchFileReader::copyPackageAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const
   {
     atom_ptr->name = _tmpResObj->name;
     atom_ptr->edition = _tmpResObj->edition;
index 529d207..6ac1e3a 100644 (file)
@@ -24,19 +24,27 @@ namespace zypp
 
 
   /**
+   * Reader of patch.xml files conforming to RNC/RNG definition located
+   * in zypp/parser/yum/schema/patch.rn(c|g).
    * 
+   * \see zypp::data::Patch
+   * \see zypp::parser::xml::Reader
    */
   class PatchFileReader : FileReaderBase
   {
   public:
 
     /**
-     * Callback definition.
+     * Consumer callback definition. Function which will process the read
+     * data must be of this type.
      */
     typedef function<bool(const data::Patch_Ptr &)> ProcessPatch;
 
     /**
-     * 
+     * CTOR. Creates also \ref xml::Reader and starts reading.
+     *
+     * \param patch_file patch.xml file to read.
+     * \param callback Function which will process read data.
      */
     PatchFileReader(const Pathname & patch_file, ProcessPatch callback);
 
@@ -53,15 +61,30 @@ namespace zypp
     bool consumeNode(xml::Reader & reader_r);
 
     /**
-     * Process atoms node and all of its children.
+     * Process <tt>atoms</tt> node and all of its children.
      * 
+     * \param reader_r XML file reader reading the patch file.
      * \return true if current node has been completely processed, false
      *         if additional processing is required outside of the method. 
      */
     bool consumeAtomsNode(xml::Reader & reader_r);
 
+    /**
+     * Process <tt>message</tt> node and all of its children.
+     * 
+     * \param reader_r XML file reader reading the patch file.
+     * \return true if current node has been completely processed, false
+     *         if additional processing is required outside of the method. 
+     */
     bool consumeMessageNode(xml::Reader & reader_r);
 
+    /**
+     * Process <tt>script</tt> node and all of its children.
+     * 
+     * \param reader_r XML file reader reading the patch file.
+     * \return true if current node has been completely processed, false
+     *         if additional processing is required outside of the method. 
+     */
     bool consumeScriptNode(xml::Reader & reader_r);
 
     /**
@@ -71,9 +94,17 @@ namespace zypp
      */
     data::Patch_Ptr handoutPatch();
 
+    /**
+     * Creates a new \ref data::ResObject_Ptr, swap its contents with
+     * \ref _tmpResObj and inserts it into <tt>_patch.atoms</tt>. Used
+     * after an atom is read.
+     */
     void saveAtomInPatch();
-    
-    void copyAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const;
+
+    /**
+     * 
+     */
+    void copyPackageAtomFromTmpObj(data::Atom_Ptr & atom_ptr) const;
 
   private:
     /**