Skip to content
Snippets Groups Projects
Commit 5b801534 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Move get_os_class from image_creator to os_type

This is needed because otherwise setup.py fails on some systems. Also
do some more cleanup.
parent 2a9836b1
No related branches found
Tags 0.7.4
No related merge requests found
......@@ -33,24 +33,4 @@
__version__ = '0.1'
import image_creator.os_type
def get_os_class(distro, osfamily):
module = None
classname = None
try:
module = __import__("image_creator.os_type.%s"
% distro, fromlist=['image_creator.os_type'])
classname = distro.capitalize()
except ImportError:
module = __import__("image_creator.os_type.%s"
% osfamily, fromlist=['image_creator.os_type'])
classname = osfamily.capitalize()
return getattr(module, classname)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
......@@ -120,8 +120,7 @@ class Disk(object):
os.close(cowfd)
self._add_cleanup(os.unlink, cow)
# Create 1G cow sparse file
dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', \
'seek=%d' % (1024 * 1024))
dd('if=/dev/null', 'of=%s' % cow, 'bs=1k', 'seek=%d' % (1024 * 1024))
cowdev = self._losetup(cow)
snapshot = uuid.uuid4().hex
......@@ -273,7 +272,7 @@ class DiskDevice(object):
if self.parttype == 'msdos' and last_partition['part_num'] > 4:
raise FatalError("This disk contains logical partitions. "
"Only primary partitions are supported.")
"Only primary partitions are supported.")
part_dev = "%s%d" % (self.guestfs_device, last_partition['part_num'])
fs_type = self.g.vfs_type(part_dev)
......@@ -299,8 +298,7 @@ class DiskDevice(object):
self.g.part_add(self.guestfs_device, 'p', start, end)
self.size = (end + 1) * sector_size
success("new image size is %dMB" %
((self.size + 2 ** 20 - 1) // 2 ** 20))
success("new size is %dMB" % ((self.size + 2 ** 20 - 1) // 2 ** 20))
if self.parttype == 'gpt':
ptable = GPTPartitionTable(self.real_device)
......@@ -318,15 +316,15 @@ class DiskDevice(object):
progress_size = (self.size + 2 ** 20 - 1) // 2 ** 20 # in MB
progressbar = progress("Dumping image file: ", 'mb')
progressbar.max = progress_size
with open(self.real_device, 'r') as source:
with open(outfile, "w") as dest:
with open(self.real_device, 'r') as src:
with open(outfile, "w") as dst:
left = self.size
offset = 0
progressbar.next()
while left > 0:
length = min(left, blocksize)
sent = sendfile(dest.fileno(), source.fileno(), offset,
length)
sent = sendfile(dst.fileno(), src.fileno(), offset, length)
offset += sent
left -= sent
progressbar.goto((self.size - left) // 2 ** 20)
......
......@@ -232,7 +232,7 @@ class GPTPartitionTable(object):
def __init__(self, disk):
self.disk = disk
with open(disk, "rb") as d:
#MBR (Logical block address 0)
# MBR (Logical block address 0)
lba0 = d.read(BLOCKSIZE)
self.mbr = MBR(lba0)
......
......@@ -33,20 +33,18 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from image_creator import get_os_class
from image_creator import __version__ as version
from image_creator import util
from image_creator.disk import Disk
from image_creator.util import get_command, error, success, output, \
FatalError, progress, md5
from image_creator.os_type import get_os_class
from image_creator.kamaki_wrapper import Kamaki
import sys
import os
import optparse
import StringIO
dd = get_command('dd')
def check_writable_dir(option, opt_str, value, parser):
dirname = os.path.dirname(value)
......@@ -145,8 +143,8 @@ def image_creator():
if options.outfile is None and not options.upload \
and not options.print_sysprep:
raise FatalError("At least one of `-o', `-u' or" \
"`--print-sysprep' must be set")
raise FatalError("At least one of `-o', `-u' or `--print-sysprep' " \
"must be set")
title = 'snf-image-creator %s' % version
output(title)
......@@ -199,7 +197,7 @@ def image_creator():
checksum = md5(snapshot, size)
metastring = '\n'.join(
['%s=%s' % (key, value) for (key, value) in metadata.items()])
['%s=%s' % (key, value) for (key, value) in metadata.items()])
metastring += '\n'
if options.outfile is not None:
......@@ -207,13 +205,13 @@ def image_creator():
output('Dumping metadata file...', False)
with open('%s.%s' % (options.outfile, 'meta'), 'w') as f:
f.write(metastring)
f.write(metastring)
success('done')
output('Dumping md5sum file...', False)
with open('%s.%s' % (options.outfile, 'md5sum'), 'w') as f:
f.write('%s %s\n' % (
checksum, os.path.basename(options.outfile)))
f.write('%s %s\n' % (checksum, \
os.path.basename(options.outfile)))
success('done')
# Destroy the device. We only need the snapshot from now on
......
......@@ -37,6 +37,21 @@ import textwrap
import re
def get_os_class(distro, osfamily):
module = None
classname = None
try:
module = __import__("image_creator.os_type.%s"
% distro, fromlist=['image_creator.os_type'])
classname = distro.capitalize()
except ImportError:
module = __import__("image_creator.os_type.%s"
% osfamily, fromlist=['image_creator.os_type'])
classname = osfamily.capitalize()
return getattr(module, classname)
def add_prefix(target):
def wrapper(self, *args):
prefix = args[0]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment