# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os, sys
-import re
+import os
import tempfile
import glob
from string import Template
from mic.utils.proxy import get_proxy_for
from mic.utils.errors import CreatorError
from mic.utils.safeurl import SafeURL
-from mic.imager.baseimager import BaseImageCreator
YUMCONF_TEMP = """[main]
% (os.path.basename(local), local))
else:
download_total_size -= int(po.packagesize)
- cached_count +=1
+ cached_count += 1
cache_avail_size = misc.get_filesystem_avail(self.cachedir)
if cache_avail_size < download_total_size:
def _zyppQueryPackage(self, pkg):
query = zypp.PoolQuery()
query.addKind(zypp.ResKind.package)
- query.addAttribute(zypp.SolvAttr.name,pkg)
+ query.addAttribute(zypp.SolvAttr.name, pkg)
query.setMatchExact()
for pi in query.queryResults(self.Z.pool()):
return pi
return None
def _splitPkgString(self, pkg):
- sp = pkg.rsplit(".",1)
+ sp = pkg.rsplit(".", 1)
name = sp[0]
arch = None
if len(sp) == 2:
if endx and startx:
pattern = '%s' % (pkg[1:-1])
q.setMatchRegex()
- q.addAttribute(zypp.SolvAttr.name,pattern)
+ q.addAttribute(zypp.SolvAttr.name, pattern)
elif arch:
q.setMatchExact()
- q.addAttribute(zypp.SolvAttr.name,name)
+ q.addAttribute(zypp.SolvAttr.name, name)
else:
q.setMatchExact()
- q.addAttribute(zypp.SolvAttr.name,pkg)
+ q.addAttribute(zypp.SolvAttr.name, pkg)
for pitem in sorted(
q.queryResults(self.Z.pool()),
if not ispattern:
if pkgarch:
if name == pkgname and str(item.arch()) == pkgarch:
- return True;
+ return True
else:
if name == pkgname:
- return True;
+ return True
else:
if startx and name.endswith(pkg[1:]):
- return True;
+ return True
if endx and name.startswith(pkg[:-1]):
- return True;
+ return True
- return False;
+ return False
def deselectPackage(self, pkg):
"""collect packages should not be installed"""
if not self.Z:
self.__initialize_zypp()
found = False
- q=zypp.PoolQuery()
+ q = zypp.PoolQuery()
q.addKind(zypp.ResKind.pattern)
for pitem in q.queryResults(self.Z.pool()):
item = zypp.asKindPattern(pitem)
if not ssl_verify:
baseurl.setQueryParam("ssl_verify", "no")
if proxy:
- scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
+ host = urlparse.urlparse(proxy)[1]
+ # scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
proxyinfo = host.rsplit(":", 1)
host = proxyinfo[0]
def getLocalPkgPath(self, po):
repoinfo = po.repoInfo()
cacheroot = repoinfo.packagesPath()
- location= po.location()
+ location = po.location()
rpmpath = str(location.filename())
pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
return pkgpath
% (package, deppkg))
elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
- msger.warning("[%s] Conflicts with [%s]" %(package,deppkg))
+ msger.warning("[%s] Conflicts with [%s]" % (package, deppkg))
raise RepoError("Unresolved dependencies, transaction failed.")
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import os
-import sys
-
from mic import chroot, msger, rt_util
from mic.utils import cmdln, misc, errors, fs_related
from mic.imager import fs
@classmethod
@cmdln.option("--include-src",
- dest="include_src",
- action="store_true",
- default=False,
- help="Generate a image with source rpms included")
+ dest = "include_src",
+ action = "store_true",
+ default = False,
+ help = "Generate a image with source rpms included")
def do_create(self, subcmd, opts, *args):
"""${cmd_name}: create fs image
configmgr._ksconf = ksconf
- # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
+ # Called After setting the configmgr._ksconf as the
+ # creatoropts['name'] is reset there.
if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
+ creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'],
+ creatoropts['release'], creatoropts['name'])
# try to find the pkgmgr
pkgmgr = None
installed_pkgs = creator.get_installed_packages()
msger.info('--------------------------------------------------')
msger.info('Generating the image with source rpms included ...')
- if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]):
+ if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"],
+ creator._instroot, creatoropts["cachedir"]):
msger.warning("Source packages can't be downloaded")
creator.configure(creatoropts["repomd"])
creator.package(creatoropts["outdir"])
creator.create_manifest()
if creatoropts['release'] is not None:
- creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
+ creator.release_output(ksconf, creatoropts['outdir'],
+ creatoropts['release'])
creator.print_outimage_info()
except errors.CreatorError:
raise
name = 'raw'
@classmethod
- @cmdln.option("--compress-disk-image", dest="compress_image", type='choice',
- choices=("gz", "bz2", "lzo"), default=None,
- help="Same with --compress-image")
- @cmdln.option("--compress-image", dest="compress_image", type='choice',
- choices=("gz", "bz2", "lzo"), default=None,
- help="Compress all raw images before package, Note: if you want "
+ @cmdln.option("--compress-disk-image", dest = "compress_image", type = 'choice',
+ choices = ("gz", "bz2", "lzo"), default = None,
+ help = "Same with --compress-image")
+ @cmdln.option("--compress-image", dest = "compress_image", type = 'choice',
+ choices = ("gz", "bz2", "lzo"), default = None,
+ help = "Compress all raw images before package, Note: if you want "
"to use 'lzo', package 'lzop' is needed to be installed manually.")
- @cmdln.option("--generate-bmap", action="store_true", default = None,
- help="also generate the block map file")
- @cmdln.option("--fstab-entry", dest="fstab_entry", type='choice',
- choices=("name", "uuid"), default="uuid",
- help="Set fstab entry, 'name' means using device names, "
+ @cmdln.option("--generate-bmap", action = "store_true", default = None,
+ help = "also generate the block map file")
+ @cmdln.option("--fstab-entry", dest = "fstab_entry", type = 'choice',
+ choices = ("name", "uuid"), default = "uuid",
+ help = "Set fstab entry, 'name' means using device names, "
"'uuid' means using filesystem uuid")
def do_create(self, subcmd, opts, *args):
"""${cmd_name}: create raw image
# Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
if creatoropts['release'] is not None:
- creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
+ creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'],
+ creatoropts['release'], creatoropts['name'])
# try to find the pkgmgr
pkgmgr = None
else:
root_mounted = False
partition_mounts = 0
- for line in runner.outs([partedcmd,"-s",img,"unit","B","print"]).splitlines():
+ for line in runner.outs([ partedcmd, "-s", img, "unit", "B", "print" ]).splitlines():
line = line.strip()
# Lines that start with number are the partitions,
line = line.replace(",","")
# Example of parted output lines that are handled:
- # Number Start End Size Type File system Flags
+ # Number Start End Size Type File system Flags
# 1 512B 3400000511B 3400000000B primary
# 2 3400531968B 3656384511B 255852544B primary linux-swap(v1)
- # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba
+ # 3 3656384512B 3720347647B 63963136B primary fat16 boot, lba
- partition_info = re.split("\s+",line)
+ partition_info = re.split("\s+", line)
size = partition_info[3].split("B")[0]
# not recognize properly.
# TODO: Can we make better assumption?
fstype = "btrfs"
- elif partition_info[5] in ["ext2","ext3","ext4","btrfs"]:
+ elif partition_info[5] in [ "ext2", "ext3", "ext4", "btrfs" ]:
fstype = partition_info[5]
- elif partition_info[5] in ["fat16","fat32"]:
+ elif partition_info[5] in [ "fat16", "fat32" ]:
fstype = "vfat"
elif "swap" in partition_info[5]:
fstype = "swap"
else:
- raise errors.CreatorError("Could not recognize partition fs type '%s'." % partition_info[5])
+ raise errors.CreatorError("Could not recognize partition fs type '%s'." %
+ partition_info[5])
if rootpart and rootpart == line[0]:
mountpoint = '/'
- elif not root_mounted and fstype in ["ext2","ext3","ext4","btrfs"]:
+ elif not root_mounted and fstype in [ "ext2", "ext3", "ext4", "btrfs" ]:
# TODO: Check that this is actually the valid root partition from /etc/fstab
mountpoint = "/"
root_mounted = True
else:
boot = False
- msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" % (size, fstype, mountpoint, boot))
+ msger.verbose("Size: %s Bytes, fstype: %s, mountpoint: %s, boot: %s" %
+ (size, fstype, mountpoint, boot))
# TODO: add_partition should take bytes as size parameter.
- imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint, fstype = fstype, boot = boot)
+ imgloop.add_partition((int)(size)/1024/1024, "/dev/sdb", mountpoint,
+ fstype = fstype, boot = boot)
try:
imgloop.mount()
@cmdln.alias("cv")
@cmdln.option("-S", "--shell",
- action="store_true", dest="shell", default=False,
- help="Launch shell before packaging the converted image")
+ action = "store_true", dest = "shell", default = False,
+ help = "Launch shell before packaging the converted image")
def do_convert(self, subcmd, opts, *args):
"""${cmd_name}: convert image format
@cmdln.alias("ch")
@cmdln.option('-s', '--saveto',
- action='store', dest='saveto', default=None,
- help="Save the unpacked image to specified dir")
+ action = 'store', dest = 'saveto', default = None,
+ help = "Save the unpacked image to specified dir")
@optparser_setup
def do_chroot(self, subcmd, opts, *args):
"""${cmd_name}: chroot into an image