Repository URL to install this package:
|
Version:
15.1.0-1 ▾
|
# (c) Copyright 2009-2010. CodeWeavers, Inc.
import UserDict
import os
import cxconfig
import cxutils
import bottlequery
class Error(Exception):
pass
def cxnsplugin_path():
return os.path.join(cxutils.CX_ROOT, "bin", "cxnsplugin")
def run_cxnsplugin(args, grab_stdout=False, background=False):
if grab_stdout:
stdout = cxutils.GRAB
else:
stdout = None
if background:
stderr = None
else:
stderr = cxutils.GRAB
retcode, out, err = cxutils.run((cxnsplugin_path(),)+tuple(args), stderr=stderr, stdout=stdout, background=background)
if retcode:
raise Error(err)
else:
return out
class PluginItem(object):
"""A single plugin dll."""
def __init__(self, parent, section):
self.parent = parent
# dll identifier
self.dllkey = section.name
# dll path
self.path = cxutils.unmangle(self.dllkey)
# dll basename
self.basename = self.path.rsplit('/', 2)[-1]
# 'install' or 'ignore'
self.mode = section.get('Mode', 'ignore')
# this mode will be set when PluginPrefs.commit() is called
self.new_mode = self.mode
# human-readable name
self.name = section.get('Name')
# human-readable description
self.description = section.get('Description')
class PluginPrefs(object, UserDict.IterableUserDict):
"""An editable plugin configuration for a bottle"""
def __init__(self, bottlename, managed):
UserDict.IterableUserDict.__init__(self)
self.bottlename = bottlename
self.managed = managed
def config_filename(self):
return os.path.join(bottlequery.get_prefix_for_bottle(self.bottlename), 'cxnsplugin.conf')
def read_config(self):
"""Reads the plugin information from cxplugin.conf."""
config = cxconfig.get(self.config_filename())
self.data.clear()
for section in config.itervalues():
self.data[section.name] = PluginItem(self, section)
def query_config(self):
"""Update settings from cxnsplugin --query."""
if self.managed:
scope = "managed"
else:
scope = "private"
data = run_cxnsplugin(('--query', '--bottle', self.bottlename, '--scope', scope), grab_stdout=True)
config = cxconfig.Raw()
config.read_string(data)
all_plugindirs = config['.all']
for section in config.itervalues():
path = section.name
if path in self.data:
if config[path] == all_plugindirs:
self.data[path].mode = 'install'
else:
self.data[path].mode = 'ignore'
def refresh(self):
"""Read the plugin configuration for this bottle"""
self.read_config()
self.query_config()
def commit(self):
"""Save and apply the changes using cxnsplugin."""
# Find all changed associations, grouped by the new setting
changes = {'ignore': [],
'install': [],
}
for plugin in self.data.values():
if plugin.new_mode != plugin.mode:
changes[plugin.new_mode].append(plugin.dllkey)
if changes['install']:
run_cxnsplugin(('--bottle', self.bottlename,
'--mode', 'install',
'--install',
'--filter', ':'.join(changes['install'])))
if changes['ignore']:
run_cxnsplugin(('--bottle', self.bottlename,
'--mode', 'ignore',
'--uninstall',
'--filter', ':'.join(changes['ignore'])))
for plugin in self.data.values():
plugin.mode = plugin.new_mode
def recreate_plugins(self):
run_cxnsplugin(('--bottle', self.bottlename, '--sync',
'--mode', 'install', '--removeall', '--install'))