add to build
authorKlaus Kaempf <kkaempf@suse.de>
Mon, 6 Feb 2006 00:28:35 +0000 (00:28 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Mon, 6 Feb 2006 00:28:35 +0000 (00:28 +0000)
zmd/backend/dbsource/DbSourceImpl.cc [new file with mode: 0644]
zmd/backend/dbsource/DbSourceImpl.h [new file with mode: 0644]
zmd/backend/dbsource/DbSources.cc
zmd/backend/query-files.cc

diff --git a/zmd/backend/dbsource/DbSourceImpl.cc b/zmd/backend/dbsource/DbSourceImpl.cc
new file mode 100644 (file)
index 0000000..d1993c2
--- /dev/null
@@ -0,0 +1,260 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* DbSourceImpl.cc
+ *
+ * Copyright (C) 2000-2002 Ximian, Inc.
+ * Copyright (C) 2005 SUSE Linux Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "DbExtract.h"
+#include "DbSourceImpl.h"
+#include "DbPackageImpl.h"
+#include "DbScriptImpl.h"
+#include "DbMessageImpl.h"
+#include "DbPatchImpl.h"
+#include "DbPatternImpl.h"
+#include "DbProductImpl.h"
+
+#include "zypp/source/SourceImpl.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/Exception.h"
+
+using namespace std;
+using namespace zypp;
+
+//---------------------------------------------------------------------------
+
+DbSourceImpl::DbSourceImpl(media::MediaAccess::Ptr & media_r, const Pathname & path_r, const std::string & alias_r)
+    : SourceImpl (media_r, path_r, alias_r)
+    , _source (Source_Ref::noSource)
+    , _pathname (path_r)
+{
+}
+
+
+void
+DbSourceImpl::createResolvables(Source_Ref source_r)
+{
+    _source = source_r;
+    extractDbFile (_pathname.asString(), this);
+}
+
+//-----------------------------------------------------------------------------
+
+Dependencies
+DbSourceImpl::createDependencies (const DbReader & parsed)
+{
+    Dependencies deps;
+
+    deps[Dep::PROVIDES] = parsed.provides;
+    deps[Dep::PREREQUIRES] = parsed.prerequires;
+    deps[Dep::REQUIRES] = parsed.requires;
+    deps[Dep::CONFLICTS] = parsed.conflicts;
+    deps[Dep::OBSOLETES] = parsed.obsoletes;
+    deps[Dep::RECOMMENDS] = parsed.recommends;
+    deps[Dep::SUGGESTS] = parsed.suggests;
+    deps[Dep::FRESHENS] = parsed.freshens;
+    deps[Dep::ENHANCES] = parsed.enhances;
+
+    return deps;
+}
+
+
+Package::Ptr
+DbSourceImpl::createPackage (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbPackageImpl> impl(new DbPackageImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Package::Ptr package = detail::makeResolvableFromImpl(dataCollect, impl);
+       return package;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create package object";
+    }
+    return NULL;
+}
+
+
+Message::Ptr
+DbSourceImpl::createMessage (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbMessageImpl> impl(new DbMessageImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Message::Ptr message = detail::makeResolvableFromImpl(dataCollect, impl);
+       return message;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create message object";
+    }
+    return NULL;
+}
+
+
+Script::Ptr
+DbSourceImpl::createScript (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbScriptImpl> impl(new DbScriptImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Script::Ptr script = detail::makeResolvableFromImpl(dataCollect, impl);
+       return script;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create script object";
+    }
+    return NULL;
+}
+
+
+Patch::Ptr
+DbSourceImpl::createPatch (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbPatchImpl> impl(new DbPatchImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Patch::Ptr patch = detail::makeResolvableFromImpl(dataCollect, impl);
+       return patch;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create patch object";
+    }
+    return NULL;
+}
+
+
+Pattern::Ptr
+DbSourceImpl::createPattern (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbPatternImpl> impl(new DbPatternImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Pattern::Ptr pattern = detail::makeResolvableFromImpl(dataCollect, impl);
+       return pattern;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create pattern object";
+    }
+    return NULL;
+}
+
+
+Product::Ptr
+DbSourceImpl::createProduct (const DbReader & parsed)
+{
+    try
+    {
+       shared_ptr<DbProductImpl> impl(new DbProductImpl(_source, parsed));
+
+       // Collect basic Resolvable data
+       NVRAD dataCollect( parsed.name,
+                       Edition( parsed.version, parsed.release, parsed.epoch ),
+                       Arch( parsed.arch ),
+                       createDependencies (parsed));
+       Product::Ptr product = detail::makeResolvableFromImpl(dataCollect, impl);
+       return product;
+    }
+    catch (const Exception & excpt_r)
+    {
+       ERR << excpt_r << endl;
+       throw "Cannot create product object";
+    }
+    return NULL;
+}
+
+//-----------------------------------------------------------------------------
+
+void
+DbSourceImpl::parserCallback (const DbReader & parsed)
+{
+  try {
+    if (parsed.kind == ResTraits<Package>::kind) {
+       Package::Ptr p = createPackage (parsed);
+       _store.insert (p);
+    }
+    else if (parsed.kind == ResTraits<Message>::kind) {
+       Message::Ptr m = createMessage (parsed);
+       _store.insert (m);
+    }
+    else if (parsed.kind == ResTraits<Script>::kind) {
+       Script::Ptr s = createScript (parsed);
+       _store.insert (s);
+    }
+    else if (parsed.kind == ResTraits<Patch>::kind) {
+       Patch::Ptr p = createPatch (parsed);
+       _store.insert (p);
+    }
+    else if (parsed.kind == ResTraits<Pattern>::kind) {
+       Pattern::Ptr p = createPattern (parsed);
+       _store.insert (p);
+    }
+    else if (parsed.kind == ResTraits<Product>::kind) {
+       Product::Ptr p = createProduct (parsed);
+       _store.insert (p);
+    }
+    else {
+       ERR << "Unsupported kind " << parsed.kind << endl;
+    }
+  }
+  catch (const Exception & excpt_r)
+  {
+    ZYPP_CAUGHT (excpt_r);
+  }
+}
+
+//-----------------------------------------------------------------------------
+
diff --git a/zmd/backend/dbsource/DbSourceImpl.h b/zmd/backend/dbsource/DbSourceImpl.h
new file mode 100644 (file)
index 0000000..ae8f914
--- /dev/null
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* DbSourceImpl.h
+ *
+ * Copyright (C) 2000-2002 Ximian, Inc.
+ * Copyright (C) 2005 SUSE Linux Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef ZYPP_ZMD_BACKEND_DBSOURCEIMPL_H
+#define ZYPP_ZMD_BACKEND_DBSOURCEIMPL_H
+
+#include <iosfwd>
+#include <string>
+
+#include "zypp/source/SourceImpl.h"
+
+class DbReader;
+//#include "DbReader.h"
+
+#include "zypp/Package.h"
+#include "zypp/Message.h"
+#include "zypp/Script.h"
+#include "zypp/Patch.h"
+#include "zypp/Product.h"
+#include "zypp/Selection.h"
+#include "zypp/Pattern.h"
+
+namespace zypp {
+        
+///////////////////////////////////////////////////////////////////
+//
+//     CLASS NAME : DbSourceImpl
+
+class DbSourceImpl : public zypp::source::SourceImpl {
+
+  public:
+
+    /** Default ctor */
+    DbSourceImpl(media::MediaAccess::Ptr & media_r, const Pathname & path_r = "/", const std::string & alias_r = "");
+
+    virtual const bool valid() const
+    { return true; }
+
+    Package::Ptr createPackage (const DbReader & data);
+    Message::Ptr createMessage (const DbReader & data);
+    Script::Ptr  createScript (const DbReader & data);
+    Patch::Ptr   createPatch (const DbReader & data);
+    Pattern::Ptr createPattern (const DbReader & data);
+    Product::Ptr createProduct (const DbReader & data);
+
+    Dependencies createDependencies (const DbReader & data);
+
+  private:
+    Source_Ref _source;
+    const Pathname _pathname;
+    void createResolvables(Source_Ref source_r);
+};
+
+
+} // namespace zypp
+
+#endif // ZYPP_ZMD_BACKEND_DBSOURCEIMPL_H
index 8e29a7c..de3947f 100644 (file)
 #include "zypp/base/Logger.h"
 #include "zypp/base/Exception.h"
 
+#include "zypp/Source.h"
+#include "zypp/SourceFactory.h"
+#include "zypp/SourceManager.h"
+#include "zypp/source/SourceImpl.h"
+
+#include "zypp/media/MediaManager.h"
+
 #include "DbSources.h"
+#include "DbSourceImpl.h"
 #include <sqlite3.h>
 
 using namespace std;
@@ -54,6 +62,9 @@ DbSources::sources (bool refresh)
 
     _sources.clear();
 
+    media::MediaManager mmgr;
+    media::MediaId mediaid = mmgr.open(Url("file://"));
+
     const char *query =
         "SELECT id, name, alias, description, priority, priority_unsubd "
         "FROM catalogs";
@@ -66,35 +77,35 @@ DbSources::sources (bool refresh)
     }
 
     while ((rc = sqlite3_step (handle)) == SQLITE_ROW) {
-       MIL << "id " << (const char *) sqlite3_column_text (handle, 0)
-           << "name " << (const char *) sqlite3_column_text (handle, 1)
-           << "alias " << (const char *) sqlite3_column_text (handle, 2)
-           << "desc " << (const char *) sqlite3_column_text (handle, 3)
-           << "prio " << sqlite3_column_int (handle, 4)
-           << "pr. un" << sqlite3_column_int (handle, 5)
+       string id ((const char *) sqlite3_column_text (handle, 0));
+       string name ((const char *) sqlite3_column_text (handle, 1));
+        string alias ((const char *) sqlite3_column_text (handle, 2));
+        string desc ((const char *) sqlite3_column_text (handle, 3));
+       unsigned priority = sqlite3_column_int (handle, 4);
+       unsigned priority_unsub = sqlite3_column_int (handle, 5);
+
+       MIL << "id " << id
+           << ", name " << name
+           << ", alias " << alias
+           << ", desc " << desc
+           << ", prio " << priority
+           << ", pr. un" << priority_unsub
            << endl;
-
 #if 0
+
        try {
 
-           media::MediaManager mmgr;
-           media::MediaId mediaid = mmgr.open(Url("file://"));
-           Source_Ref::Impl_Ptr impl = new HelixSourceImpl (mediaid, pathname, alias);
+           Source_Ref::Impl_Ptr impl = new DbSourceImpl (mediaid, pathname, alias);
+           impl->setId( id );
+           impl->setName( name );
+           impl->setPriority( priority );
+           impl->setPriorityUnsubscribed( priority_unsub );
            SourceFactory _f;
            Source_Ref s = _f.createFrom( impl );
        }
        catch (Exception & excpt_r) {
            ZYPP_CAUGHT(excpt_r);
        }
-
-        ch = rc_channel_new ((const char *) sqlite3_column_text (handle, 0),
-                             (const char *) sqlite3_column_text (handle, 1),
-                             (const char *) sqlite3_column_text (handle, 2),
-                             (const char *) sqlite3_column_text (handle, 3));
-        rc_channel_set_priorities (ch,
-                                   sqlite3_column_int (handle, 4),
-                                   sqlite3_column_int (handle, 5));
-
         if (!strcmp (rc_channel_get_id (ch), "@system")) {
             rc_channel_set_system (ch);
             rc_channel_set_hidden (ch);
index 4f9b00f..4cab23b 100644 (file)
@@ -23,12 +23,12 @@ static ResolvableList
 query_file (Target_Ptr target, const char *path)
 {
     ResolvableList resolvables;
-
-    Resolvable::constPtr resolvable = target->whoOwnsFile (path);
+#if 0
+    Resolvable::constPtr resolvable = target->rpm-qp (path);   // FIXME, needs rpm -qp
     if (resolvable != NULL) {
        resolvables.push_back (resolvable);
     }
-
+#endif
     return resolvables;
 }
 
@@ -164,7 +164,7 @@ main (int argc, char **argv)
 
     ResolvableList resolvables = query (God->target(), argv[2], argc == 4 ? argv[3] : NULL);
     if (!resolvables.empty()) {
-       write_resolvables_to_db (argv[1], resolvables, true);
+//     write_resolvables_to_db (argv[1], resolvables, true);
     }
 
     return 0;