Kaydet (Commit) 6dcb5abf authored tarafından Ali Rıza Keskin's avatar Ali Rıza Keskin

scomiface yerine reactor koyduk çalışıyor.

üst bcb7d02c
......@@ -194,8 +194,7 @@ class Install(AtomicOperation):
# what to do if / is split into /usr, /var, etc.
# check scom
if self.metadata.package.providesScom and ctx.scom and not ctx.get_option("ignore_scom"):
import inary.scomiface as scomiface
scomiface.get_link()
import inary.reactor as reactor
def check_replaces(self):
for replaced in self.pkginfo.replaces:
......@@ -316,7 +315,7 @@ class Install(AtomicOperation):
# os.chown(fpath, int(_file.uid), int(_file.gid))
if self.metadata.package.providesScom:
if ctx.scom and not ctx.get_option("ignore_scom"):
import inary.scomiface
import inary.reactor
try:
if self.operation == UPGRADE or self.operation == DOWNGRADE:
fromVersion = self.old_pkginfo.version
......@@ -325,7 +324,7 @@ class Install(AtomicOperation):
fromVersion = None
fromRelease = None
ctx.ui.notify(inary.ui.configuring, package=self.pkginfo, files=self.files)
inary.scomiface.post_install(
inary.reactor.post_install(
self.pkginfo.name,
self.metadata.package.providesScom,
self.package.scom_dir(),
......@@ -337,7 +336,7 @@ class Install(AtomicOperation):
self.metadata.package.release
)
ctx.ui.notify(inary.ui.configured, package=self.pkginfo, files=self.files)
except inary.scomiface.Error:
except :
ctx.ui.warning(_('Configuration of \"{}\" package failed.').format(self.pkginfo.name))
self.config_later = True
else:
......@@ -695,8 +694,8 @@ class Remove(AtomicOperation):
def run_preremove(self):
if self.package.providesScom:
if ctx.scom and not ctx.get_option("ignore_scom"):
import inary.scomiface
inary.scomiface.pre_remove(
import inary.reactor
inary.reactor.pre_remove(
self.package_name,
os.path.join(self.package.pkg_dir(), ctx.const.metadata_xml),
os.path.join(self.package.pkg_dir(), ctx.const.files_xml),
......@@ -705,8 +704,8 @@ class Remove(AtomicOperation):
def run_postremove(self):
if self.package.providesScom:
if ctx.scom and not ctx.get_option("ignore_scom"):
import inary.scomiface
inary.scomiface.post_remove(
import inary.reactor
inary.reactor.post_remove(
self.package_name,
os.path.join(self.package.pkg_dir(), ctx.const.metadata_xml),
os.path.join(self.package.pkg_dir(), ctx.const.files_xml),
......
......@@ -25,11 +25,10 @@ import inary.ui
import inary.data
import inary.errors
import inary.context as ctx
import inary.reactor
def configure_pending(packages=None):
# Import SCOM
import inary.scomiface
# start with pending packages
# configure them in reverse topological order of dependency
......@@ -51,7 +50,7 @@ def configure_pending(packages=None):
# FIXME: we need a full package info here!
pkginfo.name = x
ctx.ui.notify(inary.ui.configuring, package=pkginfo, files=None)
inary.scomiface.post_install(
inary.reactor.post_install(
pkginfo.name,
m.package.providesScom,
util.join_path(pkg_path, ctx.const.scom_dir),
......
......@@ -52,6 +52,7 @@ import inary.cli.listrepo
import inary.cli.listsources
import inary.cli.listupgrades
import inary.cli.rebuilddb
import inary.cli.reconfigure
import inary.cli.remove
import inary.cli.removerepo
import inary.cli.removeorphaned
......
# -*- coding:utf-8 -*-
#
# Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
#
# Copyright (C) 2016 - 2018, Suleyman POYRAZ (Zaryob)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import optparse
import gettext
__trans = gettext.translation('inary', fallback=True)
_ = __trans.gettext
import inary.util as util
import inary.cli.command as command
import inary.ui
import inary.data
import inary.errors
import inary.context as ctx
import inary.reactor
def configure_pending(packages=None):
# start with pending packages
# configure them in reverse topological order of dependency
installdb = inary.db.installdb.InstallDB()
order=packages
if True:
for x in order:
if installdb.has_package(x):
pkginfo = installdb.get_package(x)
pkg_path = installdb.package_path(x)
m = inary.data.metadata.MetaData()
metadata_path = util.join_path(pkg_path, ctx.const.metadata_xml)
m.read(metadata_path)
# FIXME: we need a full package info here!
pkginfo.name = x
ctx.ui.notify(inary.ui.configuring, package=pkginfo, files=None)
inary.reactor.post_install(
pkginfo.name,
m.package.providesScom,
util.join_path(pkg_path, ctx.const.scom_dir),
util.join_path(pkg_path, ctx.const.metadata_xml),
util.join_path(pkg_path, ctx.const.files_xml),
None,
None,
m.package.version,
m.package.release
)
ctx.ui.notify(inary.ui.configured, package=pkginfo, files=None)
installdb.clear_pending(x)
class ConfigurePending(command.PackageOp, metaclass=command.autocommand):
__doc__ = _("""Reconfigure pending packages
If SCOM configuration of some packages were not
done at installation time, they are added to a list
of packages waiting to be configured. This command
configures those packages.
""")
def __init__(self, args):
super(ConfigurePending, self).__init__(args)
name = (_("reconfigure"), "rp")
def options(self):
group = optparse.OptionGroup(self.parser, _("configure-pending options"))
super(ConfigurePending, self).options(group)
self.parser.add_option_group(group)
def run(self):
self.init(database=True, write=False)
configure_pending(self.args)
# -*- coding: utf-8 -*-
#
#Copyright (C) 2019, Ali Rıza KESKİN (sulincix)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
import gettext
__trans = gettext.translation('inary', fallback=True)
_ = __trans.gettext
import inary.context as ctx
import inary.db
import inary.util as util
import os
import sys
installdb = inary.db.installdb.InstallDB()
def post_install(package_name, provided_scripts,
scriptpath, metapath, filepath,
fromVersion, fromRelease, toVersion, toRelease):
"""Do package's post install operations"""
pkg_path = installdb.package_path(package_name)
if(os.path.isfile(pkg_path+"/"+ctx.const.scom_dir+"/package.py")):
sys.path.insert(0,pkg_path+"/"+ctx.const.scom_dir)
else:
return 0
import package as package_py
package_py.postInstall(fromVersion, fromRelease, toVersion, toRelease)
del package_py
sys.path.pop(0)
def pre_install(package_name, provided_scripts,
scriptpath, metapath, filepath,
fromVersion, fromRelease, toVersion, toRelease):
"""Do package's pre install operations"""
pkg_path = installdb.package_path(package_name)
if(os.path.isfile(pkg_path+"/"+ctx.const.scom_dir+"/package.py")):
sys.path.insert(0,pkg_path+"/"+ctx.const.scom_dir)
else:
return 0
import package as package_py
if "preInstall" in dir(package_py):
package_py.preInstall(fromVersion, fromRelease, toVersion, toRelease)
del package_py
sys.path.pop(0)
def post_remove(package_name, metapath, filepath, provided_scripts=None):
"""Do package's post removal operations"""
pkg_path = installdb.package_path(package_name)
if(os.path.isfile(pkg_path+"/"+ctx.const.scom_dir+"/package.py")):
sys.path.insert(0,pkg_path+"/"+ctx.const.scom_dir)
else:
return 0
import package as package_py
if "postInstall" in dir(package_py):
package_py.postRemove(timeout=ctx.dbus_timeout)
del package_py
sys.path.pop(0)
def pre_remove(package_name, metapath, filepath):
"""Do package's post removal operations"""
pkg_path = installdb.package_path(package_name)
if(os.path.isfile(pkg_path+"/"+ctx.const.scom_dir+"/package.py")):
sys.path.insert(0,pkg_path+"/"+ctx.const.scom_dir)
else:
return 0
import package as package_py
if "postInstall" in dir(package_py):
package_py.preRemove(timeout=ctx.dbus_timeout)
del package_py
sys.path.pop(0)
# -*- coding: utf-8 -*-
#
# Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
#
# Copyright (C) 2016 - 2018, Suleyman POYRAZ (Zaryob)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
#
import os
import time
import gettext
__trans = gettext.translation('inary', fallback=True)
_ = __trans.gettext
import inary.api
import inary.context as ctx
import inary.errors
import inary.util as util
class Error(inary.errors.Error):
pass
try:
import scom
import dbus
except ImportError:
raise Error(_("scom package is not fully installed."))
def is_char_valid(char):
"""Test if char is valid object path character."""
return char in util.ascii_letters + util.digits + "_"
def is_method_missing(exception):
"""Tells if exception is about missing method in SCOM script"""
if ("tr.org.sulin.scom.Missing" or "tr.org.sulin.scom.python.missing") in str(exception):
ctx.ui.debug(str(exception).split(":")[-1])
return True
return False
def safe_script_name(package):
"""Generates DBus-safe object name for package script names."""
object = package
for char in package:
if not is_char_valid(char):
object = object.replace(char, '_')
if object[0].isdigit():
object = '_{}'.format(object)
return object
def get_link():
"""Connect to the SCOM daemon and return the link."""
sockname = "/var/run/dbus/system_bus_socket"
if ctx.dbus_sockname:
sockname = ctx.dbus_sockname
alternate = False
# If SCOM package is updated, all new configuration requests should be
# made through new SCOM service. Passing alternate=True to Link() class
# will ensure this.
if ctx.scom_updated:
alternate = True
# This function is sometimes called when scom has recently started
# or restarting after an update. So we give scom a chance to become
# active in a reasonable time.
timeout = 7
exceptions = []
while timeout > 0:
try:
link = scom.Link(socket=sockname, alternate=alternate)
link.setLocale()
return link
except dbus.exceptions.DBusException as e:
if str(e) in exceptions:
pass
else:
exceptions.append(str(e))
except Exception as e:
if str(e) in exceptions:
pass
else:
exceptions.append(str(e))
time.sleep(0.2)
timeout -= 0.2
raise Error(_("Cannot connect to SCOM: \n \"{}\"\n").format("\n ".join(exceptions)))
def post_install(package_name, provided_scripts,
scriptpath, metapath, filepath,
fromVersion, fromRelease, toVersion, toRelease):
"""Do package's post install operations"""
self_post = False
package_name = safe_script_name(package_name)
if package_name == 'scom':
ctx.ui.debug(_("SCOM package updated. From now on,"
" using new SCOM daemon."))
inary.api.set_scom_updated(True)
link = get_link()
for script in provided_scripts:
ctx.ui.debug(_("Registering \"{0}\" named scom script for \"{1}\".").format(script.om, package_name))
script_name = safe_script_name(script.name) \
if script.name else package_name
if script.om == "System.Package":
self_post = True
try:
link.register(script_name, script.om,
os.path.join(scriptpath, script.script))
except dbus.exceptions.DBusException as exception:
raise Error(_("Script error: {}").format(exception))
if script.om == "System.Service":
try:
link.System.Service[script_name].registerState()
except dbus.exceptions.DBusException as exception:
raise Error(_("Script error: {}").format(exception))
ctx.ui.debug(_("Calling post install handlers for \"{}\" package.").format(package_name))
for handler in link.System.PackageHandler:
try:
link.System.PackageHandler[handler].setupPackage(
metapath,
filepath,
timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if setupPackage method is not defined
# in package script
if not is_method_missing(exception):
raise Error(_("Script error for \"{0}\" package: {1}.").format(package_name, exception))
if (self_post and hasattr(link.System.Package[package_name], "postInstall")):
if not fromVersion:
fromVersion = ""
if not fromRelease:
fromRelease = ""
ctx.ui.debug(_("Running package's post install script for \"{0}\" package.").format(package_name))
try:
link.System.Package[package_name].postInstall(
fromVersion, fromRelease, toVersion, toRelease,
timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if postInstall method is not defined in package script
if not is_method_missing(exception):
raise Error(_("Script error for \"{0}\" package: {1}").format(package_name, exception))
def pre_remove(package_name, metapath, filepath):
"""Do package's pre removal operations"""
ctx.ui.info(_("Running pre removal operations for \"{}\" package.").format(package_name))
link = get_link()
package_name = safe_script_name(package_name)
if package_name in list(link.System.Package):
if hasattr(link.System.Package[package_name], "preRemove"):
ctx.ui.debug(_("Running package's pre remove script for \"{}\" package.").format(package_name))
try:
link.System.Package[package_name].preRemove(
timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if preRemove method is not defined in package script
if not is_method_missing(exception):
raise Error(_("Script error: {}").format(exception))
ctx.ui.debug(_("Calling pre remove handlers for \"{}\" package.").format(package_name))
for handler in list(link.System.PackageHandler):
try:
link.System.PackageHandler[handler].cleanupPackage(
metapath, filepath, timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if cleanupPackage method is not defined
# in package script
if not is_method_missing(exception):
raise Error(_("Script error: {}").format(exception))
def post_remove(package_name, metapath, filepath, provided_scripts=None):
"""Do package's post removal operations"""
if provided_scripts is None:
provided_scripts = []
ctx.ui.info(_("Running post removal operations for \"{}\" package.").format(package_name))
link = get_link()
package_name = safe_script_name(package_name)
scripts = set([safe_script_name(s.name) for s \
in provided_scripts if s.name])
scripts.add(package_name)
if package_name in list(link.System.Package):
if hasattr(link.System.Package[package_name], "postRemove"):
ctx.ui.debug(_("Running package's postremove script for \"{}\" package.").format(package_name))
try:
link.System.Package[package_name].postRemove(
timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if postRemove method is not defined in package script
if not is_method_missing(exception):
raise Error(_("Script error: {}").format(exception))
ctx.ui.debug(_("Calling post remove handlers for \"{}\" package.").format(package_name))
for handler in list(link.System.PackageHandler):
try:
link.System.PackageHandler[handler].postCleanupPackage(
metapath, filepath, timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
# Do nothing if postCleanupPackage method is not defined
# in package script
if not is_method_missing(exception):
raise Error(_("Script error: {}").format(exception))
ctx.ui.debug(_("Unregistering scom scripts of \"{}\" package.").format(package_name))
for scr in scripts:
try:
ctx.ui.debug(_("Unregistering {} script.").format(scr))
link.remove(scr, timeout=ctx.dbus_timeout)
except dbus.exceptions.DBusException as exception:
raise Error(_("Script error: {}").format(exception))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment