summaryrefslogtreecommitdiffstats
path: root/overlays
diff options
context:
space:
mode:
Diffstat (limited to 'overlays')
-rw-r--r--overlays/.svn.ignore1
-rw-r--r--overlays/__init__.py1
-rw-r--r--overlays/bzr.py66
-rw-r--r--overlays/cvs.py73
-rw-r--r--overlays/darcs.py64
-rw-r--r--overlays/git.py63
-rw-r--r--overlays/mercurial.py64
-rw-r--r--overlays/overlay.py266
-rw-r--r--overlays/rsync.py68
-rw-r--r--overlays/svn.py65
-rw-r--r--overlays/tar.py189
11 files changed, 920 insertions, 0 deletions
diff --git a/overlays/.svn.ignore b/overlays/.svn.ignore
new file mode 100644
index 0000000..0d20b64
--- /dev/null
+++ b/overlays/.svn.ignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/overlays/__init__.py b/overlays/__init__.py
new file mode 100644
index 0000000..792d600
--- /dev/null
+++ b/overlays/__init__.py
@@ -0,0 +1 @@
+#
diff --git a/overlays/bzr.py b/overlays/bzr.py
new file mode 100644
index 0000000..8e8bb47
--- /dev/null
+++ b/overlays/bzr.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN BZR OVERLAY HANDLER
+#################################################################################
+# File: bzr.py
+#
+# Handles bzr overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Adrian Perez, Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Adrian Perez <moebius@connectical.net>
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+'''Should work with any version of Bzr equal to or better than 0.7 --
+ caution: tested only with 0.8 and 0.8.2...'''
+
+__version__ = "$Id: bzr.py 236 2006-09-05 20:39:37Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class BzrOverlay
+#
+#-------------------------------------------------------------------------------
+
+class BzrOverlay(Overlay):
+ ''' Handles bzr overlays.'''
+
+ type = 'Bzr'
+
+ binary_command = '/usr/bin/bzr'
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.binary_command + ' get "' + self.src + '/" "' +\
+ path([base, self.name]) + '"')
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + path([base, self.name]) + '" && ' + \
+ self.binary_command + ' pull --overwrite "' + self.src \
+ + '"')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary_command, 'bzr',
+ 'dev-util/bzr'),])
diff --git a/overlays/cvs.py b/overlays/cvs.py
new file mode 100644
index 0000000..95f20ea
--- /dev/null
+++ b/overlays/cvs.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN CVS OVERLAY HANDLER
+#################################################################################
+# File: cvs.py
+#
+# Handles cvs overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+''' Cvs overlay support.'''
+
+__version__ = "$Id$"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class CvsOverlay
+#
+#-------------------------------------------------------------------------------
+
+class CvsOverlay(Overlay):
+ ''' Handles cvs overlays.'''
+
+ type = 'cvs'
+
+ binary = '/usr/bin/cvs'
+
+ def __init__(self, xml, ignore = 0, quiet = False):
+
+ Overlay.__init__(self, xml, ignore, quiet)
+
+ if '&subpath' in self.data.keys():
+ self.subpath = self.data['&subpath']
+ else:
+ self.subpath = ''
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + base + '" && CVSROOT="' + self.src + '" ' +
+ self.binary + ' co -d "' + self.name
+ + '" "' + self.subpath + '"' )
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + path([base, self.name]) + '" && ' +
+ self.binary + ' update')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary, 'cvs',
+ 'dev-util/cvs'),])
diff --git a/overlays/darcs.py b/overlays/darcs.py
new file mode 100644
index 0000000..56e6d91
--- /dev/null
+++ b/overlays/darcs.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN DARCS OVERLAY HANDLER
+#################################################################################
+# File: darcs.py
+#
+# Handles darcs overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel, Andres Loeh
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+# Andres Loeh <kosmikus@gentoo.org>
+#
+''' Darcs overlay support.'''
+
+__version__ = "$Id: darcs.py 236 2006-09-05 20:39:37Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class BzrOverlay
+#
+#-------------------------------------------------------------------------------
+
+class DarcsOverlay(Overlay):
+ ''' Handles darcs overlays.'''
+
+ type = 'Darcs'
+
+ binary_command = '/usr/bin/darcs'
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.binary_command + ' get --partial "' + self.src +
+ '/" "' + path([base, self.name]) + '"')
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + path([base, self.name]) + '" && ' +
+ self.binary_command + ' pull --all "' + self.src + '"')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary_command, 'darcs',
+ 'dev-util/darcs'),])
diff --git a/overlays/git.py b/overlays/git.py
new file mode 100644
index 0000000..007e841
--- /dev/null
+++ b/overlays/git.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN GIT OVERLAY HANDLER
+#################################################################################
+# File: git.py
+#
+# Handles git overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel, Stefan Schweizer
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+# Stefan Schweizer <genstef@gentoo.org>
+''' Git overlay support.'''
+
+__version__ = "$Id: git.py 146 2006-05-27 09:52:36Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class GitOverlay
+#
+#-------------------------------------------------------------------------------
+
+class GitOverlay(Overlay):
+ ''' Handles git overlays.'''
+
+ type = 'Git'
+
+ binary_command = '/usr/bin/git'
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.binary_command + ' clone "' + self.src + '/" "'
+ + path([base, self.name]) + '"')
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + path([base, self.name]) + '" && '
+ + self.binary_command + ' pull')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary_command, 'git',
+ 'dev-util/git'),])
diff --git a/overlays/mercurial.py b/overlays/mercurial.py
new file mode 100644
index 0000000..3def5fc
--- /dev/null
+++ b/overlays/mercurial.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN MERCURIAL OVERLAY HANDLER
+#################################################################################
+# File: darcs.py
+#
+# Handles darcs overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel, Andres Loeh
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+# Andres Loeh <kosmikus@gentoo.org>
+#
+''' Mercurial overlay support.'''
+
+__version__ = "$Id: mercurial.py 236 2006-09-05 20:39:37Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class MercurialOverlay
+#
+#-------------------------------------------------------------------------------
+
+class MercurialOverlay(Overlay):
+ ''' Handles mercurial overlays.'''
+
+ type = 'Mercurial'
+
+ binary_command = '/usr/bin/hg'
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.binary_command + ' clone "' + self.src + '/" "' +
+ path([base, self.name]) + '"')
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd('cd "' + path([base, self.name]) + '" && ' +
+ self.binary_command + ' pull -u "' + self.src + '"')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary_command, 'mercurial',
+ 'dev-util/mercurial'),])
diff --git a/overlays/overlay.py b/overlays/overlay.py
new file mode 100644
index 0000000..b7a006f
--- /dev/null
+++ b/overlays/overlay.py
@@ -0,0 +1,266 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN OVERLAY BASE CLASS
+#################################################################################
+# File: overlay.py
+#
+# Base class for the different overlay types.
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+''' Basic overlay class.'''
+
+__version__ = "$Id: overlay.py 273 2006-12-30 15:54:50Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+import re, os, os.path, shutil, popen2
+
+from layman.utils import node_to_dict, dict_to_node, path
+
+from layman.debug import OUT
+
+#===============================================================================
+#
+# Class Overlay
+#
+#-------------------------------------------------------------------------------
+
+class Overlay:
+ ''' Derive the real implementations from this.'''
+
+ type = 'None'
+
+ def __init__(self, xml, ignore = 0, quiet = False):
+ '''
+ >>> here = os.path.dirname(os.path.realpath(__file__))
+ >>> document = open(here + '/../tests/testfiles/global-overlays.xml').read()
+ >>> import xml.dom.minidom
+ >>> document = xml.dom.minidom.parseString(document)
+ >>> overlays = document.getElementsByTagName('overlay')
+ >>> a = Overlay(overlays[0])
+ >>> a.name
+ u'wrobel'
+ >>> a.is_official()
+ True
+ >>> a.src
+ u'https://overlays.gentoo.org/svn/dev/wrobel'
+ >>> a.contact
+ u'nobody@gentoo.org'
+ >>> a.description
+ u'Test'
+ >>> a.priority
+ 10
+ >>> b = Overlay(overlays[1])
+ >>> b.is_official()
+ False
+ '''
+ self.quiet = quiet
+
+ self.data = node_to_dict(xml)
+
+ if '&name' in self.data.keys():
+ self.name = self.data['&name']
+ else:
+ raise Exception('Overlay is missing a "name" attribute!')
+
+ if '&src' in self.data.keys():
+ self.src = self.data['&src']
+ else:
+ raise Exception('Overlay "' + self.name + '" is missing a "src" '
+ 'attribute!')
+
+ if '&contact' in self.data.keys():
+ self.contact = self.data['&contact']
+ else:
+ self.contact = ''
+ if not ignore:
+ raise Exception('Overlay "' + self.name + '" is missing a '
+ '"contact" attribute!')
+ elif ignore == 1:
+ OUT.warn('Overlay "' + self.name + '" is missing a '
+ '"contact" attribute!', 4)
+
+ if '<description>1' in self.data.keys():
+ self.description = self.data['<description>1']['@'].strip()
+ else:
+ self.description = ''
+ if not ignore:
+ raise Exception('Overlay "' + self.name + '" is missing a '
+ '"description" entry!')
+ elif ignore == 1:
+ OUT.warn('Overlay "' + self.name + '" is missing a '
+ '"description" entry!', 4)
+
+ if '&status' in self.data.keys():
+ self.status = self.data['&status']
+ else:
+ self.status = ''
+
+ if '&priority' in self.data.keys():
+ self.priority = int(self.data['&priority'])
+ else:
+ self.priority = 50
+
+ def to_minidom(self, document):
+ '''Convert to xml.'''
+
+ return dict_to_node(self.data, document, 'overlay')
+
+ def add(self, base):
+ '''Add the overlay.'''
+
+ mdir = path([base, self.name])
+
+ if os.path.exists(mdir):
+ raise Exception('Directory ' + mdir + ' already exists. Will not ov'
+ 'erwrite its contents!')
+
+ os.makedirs(mdir)
+
+ def sync(self, base):
+ '''Sync the overlay.'''
+ pass
+
+ def delete(self, base):
+ '''Delete the overlay.'''
+ mdir = path([base, self.name])
+
+ if not os.path.exists(mdir):
+ raise Exception('Directory ' + mdir + ' does not exist. Cannot remo'
+ 've the overlay!')
+
+ shutil.rmtree(mdir)
+
+ def cmd(self, command):
+ '''Run a command.'''
+
+ OUT.info('Running command "' + command + '"...', 2)
+
+ if not self.quiet:
+ return os.system(command)
+ else:
+ cmd = popen2.Popen4(command)
+ cmd.fromchild.readlines()
+ result = cmd.wait()
+ cmd.fromchild.readlines()
+ cmd.fromchild.close()
+ cmd.tochild.close()
+ return result
+
+ def __str__(self):
+ '''
+ >>> here = os.path.dirname(os.path.realpath(__file__))
+ >>> document = open(here + '/../tests/testfiles/global-overlays.xml').read()
+ >>> import xml.dom.minidom
+ >>> document = xml.dom.minidom.parseString(document)
+ >>> overlays = document.getElementsByTagName('overlay')
+ >>> a = Overlay(overlays[0])
+ >>> print str(a)
+ wrobel
+ ~~~~~~
+ Source : https://overlays.gentoo.org/svn/dev/wrobel
+ Contact : nobody@gentoo.org
+ Type : None; Priority: 10
+ <BLANKLINE>
+ Description:
+ Test
+ <BLANKLINE>
+ '''
+
+ result = ''
+
+ result += self.name + '\n' + (len(self.name) * '~')
+
+ result += '\nSource : ' + self.src
+ result += '\nContact : ' + self.contact
+ result += '\nType : ' + self.type
+ result += '; Priority: ' + str(self.priority) + '\n'
+
+ description = self.description
+ description = re.compile(' +').sub(' ', description)
+ description = re.compile('\n ').sub('\n', description)
+ result += '\nDescription:'
+ result += '\n '.join(('\n' + description).split('\n'))
+ result += '\n'
+
+ if '<link>1' in self.data.keys():
+ link = self.data['<link>1']['@'].strip()
+ link = re.compile(' +').sub(' ', link)
+ link = re.compile('\n ').sub('\n', link)
+ result += '\nLink:\n'
+ result += '\n '.join(('\n' + link).split('\n'))
+ result += '\n'
+
+ return result
+
+ def short_list(self):
+ '''
+ >>> here = os.path.dirname(os.path.realpath(__file__))
+ >>> document = open(here + '/../tests/testfiles/global-overlays.xml').read()
+ >>> import xml.dom.minidom
+ >>> document = xml.dom.minidom.parseString(document)
+ >>> overlays = document.getElementsByTagName('overlay')
+ >>> a = Overlay(overlays[0])
+ >>> print a.short_list()
+ wrobel [None ] (source: https://overlays.gentoo.or...)
+ '''
+
+ def pad(string, length):
+ '''Pad a string with spaces.'''
+ if len(string) <= length:
+ return string + ' ' * (length - len(string))
+ else:
+ return string[:length - 3] + '...'
+
+ name = pad(self.name, 25)
+ mtype = ' [' + pad(self.type, 10) + ']'
+ source = ' (source: ' + pad(self.src, 29) + ')'
+
+ return name + mtype + source
+
+ def supported(self, binaries = []):
+ '''Is the overlay type supported?'''
+
+ if binaries:
+ for mpath, mtype, package in binaries:
+ if not os.path.exists(mpath):
+ raise Exception('Binary ' + mpath + ' seems to be missing!'
+ ' Overlay type "' + mtype + '" not support'
+ 'ed. Did you emerge ' + package + '?')
+
+ return True
+
+ def is_supported(self):
+ '''Is the overlay type supported?'''
+
+ try:
+ self.supported()
+ return True
+ except Exception, error:
+ return False
+
+ def is_official(self):
+ '''Is the overlay official?'''
+
+ return self.status == 'official'
+
+#================================================================================
+#
+# Testing
+#
+#--------------------------------------------------------------------------------
+
+if __name__ == '__main__':
+ import doctest, sys
+ doctest.testmod(sys.modules[__name__])
diff --git a/overlays/rsync.py b/overlays/rsync.py
new file mode 100644
index 0000000..e2483ad
--- /dev/null
+++ b/overlays/rsync.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN RSYNC OVERLAY HANDLER
+#################################################################################
+# File: rsync.py
+#
+# Handles rsync overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+''' Rsync overlay support.'''
+
+__version__ = "$Id: rsync.py 236 2006-09-05 20:39:37Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class RsyncOverlay
+#
+#-------------------------------------------------------------------------------
+
+class RsyncOverlay(Overlay):
+ ''' Handles rsync overlays.'''
+
+ type = 'Rsync'
+
+ binary = '/usr/bin/rsync'
+
+ base = binary + ' -rlptDvz --progress --delete --delete-after ' + \
+ '--timeout=180 --exclude="distfiles/*" --exclude="local/*" ' + \
+ '--exclude="packages/*" '
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ Overlay.add(self, base)
+
+ return self.sync(base)
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.base + '"' + self.src + '/*" "' +
+ path([base, self.name]) + '"')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary, 'rsync',
+ 'net-misc/rsync'),])
diff --git a/overlays/svn.py b/overlays/svn.py
new file mode 100644
index 0000000..5086448
--- /dev/null
+++ b/overlays/svn.py
@@ -0,0 +1,65 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN SVN OVERLAY HANDLER
+#################################################################################
+# File: svn.py
+#
+# Handles subversion overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+''' Subversion overlay support.'''
+
+__version__ = "$Id: svn.py 236 2006-09-05 20:39:37Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class SvnOverlay
+#
+#-------------------------------------------------------------------------------
+
+class SvnOverlay(Overlay):
+ ''' Handles subversion overlays.'''
+
+ type = 'Subversion'
+
+ binary = '/usr/bin/svn'
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ Overlay.add(self, base)
+
+ return self.cmd(self.binary + ' co "' + self.src + '/" "' +
+ path([base, self.name]) + '"')
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ return self.cmd(self.binary + ' update "' + path([base, self.name]) +
+ '"')
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary, 'svn',
+ 'dev-util/subversion'),])
diff --git a/overlays/tar.py b/overlays/tar.py
new file mode 100644
index 0000000..24a9b91
--- /dev/null
+++ b/overlays/tar.py
@@ -0,0 +1,189 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#################################################################################
+# LAYMAN TAR OVERLAY HANDLER
+#################################################################################
+# File: tar.py
+#
+# Handles tar overlays
+#
+# Copyright:
+# (c) 2005 - 2006 Gunnar Wrobel
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Gunnar Wrobel <wrobel@gentoo.org>
+#
+''' Tar overlay support.'''
+
+__version__ = "$Id: tar.py 310 2007-04-09 16:30:40Z wrobel $"
+
+#===============================================================================
+#
+# Dependencies
+#
+#-------------------------------------------------------------------------------
+
+import os, os.path, sys, urllib2, shutil
+
+from layman.utils import path
+from layman.overlays.overlay import Overlay
+
+#===============================================================================
+#
+# Class TarOverlay
+#
+#-------------------------------------------------------------------------------
+
+class TarOverlay(Overlay):
+ ''' Handles tar overlays.
+
+ A dummy tar handler that overwrites the __init__ method
+ so that we don't need to provide xml input:
+
+ >>> from layman.debug import OUT
+ >>> class DummyTar(TarOverlay):
+ ... def __init__(self):
+ ... self.name = 'dummy'
+ ... here = os.path.dirname(os.path.realpath(__file__))
+ ... self.src = 'file://' + here + '/../tests/testfiles/layman-test.tar.bz2'
+ ... self.subpath = 'layman-test'
+ ... self.format = 'bz2'
+ ... self.quiet = False
+ >>> testdir = os.tmpnam()
+ >>> os.mkdir(testdir)
+ >>> a = DummyTar()
+ >>> OUT.color_off()
+ >>> a.add(testdir) #doctest: +ELLIPSIS
+ * Running command "/bin/tar -v -x -j -f...
+ >>> sorted(os.listdir(testdir + '/dummy'))
+ ['app-admin', 'app-portage']
+ >>> shutil.rmtree(testdir)
+ '''
+
+ type = 'Tar'
+
+ binary = '/bin/tar'
+
+ def __init__(self, xml, ignore = 0, quiet = False):
+
+ Overlay.__init__(self, xml, ignore)
+
+ if '&format' in self.data.keys():
+ self.format = self.data['&format']
+ else:
+ self.format = ''
+
+ if '&subpath' in self.data.keys():
+ self.subpath = self.data['&subpath']
+ else:
+ self.subpath = ''
+
+ if '&category' in self.data.keys():
+ if self.subpath:
+ raise Exception('Cannot use "category" and "subpath" at the same'
+ ' time!')
+
+ self.category = self.data['&category']
+ else:
+ self.category = ''
+
+ def add(self, base):
+ '''Add overlay.'''
+
+ self.supported()
+
+ mdir = path([base, self.name])
+
+ if os.path.exists(mdir):
+ raise Exception('Directory ' + mdir + ' already exists. Will not ov'
+ 'erwrite its contents!')
+
+ if self.format == 'bz2' or (not self.format and self.src[-3:] == 'bz2'):
+ ext = 'bz2'
+ opt = '-j'
+ elif self.format == 'gz' or (not self.format and self.src[-2:] == 'gz'):
+ ext = 'gz'
+ opt = '-z'
+ else:
+ raise Exception('Unsupported file format!')
+
+ try:
+
+ tar = urllib2.urlopen(self.src).read()
+
+ except Exception, error:
+ raise Exception('Failed to fetch the tar package from: '
+ + self.src + '\nError was:' + str(error))
+
+ pkg = path([base, self.name + '.tar.' + ext])
+
+ try:
+
+ out_file = open(pkg, 'w')
+ out_file.write(tar)
+ out_file.close()
+
+ except Exception, error:
+ raise Exception('Failed to store tar package in '
+ + pkg + '\nError was:' + str(error))
+
+ if self.subpath:
+ target = path([base, 'tmp'])
+ else:
+ if self.category:
+ target = mdir + '/' + self.category
+ else:
+ target = mdir
+
+ os.makedirs(target)
+
+ result = self.cmd(self.binary + ' -v -x ' + opt + ' -f "' + pkg
+ + '" -C "' + target + '"')
+
+ if self.subpath:
+ source = target + '/' + self.subpath
+ if os.path.exists(source):
+ try:
+ os.rename(source, mdir)
+ except Exception, error:
+ raise Exception('Failed to rename tar subdirectory ' +
+ source + ' to ' + mdir + '\nError was:'
+ + str(error))
+ else:
+ raise Exception('Given subpath "' + source + '" does not exist '
+ ' in the tar package!')
+ try:
+ shutil.rmtree(target)
+ except Exception, error:
+ raise Exception('Failed to remove unnecessary tar structure "'
+ + target + '"\nError was:' + str(error))
+
+ os.unlink(pkg)
+
+ return result
+
+ def sync(self, base):
+ '''Sync overlay.'''
+
+ self.supported()
+
+ self.delete(base)
+
+ self.add(base)
+
+ def supported(self):
+ '''Overlay type supported?'''
+
+ return Overlay.supported(self, [(self.binary, 'tar', 'app-arch/tar'), ])
+
+if __name__ == '__main__':
+ import doctest
+
+ # Ignore warnings here. We are just testing
+ from warnings import filterwarnings, resetwarnings
+ filterwarnings('ignore')
+
+ doctest.testmod(sys.modules[__name__])
+
+ resetwarnings()