From: JF Ding Date: Sat, 20 Aug 2011 03:47:57 +0000 (+0800) Subject: more cleanup X-Git-Tag: 0.1~184 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0c413ab301cd96f87ca3c47ac907c711f95d611;p=tools%2Fmic.git more cleanup --- diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py index 9055f80..8454421 100644 --- a/mic/kickstart/__init__.py +++ b/mic/kickstart/__init__.py @@ -20,7 +20,6 @@ import os, sys import shutil import subprocess import time -import logging import string from mic.utils import errors @@ -671,7 +670,7 @@ def get_repos(ks, repo_urls = {}): mirrorlist = None if repos.has_key(repo.name): - logging.warn("Overriding already specified repo %s" %(repo.name,)) + msger.warning("Overriding already specified repo %s" %(repo.name,)) proxy = None if hasattr(repo, "proxy"): diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index 68eea53..9ccde56 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -24,7 +24,6 @@ import stat import subprocess import random import string -import logging import time import fcntl import struct @@ -347,7 +346,7 @@ class LoopbackDisk(Disk): device = losetupOutput.split()[0] - logging.debug("Losetup add %s mapping to %s" % (device, self.lofile)) + msger.debug("Losetup add %s mapping to %s" % (device, self.lofile)) rc = subprocess.call([self.losetupcmd, device, self.lofile]) if rc != 0: raise MountError("Failed to allocate loop device for '%s'" % @@ -357,7 +356,7 @@ class LoopbackDisk(Disk): def cleanup(self): if self.device is None: return - logging.debug("Losetup remove %s" % self.device) + msger.debug("Losetup remove %s" % self.device) rc = subprocess.call([self.losetupcmd, "-d", self.device]) self.device = None @@ -378,7 +377,7 @@ class SparseLoopbackDisk(LoopbackDisk): if size is None: size = self.size - logging.debug("Extending sparse file %s to %d" % (self.lofile, size)) + msger.debug("Extending sparse file %s to %d" % (self.lofile, size)) if create: fd = os.open(self.lofile, flags, 0644) else: @@ -392,7 +391,7 @@ class SparseLoopbackDisk(LoopbackDisk): if size is None: size = self.size - logging.debug("Truncating sparse file %s to %d" % (self.lofile, size)) + msger.debug("Truncating sparse file %s to %d" % (self.lofile, size)) fd = os.open(self.lofile, os.O_WRONLY) os.ftruncate(fd, size) os.close(fd) @@ -439,7 +438,7 @@ class DiskMount(Mount): def unmount(self): if self.mounted: - logging.debug("Unmounting directory %s" % self.mountdir) + msger.debug("Unmounting directory %s" % self.mountdir) synccmd = find_binary_path("sync") subprocess.call([synccmd]) # sync the data on this mount point rc = subprocess.call([self.umountcmd, "-l", self.mountdir]) @@ -464,13 +463,13 @@ class DiskMount(Mount): return if not os.path.isdir(self.mountdir): - logging.debug("Creating mount point %s" % self.mountdir) + msger.debug("Creating mount point %s" % self.mountdir) os.makedirs(self.mountdir) self.rmdir = self.rmmountdir self.__create() - logging.debug("Mounting %s at %s" % (self.disk.device, self.mountdir)) + msger.debug("Mounting %s at %s" % (self.disk.device, self.mountdir)) if options: args = [ self.mountcmd, "-o", options, self.disk.device, self.mountdir ] else: @@ -506,9 +505,9 @@ class ExtDiskMount(DiskMount): def __format_filesystem(self): if self.skipformat: - logging.debug("Skip filesystem format.") + msger.debug("Skip filesystem format.") return - logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) + msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) rc = subprocess.call([self.mkfscmd, "-F", "-L", self.fslabel, "-m", "1", "-b", str(self.blocksize), @@ -527,7 +526,7 @@ class ExtDiskMount(DiskMount): os.close(dev_null) self.uuid = self.__parse_field(out, "Filesystem UUID") - logging.debug("Tuning filesystem on %s" % self.disk.device) + msger.debug("Tuning filesystem on %s" % self.disk.device) subprocess.call([self.tune2fs, "-c0", "-i0", "-Odir_index", "-ouser_xattr,acl", self.disk.device], stdout=sys.stdout, stderr=sys.stderr) @@ -566,7 +565,7 @@ class ExtDiskMount(DiskMount): DiskMount.mount(self, options) def __fsck(self): - logging.debug("Checking filesystem %s" % self.disk.lofile) + msger.debug("Checking filesystem %s" % self.disk.lofile) subprocess.call(["/sbin/e2fsck", "-f", "-y", self.disk.lofile], stdout=sys.stdout, stderr=sys.stderr) def __get_size_from_filesystem(self): @@ -618,14 +617,14 @@ class VfatDiskMount(DiskMount): def __format_filesystem(self): if self.skipformat: - logging.debug("Skip filesystem format.") + msger.debug("Skip filesystem format.") return - logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) + msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) blah = [self.mkfscmd, "-n", self.fslabel, "-i", self.uuid, self.disk.device] rc = subprocess.call(blah) if rc != 0: raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device)) - logging.debug("Tuning filesystem on %s" % self.disk.device) + msger.debug("Tuning filesystem on %s" % self.disk.device) def __resize_filesystem(self, size = None): current_size = os.stat(self.disk.lofile)[stat.ST_SIZE] @@ -661,7 +660,7 @@ class VfatDiskMount(DiskMount): DiskMount.mount(self, options) def __fsck(self): - logging.debug("Checking filesystem %s" % self.disk.lofile) + msger.debug("Checking filesystem %s" % self.disk.lofile) subprocess.call([self.fsckcmd, "-y", self.disk.lofile]) def __get_size_from_filesystem(self): @@ -722,9 +721,9 @@ class BtrfsDiskMount(DiskMount): def __format_filesystem(self): if self.skipformat: - logging.debug("Skip filesystem format.") + msger.debug("Skip filesystem format.") return - logging.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) + msger.debug("Formating %s filesystem on %s" % (self.fstype, self.disk.device)) rc = subprocess.call([self.mkfscmd, "-L", self.fslabel, self.disk.device]) if rc != 0: raise MountError("Error creating %s filesystem on disk %s" % (self.fstype,self.disk.device)) @@ -771,7 +770,7 @@ class BtrfsDiskMount(DiskMount): DiskMount.mount(self, options) def __fsck(self): - logging.debug("Checking filesystem %s" % self.disk.lofile) + msger.debug("Checking filesystem %s" % self.disk.lofile) subprocess.call([self.btrfsckcmd, self.disk.lofile]) def __get_size_from_filesystem(self): diff --git a/mic/utils/partitionedfs.py b/mic/utils/partitionedfs.py index 79999d3..5ac25a4 100644 --- a/mic/utils/partitionedfs.py +++ b/mic/utils/partitionedfs.py @@ -19,15 +19,14 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os -import os.path import glob import shutil import subprocess -import logging import time from mic.utils.errors import * from mic.utils.fs_related import * +from mic import msger class PartitionedMount(Mount): def __init__(self, disks, mountdir, skipformat = False): @@ -111,19 +110,19 @@ class PartitionedMount(Mount): def __create_part_to_image(self,device, parttype, fstype, start, size): # Start is included to the size so we need to substract one from the end. end = start+size-1 - logging.debug("Added '%s' part at %d of size %d" % (parttype,start,end)) + msger.debug("Added '%s' part at %d of size %d" % (parttype,start,end)) part_cmd = [self.parted, "-s", device, "unit", "s", "mkpart", parttype] if fstype: part_cmd.extend([fstype]) part_cmd.extend(["%d" % start, "%d" % end]) - logging.debug(part_cmd) + msger.debug(part_cmd) p1 = subprocess.Popen(part_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) return p1 def __format_disks(self): - logging.debug("Assigning partitions to disks") + msger.debug("Assigning partitions to disks") mbr_sector_skipped = False @@ -153,27 +152,27 @@ class PartitionedMount(Mount): p['start'] = d['offset'] d['offset'] += p['size'] d['partitions'].append(n) - logging.debug("Assigned %s to %s%d at %d at size %d" % (p['mountpoint'], p['disk'], p['num'], p['start'], p['size'])) + msger.debug("Assigned %s to %s%d at %d at size %d" % (p['mountpoint'], p['disk'], p['num'], p['start'], p['size'])) if self.skipformat: - logging.debug("Skipping disk format, because skipformat flag is set.") + msger.debug("Skipping disk format, because skipformat flag is set.") return for dev in self.disks.keys(): d = self.disks[dev] - logging.debug("Initializing partition table for %s" % (d['disk'].device)) + msger.debug("Initializing partition table for %s" % (d['disk'].device)) p1 = subprocess.Popen([self.parted, "-s", d['disk'].device, "mklabel", "msdos"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: # NOTE: We don't throw exception when return code is not 0, because # parted always fails to reload part table with loop devices. # This prevents us from distinguishing real errors based on return code. - logging.debug("WARNING: parted returned '%s' instead of 0 when creating partition-table for disk '%s'." % (p1.returncode,d['disk'].device)) + msger.debug("WARNING: parted returned '%s' instead of 0 when creating partition-table for disk '%s'." % (p1.returncode,d['disk'].device)) - logging.debug("Creating partitions") + msger.debug("Creating partitions") for p in self.partitions: d = self.disks[p['disk']] @@ -193,7 +192,7 @@ class PartitionedMount(Mount): # Boot ROM of OMAP boards require vfat boot partition to have an # even number of sectors. if p['mountpoint'] == "/boot" and p['fstype'] in ["vfat","msdos"] and p['size'] % 2: - logging.debug("Substracting one sector from '%s' partition to get even number of sectors for the partition." % (p['mountpoint'])) + msger.debug("Substracting one sector from '%s' partition to get even number of sectors for the partition." % (p['mountpoint'])) p['size'] -= 1 p1 = self.__create_part_to_image(d['disk'].device,p['type'], @@ -204,22 +203,22 @@ class PartitionedMount(Mount): # NOTE: We don't throw exception when return code is not 0, because # parted always fails to reload part table with loop devices. # This prevents us from distinguishing real errors based on return code. - logging.debug("WARNING: parted returned '%s' instead of 0 when creating partition '%s' for disk '%s'." % (p1.returncode,p['mountpoint'],d['disk'].device)) + msger.debug("WARNING: parted returned '%s' instead of 0 when creating partition '%s' for disk '%s'." % (p1.returncode,p['mountpoint'],d['disk'].device)) if p['boot']: - logging.debug("Setting boot flag for partition '%s' on disk '%s'." % (p['num'],d['disk'].device)) + msger.debug("Setting boot flag for partition '%s' on disk '%s'." % (p['num'],d['disk'].device)) boot_cmd = [self.parted, "-s", d['disk'].device, "set", "%d" % p['num'], "boot", "on"] - logging.debug(boot_cmd) + msger.debug(boot_cmd) p1 = subprocess.Popen(boot_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: # NOTE: We don't throw exception when return code is not 0, because # parted always fails to reload part table with loop devices. # This prevents us from distinguishing real errors based on return code. - logging.debug("WARNING: parted returned '%s' instead of 0 when adding boot flag for partition '%s' disk '%s'." % (p1.returncode,p['num'],d['disk'].device)) + msger.debug("WARNING: parted returned '%s' instead of 0 when adding boot flag for partition '%s' disk '%s'." % (p1.returncode,p['num'],d['disk'].device)) def __map_partitions(self): """Load it if dm_snapshot isn't loaded""" @@ -231,7 +230,7 @@ class PartitionedMount(Mount): if d['mapped']: continue - logging.debug("Running kpartx on %s" % d['disk'].device ) + msger.debug("Running kpartx on %s" % d['disk'].device ) kpartx = subprocess.Popen([self.kpartx, "-l", "-v", d['disk'].device], stdout=subprocess.PIPE, stderr=dev_null) @@ -262,7 +261,7 @@ class PartitionedMount(Mount): mapperdev = "/dev/mapper/" + newdev loopdev = d['disk'].device + newdev[-1] - logging.debug("Dev %s: %s -> %s" % (newdev, loopdev, mapperdev)) + msger.debug("Dev %s: %s -> %s" % (newdev, loopdev, mapperdev)) pnum = d['partitions'][i] self.partitions[pnum]['device'] = loopdev @@ -274,12 +273,12 @@ class PartitionedMount(Mount): os.unlink(loopdev) os.symlink(mapperdev, loopdev) - logging.debug("Adding partx mapping for %s" % d['disk'].device) + msger.debug("Adding partx mapping for %s" % d['disk'].device) p1 = subprocess.Popen([self.kpartx, "-v", "-a", d['disk'].device], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: # Make sure that the device maps are also removed on error case. @@ -301,13 +300,13 @@ class PartitionedMount(Mount): if not d['mapped']: continue - logging.debug("Removing compat symlinks") + msger.debug("Removing compat symlinks") for pnum in d['partitions']: if self.partitions[pnum]['device'] != None: os.unlink(self.partitions[pnum]['device']) self.partitions[pnum]['device'] = None - logging.debug("Unmapping %s" % d['disk'].device) + msger.debug("Unmapping %s" % d['disk'].device) rc = subprocess.call([self.kpartx, "-d", d['disk'].device], stdout=dev_null, stderr=dev_null) if rc != 0: @@ -320,7 +319,7 @@ class PartitionedMount(Mount): def __calculate_mountorder(self): - logging.debug("Calculating mount order") + msger.debug("Calculating mount order") for p in self.partitions: self.mountOrder.append(p['mountpoint']) self.unmountOrder.append(p['mountpoint']) @@ -367,7 +366,7 @@ class PartitionedMount(Mount): argv = [ self.btrfscmd, "subvolume", "list", rootpath ] p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: raise MountError("Failed to get subvolume id from %s', return code: %d." % (rootpath, p1.returncode)) subvolid = -1 @@ -386,7 +385,7 @@ class PartitionedMount(Mount): argv = [ self.btrfscmd, "subvolume", "list", pdisk.mountdir ] p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: raise MountError("Failed to get subvolume id from %s', return code: %d." % (pdisk.mountdir, p1.returncode)) subvolid_items = out.split("\n") @@ -438,7 +437,7 @@ class PartitionedMount(Mount): argv = [ self.btrfscmd, "subvolume", "create", pdisk.mountdir + "/" + subvol["subvol"]] p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: raise MountError("Failed to create subvolume '%s', return code: %d." % (subvol["subvol"], p1.returncode)) @@ -456,7 +455,7 @@ class PartitionedMount(Mount): argv = [ self.btrfscmd, "subvolume", "set-default", "%d" % subvolid, pdisk.mountdir] p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: raise MountError("Failed to set default subvolume id: %d', return code: %d." % (subvolid, p1.returncode)) @@ -494,7 +493,7 @@ class PartitionedMount(Mount): continue subvolid = self. __get_subvolume_id(pdisk.mountdir, subvol["subvol"]) if subvolid == -1: - logging.debug("WARNING: invalid subvolume %s" % subvol["subvol"]) + msger.debug("WARNING: invalid subvolume %s" % subvol["subvol"]) continue """ Replace subvolume name with subvolume ID """ opts = subvol["fsopts"].split(",") @@ -550,7 +549,7 @@ class PartitionedMount(Mount): argv = [ self.btrfscmd, "subvolume", "snapshot", subvolpath, snapshotpath ] p1 = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out,err) = p1.communicate() - logging.debug(out) + msger.debug(out) if p1.returncode != 0: raise MountError("Failed to create subvolume snapshot '%s' for '%s', return code: %d." % (snapshotpath, subvolpath, p1.returncode)) self.snapshot_created = True diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index 7302806..451b9b8 100644 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -1,7 +1,6 @@ #!/usr/bin/python import sys import subprocess -import logging from mic.pluginbase.imager_plugin import ImagerPlugin import mic.utils.cmdln as cmdln @@ -38,7 +37,6 @@ class FsPlugin(ImagerPlugin): if key == createopts['pkgmgr']: pkgmgr = pcls if not pkgmgr: - #logging.warn("Can't find backend plugin: %s" % createopts['pkgmgr']) raise CreatorError("Can't find backend plugin: %s" % createopts['pkgmgr']) creator = fs.FsImageCreator(createopts, pkgmgr) diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index e4612c3..5f92283 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -1,8 +1,6 @@ #!/usr/bin/python -import os.path -import sys +import os, sys import subprocess -import logging import shutil import tempfile diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 4d602f1..f6007af 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -1,8 +1,7 @@ -#!/usr/bin/python -import os.path -import sys +#!/usr/bin/python -tt + +import os, sys import subprocess -import logging import shutil import tempfile @@ -56,7 +55,6 @@ class LiveUSBPlugin(ImagerPlugin): creator.print_outimage_info() outimage = creator.outimage except CreatorError, e: - logging.exception(e) raise CreatorError("failed to create image : %s" % e) finally: creator.cleanup() diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index dddcb2b..70dbab5 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -1,8 +1,8 @@ -#!/usr/bin/python +#!/usr/bin/python -tt + import os import sys import subprocess -import logging import shutil import tempfile diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 6a2ee5f..99c6ccd 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -1,8 +1,7 @@ -#!/usr/bin/python -import os.path -import sys +#!/usr/bin/python -tt + +import os, sys import subprocess -import logging import shutil import re import tempfile