ZConfig.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/base/InputStream.h"
00015 #include "zypp/base/String.h"
00016 
00017 #include "zypp/ZConfig.h"
00018 #include "zypp/ZYppFactory.h"
00019 #include "zypp/PathInfo.h"
00020 #include "zypp/parser/IniDict.h"
00021 
00022 using namespace std;
00023 using namespace zypp::filesystem;
00024 using namespace zypp::parser;
00025 
00027 namespace zypp
00028 { 
00029 
00031   //
00032   //    CLASS NAME : ZConfig::Impl
00033   //
00039   class ZConfig::Impl
00040   {
00041     public:
00042       Impl()
00043         : download_use_patchrpm( true )
00044         , download_use_deltarpm( true )
00045       {
00046         MIL << "ZConfig singleton created." << endl;
00047 
00048         // ZYPP_CONF might override /etc/zypp/zypp.conf
00049         const char *env_confpath = getenv( "ZYPP_CONF" );
00050         PathInfo confpath( env_confpath ? env_confpath : "/etc/zypp/zypp.conf" );
00051 
00052         if ( ! ( confpath.isFile() && confpath.isR() ) )
00053         {
00054           MIL << "Unable to read " << confpath << ": using defaults instead." << endl;
00055           return;
00056         }
00057 
00058         MIL << "Reading " << confpath << endl;
00059         parser::IniDict dict;
00060         dict.read( confpath.path() );
00061 
00062         for ( IniDict::section_const_iterator sit = dict.sectionsBegin();
00063               sit != dict.sectionsEnd();
00064               ++sit )
00065         {
00066           string section(*sit);
00067           //MIL << section << endl;
00068           for ( IniDict::entry_const_iterator it = dict.entriesBegin(*sit);
00069                 it != dict.entriesEnd(*sit);
00070                 ++it )
00071           {
00072             string entry(it->first);
00073             string value(it->second);
00074             //DBG << (*it).first << "=" << (*it).second << endl;
00075             if ( section == "main" )
00076             {
00077               if( entry == "download.use_patchrpm" )
00078               {
00079                 download_use_patchrpm = str::strToBool( value, download_use_patchrpm );
00080               }
00081               else if ( entry == "download.use_deltarpm" )
00082               {
00083                 download_use_deltarpm = str::strToBool( value, download_use_deltarpm );
00084               }
00085             }
00086           }
00087         }
00088       }
00089 
00090       ~Impl()
00091       {}
00092 
00093     public:
00094       bool download_use_patchrpm;
00095       bool download_use_deltarpm;
00096   };
00098 
00100   //
00101   //    METHOD NAME : ZConfig::instance
00102   //    METHOD TYPE : ZConfig &
00103   //
00104   ZConfig & ZConfig::instance()
00105   {
00106     static ZConfig _instance; // The singleton
00107     return _instance;
00108   }
00109 
00111   //
00112   //    METHOD NAME : ZConfig::ZConfig
00113   //    METHOD TYPE : Ctor
00114   //
00115   ZConfig::ZConfig()
00116   : _pimpl( new Impl )
00117   {}
00118 
00120   //
00121   //    METHOD NAME : ZConfig::~ZConfig
00122   //    METHOD TYPE : Dtor
00123   //
00124   ZConfig::~ZConfig( )
00125   {}
00126 
00127   bool ZConfig::download_use_patchrpm() const
00128   { return _pimpl->download_use_patchrpm; }
00129 
00130   bool ZConfig::download_use_deltarpm() const
00131   { return _pimpl->download_use_deltarpm; }
00132 
00133 
00135 } // namespace zypp

Generated on Thu Apr 24 02:25:04 2008 for zypp by  doxygen 1.4.6