RepoVariables.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00009 
00010 #include <iostream>
00011 #include <map>
00012 #include <algorithm>
00013 #include "zypp/base/String.h"
00014 #include "zypp/repo/RepoException.h"
00015 #include "zypp/ZConfig.h"
00016 #include "zypp/ZYppFactory.h"
00017 #include "RepoVariables.h"
00018 
00019 using namespace std;
00020 
00021 namespace zypp
00022 {
00023 namespace repo
00024 {
00025 
00026 RepoVariablesStringReplacer::RepoVariablesStringReplacer()
00027 {}
00028 
00029 RepoVariablesStringReplacer::~RepoVariablesStringReplacer()
00030 {}
00031 
00032 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const
00033 {
00034   string newvalue(value);
00035 
00036   // $arch
00037   newvalue = str::gsub( newvalue,
00038                         "$arch",
00039                         ZConfig::instance().systemArchitecture().asString() );
00040   // $basearch
00041 
00042   Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
00043   Arch::CompatSet::const_iterator it = cset.end();
00044   --it;
00045   // now at noarch
00046   --it;
00047 
00048   Arch basearch = *it;
00049   if ( basearch == Arch_noarch )
00050   {
00051     basearch = ZConfig::instance().systemArchitecture();
00052   }
00053 
00054   newvalue = str::gsub( newvalue,
00055                         "$basearch",
00056                         basearch.asString() );
00057 
00058   // only replace $releasever if the target is
00059   // initialized
00060   if ( getZYpp()->getTarget() )
00061   {
00062       newvalue = str::gsub( newvalue,
00063                             "$releasever",
00064                             getZYpp()->target()->distributionVersion() );
00065   }
00066   
00067   return newvalue;
00068 }
00069 
00071 
00072 RepoVariablesUrlReplacer::RepoVariablesUrlReplacer()
00073 {}
00074 
00075 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer()
00076 {}
00077 
00078 /*
00079  * Replaces '$arch' and '$basearch' in the path and query part of the URL
00080  * with the global ZYpp values. Examples:
00081  *
00082  * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/
00083  * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386
00084  */
00085 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const
00086 {
00087   Url newurl = value;
00088   RepoVariablesStringReplacer replacer;
00089   newurl.setPathData(replacer(value.getPathData()));
00090   newurl.setQueryString(replacer(value.getQueryString()));
00091 
00092   return newurl;
00093 }
00094 
00095 } // ns repo
00096 } // ns zypp
00097 
00098 // vim: set ts=2 sts=2 sw=2 et ai:

doxygen