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   sysarch = Arch_empty;
00029   basearch = Arch_empty;
00030 }
00031 
00032 RepoVariablesStringReplacer::~RepoVariablesStringReplacer()
00033 {}
00034 
00035 void RepoVariablesStringReplacer::resetVarCache( void )
00036 {
00037   sysarch = Arch_empty;
00038   basearch = Arch_empty;
00039   releasever = "";
00040 }
00041 
00042 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const
00043 {
00044   string newvalue(value);
00045 
00046   // $arch
00047   if( sysarch.empty() )
00048     sysarch = ZConfig::instance().systemArchitecture();
00049 
00050   newvalue = str::gsub( newvalue, "$arch", sysarch.asString() );
00051 
00052   // $basearch
00053   if( basearch.empty() )
00054     basearch = sysarch.baseArch();
00055 
00056   newvalue = str::gsub( newvalue, "$basearch", basearch.asString() );
00057 
00058   // $releasever (Target::distributionVersion assumes root=/ if target not initialized)
00059   if ( newvalue.find("$releasever") != string::npos ) {
00060     if( releasever.empty() )
00061       releasever = Target::distributionVersion(Pathname()/*guess*/);
00062 
00063     newvalue = str::gsub( newvalue, "$releasever", releasever );
00064   } 
00065 
00066   return newvalue;
00067 }
00068 
00070 
00071 RepoVariablesUrlReplacer::RepoVariablesUrlReplacer()
00072 {}
00073 
00074 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer()
00075 {}
00076 
00077 void RepoVariablesUrlReplacer::resetVarCache( void )
00078 {
00079   replacer.resetVarCache();
00080 }
00081 
00082 /*
00083  * Replaces '$arch' and '$basearch' in the path and query part of the URL
00084  * with the global ZYpp values. Examples:
00085  *
00086  * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/
00087  * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386
00088  */
00089 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const
00090 {
00091   Url newurl = value;
00092   newurl.setPathData(replacer(value.getPathData()));
00093   newurl.setQueryString(replacer(value.getQueryString()));
00094 
00095   return newurl;
00096 }
00097 
00098 } // ns repo
00099 } // ns zypp
00100 
00101 // vim: set ts=2 sts=2 sw=2 et ai:

Generated on Tue May 5 14:43:18 2015 for libzypp by  doxygen 1.5.6