Add ability to rename System.Service scripts

<Provides>
  <COMAR script="iscsi-service.py" name="iscsi">System.Service</COMAR>
  <COMAR script="iscsid-service.py" name="iscsid">System.Service</COMAR>
</Provides>

Will register two separate system services called respectively "iscsi" and "iscsid". This way
we don't have to split packages to give them separate names or to provide more than 1 services
in a sub-package.
This commit is contained in:
Ozan Çağlayan
2010-03-18 10:04:09 +00:00
parent b7a13317dd
commit 134f72f17c
4 changed files with 18 additions and 9 deletions
+3
View File
@@ -1420,6 +1420,9 @@
<optional> <optional>
<attribute name="script"/> <attribute name="script"/>
</optional> </optional>
<optional>
<attribute name="name"/>
</optional>
</define> </define>
<!-- Conflicts --> <!-- Conflicts -->
+1
View File
@@ -674,6 +674,7 @@ class Remove(AtomicOperation):
self.package_name, self.package_name,
os.path.join(self.package.pkg_dir(), ctx.const.metadata_xml), os.path.join(self.package.pkg_dir(), ctx.const.metadata_xml),
os.path.join(self.package.pkg_dir(), ctx.const.files_xml), os.path.join(self.package.pkg_dir(), ctx.const.files_xml),
provided_scripts=self.package.providesComar,
) )
def update_databases(self): def update_databases(self):
+11 -7
View File
@@ -104,17 +104,18 @@ def post_install(package_name, provided_scripts, scriptpath, metapath, filepath,
for script in provided_scripts: for script in provided_scripts:
ctx.ui.debug(_("Registering %s comar script") % script.om) ctx.ui.debug(_("Registering %s comar script") % script.om)
script_name = script.name if script.name else package_name
if script.om == "System.Package": if script.om == "System.Package":
self_post = True self_post = True
elif script.om == "System.Service": elif script.om == "System.Service":
sys_service = True sys_service = True
try: try:
link.register(package_name, script.om, os.path.join(scriptpath, script.script)) link.register(script_name, script.om, os.path.join(scriptpath, script.script))
except dbus.DBusException, exception: except dbus.DBusException, exception:
raise Error, _("Script error: %s") % exception raise Error, _("Script error: %s") % exception
if sys_service: if sys_service:
try: try:
link.System.Service[package_name].registerState() link.System.Service[script_name].registerState()
except dbus.DBusException, exception: except dbus.DBusException, exception:
raise Error, _("Script error: %s") % exception raise Error, _("Script error: %s") % exception
@@ -167,13 +168,15 @@ def pre_remove(package_name, metapath, filepath):
if not is_method_missing(exception): if not is_method_missing(exception):
raise Error, _("Script error: %s") % exception raise Error, _("Script error: %s") % exception
def post_remove(package_name, metapath, filepath): def post_remove(package_name, metapath, filepath, provided_scripts=[]):
"""Do package's post removal operations""" """Do package's post removal operations"""
ctx.ui.info(_("Running post removal operations for %s") % package_name) ctx.ui.info(_("Running post removal operations for %s") % package_name)
link = get_link() link = get_link()
package_name = safe_package_name(package_name) package_name = safe_package_name(package_name)
scripts = set([s.name for s in provided_scripts if s.name])
scripts.add(package_name)
if package_name in list(link.System.Package): if package_name in list(link.System.Package):
ctx.ui.debug(_("Running package's postremove script")) ctx.ui.debug(_("Running package's postremove script"))
@@ -194,7 +197,8 @@ def post_remove(package_name, metapath, filepath):
raise Error, _("Script error: %s") % exception raise Error, _("Script error: %s") % exception
ctx.ui.debug(_("Unregistering comar scripts")) ctx.ui.debug(_("Unregistering comar scripts"))
try: for scr in scripts:
link.remove(package_name, timeout=ctx.dbus_timeout) try:
except dbus.DBusException, exception: link.remove(scr, timeout=ctx.dbus_timeout)
raise Error, _("Script error: %s") % exception except dbus.DBusException, exception:
raise Error, _("Script error: %s") % exception
+2 -1
View File
@@ -142,11 +142,12 @@ class ComarProvide:
s_om = [autoxml.String, autoxml.mandatory] s_om = [autoxml.String, autoxml.mandatory]
a_script = [autoxml.String, autoxml.mandatory] a_script = [autoxml.String, autoxml.mandatory]
a_name = [autoxml.String, autoxml.optional]
def __str__(self): def __str__(self):
# FIXME: descriptive enough? # FIXME: descriptive enough?
s = self.script s = self.script
s += ' (' + self.om + ')' s += ' (' + self.om + '%s' % (' for %s' % self.name if self.name else '') + ')'
return s return s
class Archive: class Archive: