__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 :
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
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)
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)
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)
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)
# 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)
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)
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:
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
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]