summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-11-30 20:59:25 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-11-30 20:59:25 +0000
commit4eafcba4a47bb81da309e2e183ecba6601f89941 (patch)
treeb47dd48b81f44024f4aee2858270c4198bc18c7e /src/lib
parent96b390265592d210bb09e9374fa376e3990e37c3 (diff)
downloadbcfg2-4eafcba4a47bb81da309e2e183ecba6601f89941.tar.gz
bcfg2-4eafcba4a47bb81da309e2e183ecba6601f89941.tar.bz2
bcfg2-4eafcba4a47bb81da309e2e183ecba6601f89941.zip
MacPorts: Preliminary attempt at a workable macports client tool
This commit adds support for installing macports via 'port install' and verifying the presence of installed packages. We can't expect to be able to do much more than this at the moment. Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5597 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Client/Tools/MacPorts.py60
-rw-r--r--src/lib/Client/Tools/__init__.py4
2 files changed, 62 insertions, 2 deletions
diff --git a/src/lib/Client/Tools/MacPorts.py b/src/lib/Client/Tools/MacPorts.py
new file mode 100644
index 000000000..f398c73ed
--- /dev/null
+++ b/src/lib/Client/Tools/MacPorts.py
@@ -0,0 +1,60 @@
+# This is the bcfg2 support for macports packages
+'''This provides bcfg2 support for macports packages'''
+__revision__ = '$Revision$'
+
+import Bcfg2.Client.Tools
+
+class MacPorts(Bcfg2.Client.Tools.PkgTool):
+ '''macports package support'''
+ name = 'MacPorts'
+ __execs__ = ["/opt/local/bin/port"]
+ __handles__ = [('Package', 'macport')]
+ __req__ = {'Package': ['name', 'version']}
+ pkgtype = 'macport'
+ pkgtool = ("/opt/local/bin/port install %s")
+
+ def __init__(self, logger, setup, config):
+ Bcfg2.Client.Tools.PkgTool.__init__(self, logger, setup, config)
+ self.installed = {}
+ self.RefreshPackages()
+
+ def RefreshPackages(self):
+ '''Refresh memory hashes of packages'''
+ pkgcache = self.cmd.run("/opt/local/bin/port installed")[1]
+ self.installed = {}
+ for pkg in pkgcache:
+ if pkg.startswith("The following ports are currently installed"):
+ continue
+ pkgname = pkg.split('@')[0].strip()
+ version = pkg.split('@')[1].split(' ')[0]
+ self.logger.info(" pkgname: %s\n version: %s" % (pkgname, version))
+ self.installed[pkgname] = version
+
+ def VerifyPackage(self, entry, modlist):
+ '''Verify Package status for entry'''
+ if not 'version' in entry.attrib:
+ self.logger.info("Cannot verify unversioned package %s" %
+ (entry.attrib['name']))
+ return False
+
+ if entry.attrib['name'] in self.installed:
+ if self.installed[entry.attrib['name']] == entry.attrib['version']:
+ #if not self.setup['quick'] and \
+ # entry.get('verify', 'true') == 'true':
+ #FIXME: We should be able to check this once
+ # http://trac.macports.org/ticket/15709 is implemented
+ return True
+ else:
+ entry.set('current_version', self.installed[entry.get('name')])
+ return False
+ entry.set('current_exists', 'false')
+ return False
+
+ def RemovePackages(self, packages):
+ '''Remove extra packages'''
+ names = [pkg.get('name') for pkg in packages]
+ self.logger.info("Removing packages: %s" % " ".join(names))
+ self.cmd.run("/opt/local/bin/port uninstall %s" % \
+ " ".join(names))
+ self.RefreshPackages()
+ self.extra = self.FindExtraPackages()
diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py
index b6936af18..d25219579 100644
--- a/src/lib/Client/Tools/__init__.py
+++ b/src/lib/Client/Tools/__init__.py
@@ -2,8 +2,8 @@
__revision__ = '$Revision$'
__all__ = ["Action", "APT", "Blast", "Chkconfig", "DebInit", "Encap", "IPS",
- "FreeBSDInit", "FreeBSDPackage", "launchd", "Portage", "POSIX",
- "RPMng", 'rpmtools', "RcUpdate", "SMF", "SYSV", "YUMng"]
+ "FreeBSDInit", "FreeBSDPackage", "launchd", "MacPorts", "Portage",
+ "POSIX", "RPMng", 'rpmtools', "RcUpdate", "SMF", "SYSV", "YUMng"]
drivers = [item for item in __all__ if item not in ['rpmtools']]
default = [item for item in drivers if item not in ['RPM', 'Yum']]