View | Details | Raw Unified | Return to bug 381917
Collapse All | Expand All

(-)src/Y2PkgFunction.h (-2 / +4 lines)
Lines 6-15 Link Here
6
6
7
#include <y2/Y2Function.h>
7
#include <y2/Y2Function.h>
8
8
9
class PkgModuleFunctions;
9
class Y2PkgFunction: public Y2Function
10
class Y2PkgFunction: public Y2Function
10
{
11
{
11
    unsigned int m_position;
12
    unsigned int m_position;
12
    PkgFunctions* m_instance;
13
    // originally PkgFunctions* m_instance, but changed to delay loading zypp
14
    PkgModuleFunctions* m_ns_instance;
13
    YCPValue m_param1;
15
    YCPValue m_param1;
14
    YCPValue m_param2;
16
    YCPValue m_param2;
15
    YCPValue m_param3;
17
    YCPValue m_param3;
Lines 18-24 Link Here
18
    string m_name;
20
    string m_name;
19
public:
21
public:
20
22
21
    Y2PkgFunction (string name, PkgFunctions* instance, unsigned int pos);
23
    Y2PkgFunction (string name, PkgModuleFunctions* instance, unsigned int pos);
22
    bool attachParameter (const YCPValue& arg, const int position);
24
    bool attachParameter (const YCPValue& arg, const int position);
23
    constTypePtr wantedParameterType () const;
25
    constTypePtr wantedParameterType () const;
24
    bool appendParameter (const YCPValue& arg);
26
    bool appendParameter (const YCPValue& arg);
(-)src/PkgFunctions.cc (+47 lines)
Lines 37-42 Link Here
37
#include <ycp/YCPVoid.h>
37
#include <ycp/YCPVoid.h>
38
38
39
#include <zypp/ZYppFactory.h>
39
#include <zypp/ZYppFactory.h>
40
#include <zypp/base/Logger.h>
41
#include <zypp/base/LogControl.h>
40
42
41
// sleep
43
// sleep
42
#include <unistd.h>
44
#include <unistd.h>
Lines 49-54 Link Here
49
51
50
const zypp::ResStatus::TransactByValue PkgFunctions::whoWantsIt = zypp::ResStatus::APPL_HIGH;
52
const zypp::ResStatus::TransactByValue PkgFunctions::whoWantsIt = zypp::ResStatus::APPL_HIGH;
51
53
54
struct YaSTZyppLogger : public zypp::base::LogControl::LineWriter
55
{
56
  virtual void writeOut( const std::string & formated_r )
57
  {
58
    // don't log empty (debug) messages  
59
    if (!formated_r.empty())
60
    {
61
	y2lograw((formated_r+"\n").c_str());
62
    }
63
  }
64
};
65
66
struct YaSTZyppFormatter : public zypp::base::LogControl::LineFormater
67
{
68
    virtual std::string format( const std::string & group_r,
69
	    zypp::base::logger::LogLevel    level_r,
70
	    const char *        file_r,
71
	    const char *        func_r,
72
	    int                 line_r,
73
	    const std::string & message_r )
74
    {
75
	if (get_log_debug() || level_r > zypp::base::logger::E_DBG)
76
	{
77
	    // call the default implementation
78
	    return zypp::base::LogControl::LineFormater::format(group_r, level_r, file_r, func_r, line_r, message_r);
79
	}
80
81
	// return empty string (ignore debug messages when debug is tuned off)
82
	return std::string();
83
    }
84
85
};
86
87
extern "C" {
88
PkgFunctions * createPkgFunctions () {
89
    return new PkgFunctions ();
90
}
91
}
92
52
/**
93
/**
53
 * Constructor.
94
 * Constructor.
54
 */
95
 */
Lines 59-64 Link Here
59
    ,_callbackHandler( *new CallbackHandler(*this) )
100
    ,_callbackHandler( *new CallbackHandler(*this) )
60
    ,target_log_set(false)
101
    ,target_log_set(false)
61
{
102
{
103
    y2milestone("Redirecting ZYPP log to y2log");
104
    boost::shared_ptr<YaSTZyppLogger> myLogger( new YaSTZyppLogger );
105
    zypp::base::LogControl::instance().setLineWriter( myLogger );
106
    boost::shared_ptr<YaSTZyppFormatter> myFormatter( new YaSTZyppFormatter );
107
    zypp::base::LogControl::instance().setLineFormater( myFormatter );
108
62
    const char *domain = "pkg-bindings";
109
    const char *domain = "pkg-bindings";
63
    bindtextdomain( domain, LOCALEDIR );
110
    bindtextdomain( domain, LOCALEDIR );
64
    bind_textdomain_codeset( domain, "utf8" );
111
    bind_textdomain_codeset( domain, "utf8" );
(-)src/PkgModuleFunctions.cc (-1 / +28 lines)
Lines 27-32 Link Here
27
#include <y2/Y2Function.h>
27
#include <y2/Y2Function.h>
28
#include <ycp/YCPVoid.h>
28
#include <ycp/YCPVoid.h>
29
#include "log.h"
29
#include "log.h"
30
#include <dlfcn.h>
30
31
31
/////////////////////////////////////////////////////////////////////////////
32
/////////////////////////////////////////////////////////////////////////////
32
33
Lines 36-41 Link Here
36
 */
37
 */
37
PkgModuleFunctions::PkgModuleFunctions ()
38
PkgModuleFunctions::PkgModuleFunctions ()
38
    : Y2Namespace()
39
    : Y2Namespace()
40
    , pkg_functions (NULL)
39
{
41
{
40
    registerFunctions ();
42
    registerFunctions ();
41
}
43
}
Lines 45-50 Link Here
45
 */
47
 */
46
PkgModuleFunctions::~PkgModuleFunctions()
48
PkgModuleFunctions::~PkgModuleFunctions()
47
{
49
{
50
    delete pkg_functions;
48
}
51
}
49
52
50
Y2Function* PkgModuleFunctions::createFunctionCall (const string name, constFunctionTypePtr type)
53
Y2Function* PkgModuleFunctions::createFunctionCall (const string name, constFunctionTypePtr type)
Lines 57-65 Link Here
57
	return NULL;
60
	return NULL;
58
    }
61
    }
59
62
60
    return new Y2PkgFunction (name, &pkg_functions, it - _registered_functions.begin ());
63
    return new Y2PkgFunction (name, this, it - _registered_functions.begin ());
61
}
64
}
62
65
66
PkgFunctions* PkgModuleFunctions::get_impl ()
67
{
68
    if (pkg_functions == NULL) {
69
	y2milestone ("Now creating PkgFunctions");
70
	// Load the zypp dependencies lazily (fate#302119).
71
	// No version suffix. we take whatever there is,
72
	// the interface changes too fast
73
	void * pkg_handle = dlopen (PLUGINDIR "/libpy2Pkgzypp.so",
74
				RTLD_LAZY | RTLD_GLOBAL);
75
	if (pkg_handle) {
76
	    typedef PkgFunctions * (* cPF_t)();
77
	    cPF_t cPF = (cPF_t) dlsym (pkg_handle, "createPkgFunctions");
78
	    if (cPF) {
79
		pkg_functions = (*cPF)();
80
	    }
81
	}
82
	if (pkg_functions == NULL) {
83
	    y2error ("Could not load zypp implementation of Pkg: %s", dlerror ());
84
	    throw std::runtime_error("Pkg zypp failed");
85
	}
86
    }
87
    return pkg_functions;
88
}
89
63
YCPValue PkgModuleFunctions::evaluate(bool cse)
90
YCPValue PkgModuleFunctions::evaluate(bool cse)
64
{
91
{
65
    if (cse) return YCPNull ();
92
    if (cse) return YCPNull ();
(-)src/PkgModule.cc (-44 lines)
Lines 23-78 Link Here
23
#include <PkgModule.h>
23
#include <PkgModule.h>
24
#include "log.h"
24
#include "log.h"
25
25
26
#include <zypp/base/Logger.h>
27
#include <zypp/base/LogControl.h>
28
29
PkgModule* PkgModule::current_pkg = NULL;
26
PkgModule* PkgModule::current_pkg = NULL;
30
27
31
struct YaSTZyppLogger : public zypp::base::LogControl::LineWriter
32
{
33
  virtual void writeOut( const std::string & formated_r )
34
  {
35
    // don't log empty (debug) messages  
36
    if (!formated_r.empty())
37
    {
38
	y2lograw((formated_r+"\n").c_str());
39
    }
40
  }
41
};
42
43
struct YaSTZyppFormatter : public zypp::base::LogControl::LineFormater
44
{
45
    virtual std::string format( const std::string & group_r,
46
	    zypp::base::logger::LogLevel    level_r,
47
	    const char *        file_r,
48
	    const char *        func_r,
49
	    int                 line_r,
50
	    const std::string & message_r )
51
    {
52
	if (get_log_debug() || level_r > zypp::base::logger::E_DBG)
53
	{
54
	    // call the default implementation
55
	    return zypp::base::LogControl::LineFormater::format(group_r, level_r, file_r, func_r, line_r, message_r);
56
	}
57
58
	// return empty string (ignore debug messages when debug is tuned off)
59
	return std::string();
60
    }
61
62
};
63
64
PkgModule* PkgModule::instance ()
28
PkgModule* PkgModule::instance ()
65
{
29
{
66
    if (current_pkg == NULL)
30
    if (current_pkg == NULL)
67
    {
31
    {
68
	y2milestone("Redirecting ZYPP log to y2log");
69
70
        boost::shared_ptr<YaSTZyppLogger> myLogger( new YaSTZyppLogger );
71
        zypp::base::LogControl::instance().setLineWriter( myLogger );
72
73
        boost::shared_ptr<YaSTZyppFormatter> myFormatter( new YaSTZyppFormatter );
74
        zypp::base::LogControl::instance().setLineFormater( myFormatter );
75
76
	current_pkg = new PkgModule ();
32
	current_pkg = new PkgModule ();
77
    }
33
    }
78
    
34
    
(-)src/Y2PkgFunction.cc (-2 / +5 lines)
Lines 22-27 Link Here
22
22
23
23
24
#include "Y2PkgFunction.h"
24
#include "Y2PkgFunction.h"
25
#include "PkgModuleFunctions.h"
25
26
26
#include <ycp/YCPBoolean.h>
27
#include <ycp/YCPBoolean.h>
27
#include <ycp/YCPValue.h>
28
#include <ycp/YCPValue.h>
Lines 35-43 Link Here
35
36
36
#include <ycp/y2log.h>
37
#include <ycp/y2log.h>
37
38
38
    Y2PkgFunction::Y2PkgFunction (string name, PkgFunctions* instance, unsigned int pos) :
39
    Y2PkgFunction::Y2PkgFunction (string name, PkgModuleFunctions* instance, unsigned int pos) :
39
	m_position (pos)
40
	m_position (pos)
40
	, m_instance (instance)
41
	, m_ns_instance (instance)
41
	, m_param1 ( YCPNull () )
42
	, m_param1 ( YCPNull () )
42
	, m_param2 ( YCPNull () )
43
	, m_param2 ( YCPNull () )
43
	, m_param3 ( YCPNull () )
44
	, m_param3 ( YCPNull () )
Lines 108-113 Link Here
108
109
109
	try
110
	try
110
	{
111
	{
112
	    PkgFunctions* m_instance = m_ns_instance->get_impl ();
113
111
	    switch (m_position) {
114
	    switch (m_position) {
112
#include "PkgBuiltinCalls.h"
115
#include "PkgBuiltinCalls.h"
113
	    }
116
	    }
(-)src/PkgFunctions.h (+5 lines)
Lines 750-753 Link Here
750
	RepoId logFindAlias(const std::string &alias) const;
750
	RepoId logFindAlias(const std::string &alias) const;
751
751
752
};
752
};
753
754
extern "C" {
755
PkgFunctions * createPkgFunctions ();
756
}
757
753
#endif // PkgFunctions_h
758
#endif // PkgFunctions_h
(-)src/PkgModuleFunctions.h (-2 / +6 lines)
Lines 25-32 Link Here
25
25
26
#include <string>
26
#include <string>
27
#include <y2/Y2Namespace.h>
27
#include <y2/Y2Namespace.h>
28
#include "PkgFunctions.h"
29
28
29
class PkgFunctions;
30
/**
30
/**
31
 * A simple class for package management access
31
 * A simple class for package management access
32
 */
32
 */
Lines 62-72 Link Here
62
62
63
	virtual Y2Function* createFunctionCall (const std::string name, constFunctionTypePtr type);
63
	virtual Y2Function* createFunctionCall (const std::string name, constFunctionTypePtr type);
64
64
65
	// load the implementation on demand
66
	PkgFunctions* get_impl ();
67
65
    private:
68
    private:
66
69
67
	void registerFunctions ();
70
	void registerFunctions ();
68
71
69
	PkgFunctions pkg_functions;
72
	PkgFunctions * pkg_functions;
73
70
        std::vector<std::string> _registered_functions;
74
        std::vector<std::string> _registered_functions;
71
};
75
};
72
#endif // PkgModuleFunctions_h
76
#endif // PkgModuleFunctions_h
(-)src/Makefile.am (-11 / +20 lines)
Lines 6-31 Link Here
6
AM_CXXFLAGS = -DY2LOG=\"Pkg\"			\
6
AM_CXXFLAGS = -DY2LOG=\"Pkg\"			\
7
	-DSUSEVERSION=\"${SUSEVERSION}\"	\
7
	-DSUSEVERSION=\"${SUSEVERSION}\"	\
8
	-DLOCALEDIR=\"${localedir}\"		\
8
	-DLOCALEDIR=\"${localedir}\"		\
9
	-DPLUGINDIR=\"${plugindir}\"		\
9
	-fno-inline				\
10
	-fno-inline				\
10
	-Woverloaded-virtual			\
11
	-Woverloaded-virtual			\
11
	-DZYPP_BASE_LOGGER_LOGGROUP=\"Pkg\"
12
	-DZYPP_BASE_LOGGER_LOGGROUP=\"Pkg\"
12
13
14
# Pkg is a stub that dlopens Pkgzypp (and zypp) lazily
15
# at the last moment (fate#302119)
16
plugin_LTLIBRARIES = libpy2Pkg.la libpy2Pkgzypp.la
13
17
14
# to look for the packagemanager in the prefix first (really first?)
18
libpy2Pkg_la_SOURCES =				\
15
AM_LDFLAGS = -L${libdir}
19
	PkgModule.cc PkgModule.h		\
20
	PkgModuleFunctions.h			\
21
	PkgModuleFunctions.cc			\
22
	Y2PkgFunction.cc Y2PkgFunction.h	\
23
	Y2PkgComponent.cc Y2PkgComponent.h	\
24
	Y2CCPkg.cc Y2CCPkg.h
16
25
17
plugin_LTLIBRARIES = libpy2Pkg.la
26
libpy2Pkgzypp_la_SOURCES =			\
18
19
libpy2Pkg_la_SOURCES =				\
20
	PkgError.cc PkgError.h			\
27
	PkgError.cc PkgError.h			\
21
	Y2PkgComponent.cc Y2PkgComponent.h	\
22
	Y2CCPkg.cc Y2CCPkg.h			\
23
	ycpTools.cc ycpTools.h			\
28
	ycpTools.cc ycpTools.h			\
24
	PkgModule.cc PkgModule.h		\
25
	PkgProgress.cc PkgProgress.h		\
29
	PkgProgress.cc PkgProgress.h		\
26
	ProvideProcess.cc ProvideProcess.h	\
30
	ProvideProcess.cc ProvideProcess.h	\
27
	PkgModuleFunctions.h			\
28
	PkgModuleFunctions.cc			\
29
	PkgFunctions.h PkgFunctions.cc		\
31
	PkgFunctions.h PkgFunctions.cc		\
30
	Package.cc				\
32
	Package.cc				\
31
	Patch.cc				\
33
	Patch.cc				\
Lines 49-63 Link Here
49
	Callbacks.h				\
51
	Callbacks.h				\
50
	Callbacks.YCP.h Callbacks.YCP.cc	\
52
	Callbacks.YCP.h Callbacks.YCP.cc	\
51
	Callbacks.cc Callbacks_Register.cc	\
53
	Callbacks.cc Callbacks_Register.cc	\
52
	Y2PkgFunction.cc Y2PkgFunction.h	\
53
	YRepo.h YRepo.cc			\
54
	YRepo.h YRepo.cc			\
54
	HelpTexts.h i18n.h log.h
55
	HelpTexts.h i18n.h log.h
55
56
56
57
57
libpy2Pkg_la_LDFLAGS = -version-info 2:0
58
libpy2Pkg_la_LDFLAGS = -version-info 2:0
58
libpy2Pkg_la_LIBADD = \
59
libpy2Pkg_la_LIBADD = \
60
	-L${libdir}	\
59
	-lycp		\
61
	-lycp		\
60
	-ly2		\
62
	-ly2		\
63
	-ly2util
64
65
libpy2Pkgzypp_la_LDFLAGS = -version-info 2:0
66
libpy2Pkgzypp_la_LIBADD = \
67
	-L${libdir}	\
68
	-lycp		\
69
	-ly2		\
61
	-ly2util	\
70
	-ly2util	\
62
	${ZYPP_LIBS}
71
	${ZYPP_LIBS}
63
72
(-)yast2-pkg-bindings.spec.in (-1 / +4 lines)
Lines 20-30 Link Here
20
20
21
@INSTALL@
21
@INSTALL@
22
rm -rf %{buildroot}/@plugindir@/libpy2Pkg.la
22
rm -rf %{buildroot}/@plugindir@/libpy2Pkg.la
23
rm -rf %{buildroot}/@plugindir@/libpy2Pkg.so
24
rm -rf %{buildroot}/@plugindir@/libpy2Pkgzypp.la
23
25
24
@CLEAN@
26
@CLEAN@
25
27
26
%files
28
%files
27
%defattr(-,root,root)
29
%defattr(-,root,root)
28
@plugindir@/libpy2Pkg.so.*
30
@plugindir@/libpy2Pkg.so.*
29
@plugindir@/libpy2Pkg.so
31
@plugindir@/libpy2Pkgzypp.so
32
@plugindir@/libpy2Pkgzypp.so.*
30
%doc @docdir@
33
%doc @docdir@

Return to bug 381917