libzypp  17.28.0
PluginServices.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 #include <iostream>
10 #include <sstream>
11 #include <zypp/base/Logger.h>
12 #include <zypp/base/Gettext.h>
13 #include <zypp/base/String.h>
14 #include <zypp/base/InputStream.h>
16 
18 #include <zypp/ServiceInfo.h>
19 #include <zypp/RepoInfo.h>
20 #include <zypp/PathInfo.h>
21 
22 using std::endl;
23 using std::stringstream;
24 
26 namespace zypp
27 {
28  namespace repo
30  {
31 
33  {
34  public:
35  static void loadServices( const Pathname &path,
36  const PluginServices::ProcessService &callback );
37  };
38 
40  const PluginServices::ProcessService & callback/*,
41  const ProgressData::ReceiverFnc &progress*/ )
42  {
43  std::list<Pathname> entries;
44  if (PathInfo(path).isExist())
45  {
46  if ( filesystem::readdir( entries, path, false ) != 0 )
47  {
48  // TranslatorExplanation '%s' is a pathname
49  ZYPP_THROW(Exception(str::form(_("Failed to read directory '%s'"), path.c_str())));
50  }
51 
52  //str::regex allowedServiceExt("^\\.service(_[0-9]+)?$");
53  for_(it, entries.begin(), entries.end() )
54  {
55  ServiceInfo service_info;
56  service_info.setAlias((*it).basename());
57  Url url;
58  url.setPathName((*it).asString());
59  url.setScheme("file");
60  service_info.setUrl(url);
61  service_info.setType(ServiceType::PLUGIN);
62  service_info.setAutorefresh( true );
63  DBG << "Plugin Service: " << service_info << endl;
64  callback(service_info);
65  }
66 
67  }
68  }
69 
71  const ProcessService & callback/*,
72  const ProgressData::ReceiverFnc &progress */)
73  {
74  Impl::loadServices(path, callback/*, progress*/);
75  }
76 
78  {}
79 
80  std::ostream & operator<<( std::ostream & str, const PluginServices & obj )
81  {
82  return str;
83  }
84 
86  } // namespace repo
89 } // namespace zypp
zypp::filesystem::readdir
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition: PathInfo.cc:576
zypp::ServiceInfo
Service data.
Definition: ServiceInfo.h:37
zypp::Exception
Base class for Exception.
Definition: Exception.h:146
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition: RepoInfoBase.cc:91
zypp::repo::PluginServices::Impl
Definition: PluginServices.cc:33
zypp::repo::PluginServices::PluginServices
PluginServices(const Pathname &path, const ProcessService &callback)
Definition: PluginServices.cc:70
zypp::Url::setScheme
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:663
zypp::ServiceInfo::setType
void setType(const repo::ServiceType &type)
Set service type.
Definition: ServiceInfo.cc:109
zypp::filesystem::PathInfo
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:219
RepoInfo.h
_
#define _(MSG)
Definition: Gettext.h:37
zypp::filesystem::Pathname::c_str
const char * c_str() const
String representation.
Definition: Pathname.h:110
zypp::Url::setPathName
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:759
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
zypp::repo::ServiceType::PLUGIN
static const ServiceType PLUGIN
Plugin services are scripts installed on your system that provide the package manager with repositori...
Definition: ServiceType.h:43
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
PluginServices.h
zypp::repo::PluginServices
Definition: PluginServices.h:29
DBG
#define DBG
Definition: Logger.h:95
UserRequestException.h
ServiceInfo.h
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
InputStream.h
zypp::repo::PluginServices::ProcessService
function< bool(const ServiceInfo &)> ProcessService
Callback definition.
Definition: PluginServices.h:40
zypp::repo::PluginServices::~PluginServices
~PluginServices()
Dtor.
Definition: PluginServices.cc:77
str
String related utilities and Regular expression matching.
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition: RepoInfoBase.cc:94
zypp::ServiceInfo::setUrl
void setUrl(const Url &url)
Set the service url (raw value)
Definition: ServiceInfo.cc:105
zypp::repo::PluginServices::Impl::loadServices
static void loadServices(const Pathname &path, const PluginServices::ProcessService &callback)
Definition: PluginServices.cc:39
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::repo::PluginServices::operator<<
friend std::ostream & operator<<(std::ostream &str, const PluginServices &obj)
Definition: PluginServices.cc:80
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28