]> git.mxchange.org Git - simgear.git/commitdiff
pkgutil can show detailed info about a package.
authorJames Turner <zakalawe@mac.com>
Sat, 2 Mar 2013 17:02:08 +0000 (17:02 +0000)
committerJames Turner <zakalawe@mac.com>
Sat, 2 Mar 2013 17:02:08 +0000 (17:02 +0000)
simgear/package/Package.cxx
simgear/package/Package.hxx
simgear/package/pkgutil.cxx

index cc118e70fe8adca336a2ae4f5711e414c7bcfb9f..7e0b1853ba8abf4714966b042a1d791cab0a5e54 100644 (file)
@@ -112,6 +112,11 @@ unsigned int Package::revision() const
     return m_props->getIntValue("revision");
 }
     
+std::string Package::name() const
+{
+    return m_props->getStringValue("name");
+}
+
 std::string Package::description() const
 {
     return getLocalisedProp("decription");
index fe0894e13732c2af2270fbd75d8a6468c1e34ed4..19a69434ac392e8d28e6516d1d2e4e47ac64def4 100644 (file)
@@ -51,6 +51,12 @@ public:
     
     std::string id() const;
     
+    /**
+     * human-readable name - note this is probably not localised,
+     * although this is not ruled out for the future.
+     */
+    std::string name() const;
+    
     /**
      * syntactic sugar to get the localised description
      */
index f0f19d76851f512d0fe770f28ba772cd25f63cdf..837f0d71d9b1a7a5e4fbb9472a8ddd40449e1506 100644 (file)
@@ -46,7 +46,7 @@ public:
     virtual void startInstall(pkg::Install* aInstall)
     {
         _lastPercent = 999;
-        cout << "starting install of " << aInstall->package()->description() << endl;
+        cout << "starting install of " << aInstall->package()->name() << endl;
     }
     
     virtual void installProgress(pkg::Install* aInstall, unsigned int bytes, unsigned int total)
@@ -62,18 +62,56 @@ public:
     
     virtual void finishInstall(pkg::Install* aInstall)
     {
-        cout << "done install of " << aInstall->package()->description() << endl;
+        cout << "done install of " << aInstall->package()->name() << endl;
     }
 
     virtual void failedInstall(pkg::Install* aInstall, FailureCode aReason)
     {
-        cerr << "failed install of " << aInstall->package()->description() << endl;
+        cerr << "failed install of " << aInstall->package()->name() << endl;
     }
 private:
     unsigned int _lastPercent;
     
 };
 
+void printRating(pkg::Package* pkg, const std::string& aRating, const std::string& aLabel)
+{
+    SGPropertyNode* ratings = pkg->properties()->getChild("rating");
+    cout << "\t" << aLabel << ":" << ratings->getIntValue(aRating) << endl;
+}
+
+void printPackageInfo(pkg::Package* pkg)
+{
+    cout << "Package:" << pkg->catalog()->id() << "." << pkg->id() << endl;
+    cout << "Revision:" << pkg->revision() << endl;
+    cout << "Name:" << pkg->name() << endl;
+    cout << "Description:" << pkg->description() << endl;
+    cout << "Long description:\n" << pkg->getLocalisedProp("long-description") << endl << endl;
+    
+    if (pkg->properties()->hasChild("author")) {
+        cout << "Authors:" << endl;
+        BOOST_FOREACH(SGPropertyNode* author, pkg->properties()->getChildren("author")) {
+            if (author->hasChild("name")) {
+                cout << "\t" << author->getStringValue("name") << endl;
+                
+            } else {
+                // simple author structure
+                cout << "\t" << author->getStringValue() << endl;
+            }
+        
+            
+        }
+        
+        cout << endl;
+    }
+    
+    cout << "Ratings:" << endl;
+    printRating(pkg, "fdm",     "Flight-model    ");
+    printRating(pkg, "cockpit", "Cockpit         ");
+    printRating(pkg, "model",   "3D model        ");
+    printRating(pkg, "systems", "Aircraft systems");
+}
+
 int main(int argc, char** argv)
 {
 
@@ -92,7 +130,7 @@ int main(int argc, char** argv)
         std::string url(argv[2]);
         pkg::Catalog::createFromUrl(root, url);
     } else if (!strcmp(argv[1], "refresh")) {
-        root->refresh();
+        root->refresh(true);
     } else if (!strcmp(argv[1], "install")) {
         pkg::Package* pkg = root->getPackageById(argv[2]);
         if (!pkg) {
@@ -139,6 +177,14 @@ int main(int argc, char** argv)
         BOOST_FOREACH(pkg::Package* p, updates) {
             cout << "\t" << p->id() << " " << p->getLocalisedProp("name") << endl;
         }
+    } else if (!strcmp(argv[1], "info")) {
+        pkg::Package* pkg = root->getPackageById(argv[2]);
+        if (!pkg) {
+            cerr << "unknown package:" << argv[2] << endl;
+            return EXIT_FAILURE;
+        }
+    
+        printPackageInfo(pkg);
     } else {
         cerr << "unknown command:" << argv[1] << endl;
         return EXIT_FAILURE;