summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpuppet-host-package2
-rw-r--r--puppethost.py36
2 files changed, 26 insertions, 12 deletions
diff --git a/puppet-host-package b/puppet-host-package
index 60ef9d1..56b0f32 100755
--- a/puppet-host-package
+++ b/puppet-host-package
@@ -55,6 +55,8 @@ def _main():
help='RPM spec file template [%default]')
parser.add_option('-v', '--verbose', dest='verbose', action='count',
help='Be verbose (may be used more than once)')
+ parser.add_option('--package-type',
+ help='Package type (%s) [%s]' % (', '.join(sorted(puppethost.package_types)), '%default'))
opts, args = parser.parse_args()
if opts.force:
diff --git a/puppethost.py b/puppethost.py
index 793cd5f..1a9323a 100644
--- a/puppethost.py
+++ b/puppethost.py
@@ -39,6 +39,7 @@ defaults = {
'sign': True,
'ssldir': '/etc/puppet/ssl',
'template': '%(ssldir)s/template.spec',
+ 'package_type': 'rpm',
'pkgprefix': 'host-package-',
'puppetuser': 'puppet',
'verbose': 1,
@@ -67,7 +68,7 @@ for config in configs:
except:
defaults[opt] = 0
-package_types = ['deb', 'rpm']
+package_types = ['deb', 'rpm', 'tar']
def sign(packages, key=''):
"""Sign packages."""
@@ -149,15 +150,16 @@ class PuppetHost(object):
self._version = time.strftime(self.datefmt)
- def package(self, packages = ['rpm']):
- """Create packages in requested format."""
- for package in packages:
- if package not in package_types or not hasattr(self, package):
- raise PuppetHostError('Bogus package type: %s' % package)
- try: getattr(self, package)()
- except Exception, error:
- print error
- continue
+ def package(self, ptype = None):
+ """Create a package in the requested format."""
+ if ptype is None:
+ ptype = self.opts['package_type']
+ if ptype not in package_types or not hasattr(self, ptype):
+ raise PuppetHostError('Bogus package type: %s' % ptype)
+ try:
+ getattr(self, ptype)()
+ except Exception, error:
+ print error
def deb(self):
"""Create a .deb package."""
@@ -168,7 +170,8 @@ class PuppetHost(object):
self._check_files()
name = '%s%s-%s' % (self.opts['pkgprefix'], self.hostname, self.version)
- tarball = '%s/%s.tar.gz' % (self.tmpdir, name)
+ destdir = self.opts['package_type'] == 'tar' and self.opts['destdir'] or self.tmpdir
+ tarball = '%s/%s.tar.gz' % (destdir, name)
if os.path.exists(tarball) and not self.opts['force_tarball']:
raise PuppetHostError('%s exists, not overwriting' % tarball)
@@ -179,12 +182,21 @@ class PuppetHost(object):
tar = tarfile.open(tarball, 'w:gz')
tar.dereference = True
+ # Add the ssldir tarball if tar is the package type
+ if self.opts['package_type'] == 'tar':
+ tar.add(self.opts['ssldir'], recursive=False)
for f in sorted(self.files.values()):
- arcname = '%s%s' % (name, f.replace(self.opts['ssldir'], ''))
+ arcname = None
+ # Adjust the path in the archive if tar is not the package type
+ if self.opts['package_type'] != 'tar':
+ arcname = '%s%s' % (name, f.replace(self.opts['ssldir'], ''))
tar.add(f, arcname)
tar.close()
self.tarball = tarball
+ if self.opts['package_type'] == 'tar':
+ self.packages.append(('tar', tarball))
+
if self.opts['verbose']:
print 'done'