shorten most of the unnecessary long lines
authorJF Ding <jian-feng.ding@intel.com>
Mon, 19 Dec 2011 05:00:16 +0000 (13:00 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 19 Dec 2011 05:00:16 +0000 (13:00 +0800)
mic/chroot.py
mic/conf.py
mic/creator.py
mic/imager/baseimager.py
mic/imager/fs.py
mic/imager/livecd.py
mic/imager/liveusb.py
mic/imager/loop.py
mic/imager/raw.py
mic/plugin.py

index 2903d58..958c2ae 100644 (file)
@@ -130,19 +130,28 @@ def setup_chrootenv(chrootdir, bindmounts = None):
             else:
                 srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
                 if os.path.isdir(chrootdir + "/" + srcdst[1]):
-                    msger.warning("%s has existed in %s , skip it." % (srcdst[1], chrootdir))
+                    msger.warning("%s has existed in %s , skip it."\
+                                  % (srcdst[1], chrootdir))
                     continue
 
-            chrootmounts.append(fs_related.BindChrootMount(srcdst[0], chrootdir, srcdst[1]))
+            chrootmounts.append(fs_related.BindChrootMount(srcdst[0],
+                                                           chrootdir,
+                                                           srcdst[1]))
 
         """Default bind mounts"""
         for pt in BIND_MOUNTS:
             chrootmounts.append(fs_related.BindChrootMount(pt, chrootdir, None))
 
-        chrootmounts.append(fs_related.BindChrootMount("/", chrootdir, "/parentroot", "ro"))
+        chrootmounts.append(fs_related.BindChrootMount("/",
+                                                       chrootdir,
+                                                       "/parentroot",
+                                                       "ro"))
 
         for kernel in os.listdir("/lib/modules"):
-            chrootmounts.append(fs_related.BindChrootMount("/lib/modules/" + kernel, chrootdir, None, "ro"))
+            chrootmounts.append(fs_related.BindChrootMount("/lib/modules/"+kernel,
+                                                           chrootdir,
+                                                           None,
+                                                           "ro"))
 
         return chrootmounts
 
@@ -270,10 +279,13 @@ def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"):
 
     os.close(dev_null)
     if not architecture_found:
-        raise errors.CreatorError("Failed to get architecture from any of the following files %s from chroot." % files_to_check)
+        raise errors.CreatorError("Failed to get architecture from any of the "
+                                  "following files %s from chroot." \
+                                  % files_to_check)
 
     try:
-        msger.info("Launching shell. Exit to continue.\n----------------------------------")
+        msger.info("Launching shell. Exit to continue.\n"
+                   "----------------------------------")
         globalmounts = setup_chrootenv(chrootdir, bindmounts)
         subprocess.call(execute, preexec_fn = mychroot, shell=True)
 
index 08ff492..378765d 100644 (file)
@@ -114,10 +114,10 @@ class ConfigMgr(object):
                 getattr(self, section).update(dict(parser.items(section)))
 
     def _selinux_check(self, arch, ks):
-        """
-        If a user needs to use btrfs or creates ARM image,
+        """If a user needs to use btrfs or creates ARM image,
         selinux must be disabled at start.
         """
+
         for path in ["/usr/sbin/getenforce",
                      "/usr/bin/getenforce",
                      "/sbin/getenforce",
@@ -129,7 +129,7 @@ class ConfigMgr(object):
                 selinux_status = runner.outs([path])
                 if arch and arch.startswith("arm") \
                         and selinux_status == "Enforcing":
-                    raise errors.ConfigError("Can't create arm image if "\
+                    raise errors.ConfigError("Can't create arm image if "
                           "selinux is enabled, please disable it and try again")
 
                 use_btrfs = False
@@ -139,9 +139,9 @@ class ConfigMgr(object):
                         break
 
                 if use_btrfs and selinux_status == "Enforcing":
-                    raise errors.ConfigError("Can't create image using btrfs "\
-                                          "filesystem if selinux is enabled, "\
-                                          "please disable it and try again")
+                    raise errors.ConfigError("Can't create image using btrfs "
+                                           "filesystem if selinux is enabled, "
+                                           "please disable it and try again.")
                 break
 
     def _parse_kickstart(self, ksconf=None):
@@ -161,22 +161,23 @@ class ConfigMgr(object):
 
         msger.info("Retrieving repo metadata:")
         ksrepos = misc.get_repostrs_from_ks(ks)
-        self.create['repomd'] = misc.get_metadata_from_repos(ksrepos,
-                                                        self.create['cachedir'])
+        self.create['repomd'] = misc.get_metadata_from_repos(
+                                                    ksrepos,
+                                                    self.create['cachedir'])
         msger.raw(" DONE")
 
         target_archlist, archlist = misc.get_arch(self.create['repomd'])
         if self.create['arch']:
             if self.create['arch'] not in archlist:
-                raise errors.ConfigError("Invalid arch %s for repository. "\
-                          "Valid arches: %s" % (self.create['arch'],
-                                                ', '.join(archlist)))
+                raise errors.ConfigError("Invalid arch %s for repository. "
+                                  "Valid arches: %s" \
+                                  % (self.create['arch'], ', '.join(archlist)))
         else:
             if len(target_archlist) == 1:
                 self.create['arch'] = str(target_archlist[0])
                 msger.info("\nUse detected arch %s." % target_archlist[0])
             else:
-                raise errors.ConfigError("Please specify a valid arch, "\
+                raise errors.ConfigError("Please specify a valid arch, "
                                          "your choise can be: %s" \
                                          % ', '.join(archlist))
 
index 14da049..4f90a26 100644 (file)
@@ -50,19 +50,48 @@ class Creator(cmdln.Cmdln):
 
     def get_optparser(self):
         optparser = cmdln.CmdlnOptionParser(self)
-        optparser.add_option('-d', '--debug', action='store_true', dest='debug', help=SUPPRESS_HELP)
-        optparser.add_option('-v', '--verbose', action='store_true', dest='verbose', help=SUPPRESS_HELP)
-        optparser.add_option('', '--logfile', type='string', dest='logfile', default=None, help='Path of logfile')
-        optparser.add_option('-c', '--config', type='string', dest='config', default=None, help='Specify config file for mic')
-        optparser.add_option('-k', '--cachedir', type='string', action='store', dest='cachedir', default=None, help='Cache directory to store the downloaded')
-        optparser.add_option('-o', '--outdir', type='string', action='store', dest='outdir', default=None, help='Output directory')
-        optparser.add_option('-A', '--arch', type='string', dest='arch', default=None, help='Specify repo architecture')
-        optparser.add_option('', '--release', type='string', dest='release', default=None, metavar='RID', help='Generate a release of RID with all necessary files, when @BUILD_ID@ is contained in kickstart file, it will be replaced by RID')
-        optparser.add_option("", "--record-pkgs", type="string", dest="record_pkgs", default=None,
-                             help='Record the info of installed packages, multiple values can be specified which joined by ",", valid values: "name", "content", "license"')
-        optparser.add_option('', '--pkgmgr', type='string', dest='pkgmgr', default=None, help='Specify backend package manager')
-        optparser.add_option('', '--local-pkgs-path', type='string', dest='local_pkgs_path', default=None, help='Path for local pkgs(rpms) to be installed')
-        optparser.add_option('', '--compress-disk-image', type='string', dest='compress_disk_image', default=None, help='Sets the disk image compression. NOTE: The available values might depend on the used filesystem type.')
+        optparser.add_option('-d', '--debug', action='store_true', dest='debug',
+                             help=SUPPRESS_HELP)
+        optparser.add_option('-v', '--verbose', action='store_true',
+                             dest='verbose',
+                             help=SUPPRESS_HELP)
+        optparser.add_option('', '--logfile', type='string', dest='logfile',
+                             default=None,
+                             help='Path of logfile')
+        optparser.add_option('-c', '--config', type='string', dest='config',
+                             default=None,
+                             help='Specify config file for mic')
+        optparser.add_option('-k', '--cachedir', type='string', action='store',
+                             dest='cachedir', default=None,
+                             help='Cache directory to store the downloaded')
+        optparser.add_option('-o', '--outdir', type='string', action='store',
+                             dest='outdir', default=None,
+                             help='Output directory')
+        optparser.add_option('-A', '--arch', type='string', dest='arch',
+                             default=None,
+                             help='Specify repo architecture')
+        optparser.add_option('', '--release', type='string', dest='release',
+                             default=None, metavar='RID',
+                             help='Generate a release of RID with all necessary'
+                                  ' files, when @BUILD_ID@ is contained in '
+                                  'kickstart file, it will be replaced by RID')
+        optparser.add_option("", "--record-pkgs", type="string",
+                             dest="record_pkgs", default=None,
+                             help='Record the info of installed packages, '
+                                  'multiple values can be specified which '
+                                  'joined by ",", valid values: "name", '
+                                  '"content", "license"')
+        optparser.add_option('', '--pkgmgr', type='string', dest='pkgmgr',
+                             default=None,
+                             help='Specify backend package manager')
+        optparser.add_option('', '--local-pkgs-path', type='string',
+                             dest='local_pkgs_path', default=None,
+                             help='Path for local pkgs(rpms) to be installed')
+        optparser.add_option('', '--compress-disk-image', type='string',
+                             dest='compress_disk_image', default=None,
+                             help='Sets the disk image compression. NOTE: The '
+                                  'available values might depend on the used '
+                                  'filesystem type.')
         return optparser
 
     def preoptparse(self, argv):
@@ -133,7 +162,9 @@ class Creator(cmdln.Cmdln):
             configmgr.create['record_pkgs'] = []
             for infotype in self.options.record_pkgs.split(','):
                 if infotype not in ('name', 'content', 'license'):
-                    raise errors.Usage('Invalid pkg recording: %s, valid ones: "name", "content", "license"' % infotype)
+                    raise errors.Usage('Invalid pkg recording: %s, valid ones:'
+                                       ' "name", "content", "license"' \
+                                       % infotype)
 
                 configmgr.create['record_pkgs'].append(infotype)
 
@@ -144,13 +175,15 @@ class Creator(cmdln.Cmdln):
             else:
                 raise errors.Usage('Invalid architecture: "%s".\n'
                                    '  Supported architectures are: \n'
-                                   '  %s\n' % (self.options.arch, ', '.join(supported_arch)))
+                                   '  %s\n' % (self.options.arch,
+                                               ', '.join(supported_arch)))
 
         if self.options.pkgmgr is not None:
             configmgr.create['pkgmgr'] = self.options.pkgmgr
 
         if self.options.compress_disk_image is not None:
-            configmgr.create['compress_disk_image'] = self.options.compress_disk_image
+            configmgr.create['compress_disk_image'] = \
+                                                self.options.compress_disk_image
 
     def main(self, argv=None):
         if argv is None:
index 192e8f5..ff9e873 100644 (file)
@@ -84,7 +84,8 @@ class BaseImageCreator(object):
 
                 # check whether destine dir exist
                 if os.path.exists(self.destdir):
-                    if msger.ask('Image dir: %s already exists, cleanup and continue?' % self.destdir):
+                    if msger.ask('Image dir: %s already exists, '
+                                 'cleanup and continue?' % self.destdir):
                         shutil.rmtree(self.destdir, ignore_errors = True)
                     else:
                         raise Abort('Canceled')
@@ -145,7 +146,8 @@ class BaseImageCreator(object):
                 if dep == "extlinux":
                     self._dep_checks.remove(dep)
 
-            if not os.path.exists("/usr/bin/qemu-arm") or not misc.is_statically_linked("/usr/bin/qemu-arm"):
+            if not os.path.exists("/usr/bin/qemu-arm") or \
+               not misc.is_statically_linked("/usr/bin/qemu-arm"):
                 self._dep_checks.append("qemu-arm-static")
 
             if os.path.exists("/proc/sys/vm/vdso_enabled"):
@@ -153,9 +155,11 @@ class BaseImageCreator(object):
                 vdso_value = vdso_fh.read().strip()
                 vdso_fh.close()
                 if (int)(vdso_value) == 1:
-                    msger.warning("vdso is enabled on your host, which might cause problems with arm emulations.\n"
-                                  "\tYou can disable vdso with following command before starting image build:\n"
-                                  "\techo 0 | sudo tee /proc/sys/vm/vdso_enabled")
+                    msger.warning("vdso is enabled on your host, which might "
+                        "cause problems with arm emulations.\n"
+                        "\tYou can disable vdso with following command before "
+                        "starting image build:\n"
+                        "\techo 0 | sudo tee /proc/sys/vm/vdso_enabled")
 
         # make sure the specified tmpdir and cachedir exist
         if not os.path.exists(self.tmpdir):
@@ -163,8 +167,12 @@ class BaseImageCreator(object):
         if not os.path.exists(self.cachedir):
             os.makedirs(self.cachedir)
 
-        if self._img_compression_method != None and self._img_compression_method not in self._valid_compression_methods:
-            raise CreatorError("Given disk image compression method ('%s') is not valid. Valid values are '%s'." % (self._img_compression_method, ' '.join(self._valid_compression_methods)))
+        if self._img_compression_method != None and \
+           self._img_compression_method not in self._valid_compression_methods:
+            raise CreatorError("Given disk image compression method ('%s') is "
+                               "not valid. Valid values are '%s'." \
+                               % (self._img_compression_method,
+                                  ' '.join(self._valid_compression_methods)))
 
     def __del__(self):
         self.cleanup()
@@ -311,11 +319,14 @@ class BaseImageCreator(object):
             f = open(licensefile, "w")
 
             f.write('Summary:\n')
-            for license in reversed(sorted(self._pkgs_license, key=lambda license: len(self._pkgs_license[license]))):
-                f.write("    - %s: %s\n" % (license, len(self._pkgs_license[license])))
+            for license in reversed(sorted(self._pkgs_license, key=\
+                            lambda license: len(self._pkgs_license[license]))):
+                f.write("    - %s: %s\n" \
+                        % (license, len(self._pkgs_license[license])))
 
             f.write('\nDetails:\n')
-            for license in reversed(sorted(self._pkgs_license, key=lambda license: len(self._pkgs_license[license]))):
+            for license in reversed(sorted(self._pkgs_license, key=\
+                            lambda license: len(self._pkgs_license[license]))):
                 f.write("    - %s:\n" % (license))
                 for pkg in sorted(self._pkgs_license[license]):
                     f.write("        - %s\n" % (pkg))
@@ -382,7 +393,9 @@ class BaseImageCreator(object):
         A sensible default implementation is provided.
 
         """
-        s =  "/dev/root  /         %s    %s 0 0\n" % (self._fstype, "defaults,noatime" if not self._fsopts else self._fsopts)
+        s =  "/dev/root  /         %s    %s 0 0\n" \
+             % (self._fstype,
+                "defaults,noatime" if not self._fsopts else self._fsopts)
         s += self._get_fstab_special()
         return s
 
@@ -622,6 +635,7 @@ class BaseImageCreator(object):
                    ('ptmx',   5, 2, 0666),
                    ('tty',    5, 0, 0666),
                    ('zero',   1, 5, 0666))
+
         links = (("/proc/self/fd", "/dev/fd"),
                  ("/proc/self/fd/0", "/dev/stdin"),
                  ("/proc/self/fd/1", "/dev/stdout"),
@@ -629,10 +643,14 @@ class BaseImageCreator(object):
 
         for (node, major, minor, perm) in devices:
             if not os.path.exists(self._instroot + "/dev/" + node):
-                os.mknod(self._instroot + "/dev/" + node, perm | stat.S_IFCHR, os.makedev(major,minor))
+                os.mknod(self._instroot + "/dev/" + node,
+                         perm | stat.S_IFCHR,
+                         os.makedev(major,minor))
+
         for (src, dest) in links:
             if not os.path.exists(self._instroot + dest):
                 os.symlink(src, self._instroot + dest)
+
         os.umask(origumask)
 
     def mount(self, base_on = None, cachedir = None):
@@ -660,11 +678,19 @@ class BaseImageCreator(object):
 
         self._mount_instroot(base_on)
 
-        for d in ("/dev/pts", "/etc", "/boot", "/var/log", "/var/cache/yum", "/sys", "/proc", "/usr/bin"):
+        for d in ("/dev/pts",
+                  "/etc",
+                  "/boot",
+                  "/var/log",
+                  "/var/cache/yum",
+                  "/sys",
+                  "/proc",
+                  "/usr/bin"):
             fs.makedirs(self._instroot + d)
 
         if self.target_arch and self.target_arch.startswith("arm"):
-            self.qemu_emulator = misc.setup_qemu_emulator(self._instroot, self.target_arch)
+            self.qemu_emulator = misc.setup_qemu_emulator(self._instroot,
+                                                          self.target_arch)
 
         self.get_cachedir(cachedir)
 
@@ -912,7 +938,10 @@ class BaseImageCreator(object):
             try:
                 try:
                     subprocess.call([s.interp, script],
-                                    preexec_fn = preexec, env = env, stdout = sys.stdout, stderr = sys.stderr)
+                                    preexec_fn = preexec,
+                                    env = env,
+                                    stdout = sys.stdout,
+                                    stderr = sys.stderr)
                 except OSError, (err, msg):
                     raise CreatorError("Failed to execute %%post script "
                                        "with '%s' : %s" % (s.interp, msg))
@@ -1016,22 +1045,32 @@ class BaseImageCreator(object):
             img_location = os.path.join(self._outdir,self._img_name)
             if self._img_compression_method == "bz2":
                 bzip2 = fs.find_binary_path('bzip2')
-                msger.info("Compressing %s with bzip2. Please wait..." % img_location)
+                msger.info("Compressing %s with bzip2. Please wait..." \
+                           % img_location)
                 rc = runner.show([bzip2, "-f", img_location])
                 if rc:
-                    raise CreatorError("Failed to compress image %s with %s." % (img_location, self._img_compression_method))
-                for bootimg in glob.glob(os.path.dirname(img_location) + "/*-boot.bin"):
-                    msger.info("Compressing %s with bzip2. Please wait..." % bootimg)
+                    raise CreatorError("Failed to compress image %s with %s." \
+                                % (img_location, self._img_compression_method))
+
+                for bootimg in glob.glob(os.path.dirname(img_location) + \
+                                         "/*-boot.bin"):
+                    msger.info("Compressing %s with bzip2. Please wait..." \
+                               % bootimg)
                     rc = runner.show([bzip2, "-f", bootimg])
                     if rc:
-                        raise CreatorError("Failed to compress image %s with %s." % (bootimg, self._img_compression_method))
+                        raise CreatorError("Failed to compress image %s with "
+                                           "%s." \
+                                           % (bootimg,
+                                              self._img_compression_method))
 
         if self._recording_pkgs:
             self._save_recording_pkgs(destdir)
 
-        """ For image formats with two or multiple image files, it will be better to put them under a directory """
+        # For image formats with two or multiple image files, it will be
+        # better to put them under a directory
         if self.image_format in ("raw", "vmdk", "vdi", "nand", "mrstnand"):
-            destdir = os.path.join(destdir, "%s-%s" % (self.name, self.image_format))
+            destdir = os.path.join(destdir, "%s-%s" \
+                                            % (self.name, self.image_format))
             msger.debug("creating destination dir: %s" % destdir)
             fs.makedirs(destdir)
 
@@ -1075,7 +1114,10 @@ class BaseImageCreator(object):
 
             for file in self.outimage:
                 msger.info("adding %s to %s" % (file, dst))
-                tar.add(file, arcname=os.path.join("%s-%s" % (self.name, image_format), os.path.basename(file)))
+                tar.add(file,
+                        arcname=os.path.join("%s-%s" \
+                                           % (self.name, image_format),
+                                              os.path.basename(file)))
                 if os.path.isdir(file):
                     shutil.rmtree(file, ignore_errors = True)
                 else:
@@ -1126,7 +1168,8 @@ class BaseImageCreator(object):
 
                     rc, md5sum = runner.runtool(["/usr/bin/md5sum", "-b", _rpath(f)])
                     if rc != 0:
-                        msger.warning("Failed to generate md5sum for file %s" % _rpath(f))
+                        msger.warning("Failed to generate md5sum for file %s" \
+                                      % _rpath(f))
                     else:
                         md5sum = md5sum.lstrip().split()[0]
                         wf.write(md5sum+" "+ f +"\n")
index 456267a..fdc9956 100644 (file)
@@ -33,7 +33,11 @@ class FsImageCreator(BaseImageCreator):
 
     def package(self, destdir = "."):
 
-        ignores = ["/dev/fd", "/dev/stdin", "/dev/stdout", "/dev/stderr", "/etc/mtab"]
+        ignores = ["/dev/fd",
+                   "/dev/stdin",
+                   "/dev/stdout",
+                   "/dev/stderr",
+                   "/etc/mtab"]
 
         if not os.path.exists(destdir):
             os.makedirs(destdir)
@@ -55,10 +59,16 @@ class FsImageCreator(BaseImageCreator):
 
         elif self._img_compression_method == "tar.bz2":
             dst = "%s/%s.tar.bz2" % (destdir, self.name)
-            msger.info("Creating %s (compressing %s with %s). Please wait..." % (dst, self._instroot, self._img_compression_method))
+            msger.info("Creating %s (compressing %s with %s). Please wait..." \
+                       % (dst, self._instroot, self._img_compression_method))
 
             tar = find_binary_path('tar')
-            tar_cmdline = [tar, "--numeric-owner", "--preserve-permissions", "--preserve-order", "--one-file-system", "--directory", self._instroot]
+            tar_cmdline = [tar, "--numeric-owner",
+                                "--preserve-permissions",
+                                "--preserve-order",
+                                "--one-file-system",
+                                "--directory",
+                                self._instroot]
             for ignore_entry in ignores:
                 if ignore_entry.startswith('/'):
                     ignore_entry = ignore_entry[1:]
@@ -69,9 +79,11 @@ class FsImageCreator(BaseImageCreator):
 
             rc = call(tar_cmdline)
             if rc:
-                raise CreatorError("Failed compress image with tar.bz2. Cmdline: %s" % (" ".join(tar_cmdline)))
+                raise CreatorError("Failed compress image with tar.bz2. "
+                                   "Cmdline: %s" % (" ".join(tar_cmdline)))
 
             self.outimage.append(dst)
 
         else:
-            raise CreatorError("Compression method '%s' not supported for 'fs' image format." % (self._img_compression_method))
+            raise CreatorError("Compression method '%s' not supported for 'fs' "
+                               "image format." % (self._img_compression_method))
index a95e0e8..1341781 100644 (file)
@@ -70,11 +70,22 @@ class LiveImageCreatorBase(LoopImageCreator):
 
         self.__isodir = None
 
-        self.__modules = ["=ata", "sym53c8xx", "aic7xxx", "=usb", "=firewire", "=mmc", "=pcmcia", "mptsas"]
+        self.__modules = ["=ata",
+                          "sym53c8xx",
+                          "aic7xxx",
+                          "=usb",
+                          "=firewire",
+                          "=mmc",
+                          "=pcmcia",
+                          "mptsas"]
         if self.ks:
             self.__modules.extend(kickstart.get_modules(self.ks))
 
-        self._dep_checks.extend(["isohybrid", "unsquashfs", "mksquashfs", "dd", "genisoimage"])
+        self._dep_checks.extend(["isohybrid",
+                                 "unsquashfs",
+                                 "mksquashfs",
+                                 "dd",
+                                 "genisoimage"])
 
     #
     # Hooks for subclasses
@@ -85,7 +96,8 @@ class LiveImageCreatorBase(LoopImageCreator):
             This is the hook where subclasses must create the booloader
             configuration in order to allow a bootable ISO to be built.
 
-            isodir -- the directory where the contents of the ISO are to be staged
+            isodir -- the directory where the contents of the ISO are to
+                      be staged
         """
         raise CreatorError("Bootloader configuration is arch-specific, "
                            "but not implemented for this arch!")
@@ -100,8 +112,9 @@ class LiveImageCreatorBase(LoopImageCreator):
     def _get_kernel_options(self):
         """Return a kernel options string for bootloader configuration.
 
-            This is the hook where subclasses may specify a set of kernel options
-            which should be included in the images bootloader configuration.
+            This is the hook where subclasses may specify a set of kernel
+            options which should be included in the images bootloader
+            configuration.
 
             A sensible default implementation is provided.
         """
@@ -121,8 +134,8 @@ class LiveImageCreatorBase(LoopImageCreator):
     def _get_mkisofs_options(self, isodir):
         """Return the architecture specific mkisosfs options.
 
-            This is the hook where subclasses may specify additional arguments to
-            mkisofs, e.g. to enable a bootable ISO to be built.
+            This is the hook where subclasses may specify additional arguments
+            to mkisofs, e.g. to enable a bootable ISO to be built.
 
             By default, an empty list is returned.
         """
@@ -133,11 +146,11 @@ class LiveImageCreatorBase(LoopImageCreator):
     #
     def _has_checkisomd5(self):
         """Check whether checkisomd5 is available in the install root."""
-        def exists(instroot, path):
-            return os.path.exists(instroot + path)
+        def _exists(path):
+            return os.path.exists(self._instroot + path)
 
-        if (exists(self._instroot, "/usr/lib/moblin-installer-runtime/checkisomd5") or
-            exists(self._instroot, "/usr/bin/checkisomd5")):
+        if (_exists("/usr/lib/moblin-installer-runtime/checkisomd5") or \
+            _exists("/usr/bin/checkisomd5")):
             if (os.path.exists("/usr/bin/implantisomd5") or
                os.path.exists("/usr/lib/anaconda-runtime/implantisomd5")):
                 return True
@@ -255,13 +268,17 @@ class LiveImageCreatorBase(LoopImageCreator):
             minimal_size = self._resparse()
 
             if not self.skip_minimize:
-                fs_related.create_image_minimizer(self.__isodir + "/LiveOS/osmin.img",
-                                       self._image, minimal_size)
+                fs_related.create_image_minimizer(self.__isodir + \
+                                                      "/LiveOS/osmin.img",
+                                                  self._image,
+                                                  minimal_size)
 
             if self.skip_compression:
                 shutil.move(self._image, self.__isodir + "/LiveOS/ext3fs.img")
             else:
-                fs_related.makedirs(os.path.join(os.path.dirname(self._image), "LiveOS"))
+                fs_related.makedirs(os.path.join(
+                                        os.path.dirname(self._image),
+                                        "LiveOS"))
                 shutil.move(self._image,
                             os.path.join(os.path.dirname(self._image),
                                          "LiveOS", "ext3fs.img"))
@@ -282,7 +299,8 @@ class x86LiveImageCreator(LiveImageCreatorBase):
                  "-boot-load-size", "4" ]
 
     def _get_required_packages(self):
-        return ["syslinux", "syslinux-extlinux"] + LiveImageCreatorBase._get_required_packages(self)
+        return ["syslinux", "syslinux-extlinux"] + \
+               LiveImageCreatorBase._get_required_packages(self)
 
     def _get_isolinux_stanzas(self, isodir):
         return ""
@@ -335,7 +353,7 @@ class x86LiveImageCreator(LiveImageCreatorBase):
         if self._alt_initrd_name:
             src_initrd_path = os.path.join(bootdir, self._alt_initrd_name)
         else:
-            src_initrd_path = os.path.join(bootdir, "initrd-" + version + ".img")
+            src_initrd_path = os.path.join(bootdir, "initrd-" +version+ ".img")
 
         try:
             shutil.copyfile(bootdir + "/vmlinuz-" + version,
@@ -343,7 +361,8 @@ class x86LiveImageCreator(LiveImageCreatorBase):
             shutil.copyfile(src_initrd_path,
                             isodir + "/isolinux/initrd" + index + ".img")
         except:
-            raise CreatorError("Unable to copy valid kernels or initrds, please check the repo")
+            raise CreatorError("Unable to copy valid kernels or initrds, "
+                               "please check the repo.")
 
         is_xen = False
         if os.path.exists(bootdir + "/xen.gz-" + version[:-3]):
@@ -407,26 +426,47 @@ menu color cmdline 0 #ffffffff #00000000
                 versions.append(version)
 
         if not versions:
-            raise CreatorError("Unable to find valid kernels, please check the repo")
+            raise CreatorError("Unable to find valid kernels, "
+                               "please check the repo")
 
         kernel_options = self._get_kernel_options()
 
-        """ menu can be customized highly, the format is
+        """ menu can be customized highly, the format is:
 
-              short_name1:long_name1:extra_options1;short_name2:long_name2:extra_options2
+          short_name1:long_name1:extra_opts1;short_name2:long_name2:extra_opts2
 
-            for example: autoinst:Installation only:systemd.unit=installer-graphical.service
-            but in order to keep compatible with old format, these are still ok:
+        e.g.: autoinst:InstallationOnly:systemd.unit=installer-graphical.service
+        but in order to keep compatible with old format, these are still ok:
 
               liveinst autoinst
               liveinst;autoinst
               liveinst::;autoinst::
         """
-        oldmenus = {"basic":{"short":"basic", "long":"Installation Only (Text based)", "extra":"basic nosplash 4"},
-                    "liveinst":{"short":"liveinst", "long":"Installation Only", "extra":"liveinst nosplash 4"},
-                    "autoinst":{"short":"autoinst", "long":"Autoinstall (Deletes all existing content)", "extra":"autoinst nosplash 4"},
-                    "netinst":{"short":"netinst", "long":"Network Installation", "extra":"netinst 4"},
-                    "verify":{"short":"check", "long":"Verify and", "extra":"check"}
+        oldmenus = {"basic": {
+                        "short": "basic",
+                        "long": "Installation Only (Text based)",
+                        "extra": "basic nosplash 4"
+                    },
+                    "liveinst": {
+                        "short": "liveinst",
+                        "long": "Installation Only",
+                        "extra": "liveinst nosplash 4"
+                    },
+                    "autoinst": {
+                        "short": "autoinst",
+                        "long": "Autoinstall (Deletes all existing content)",
+                        "extra": "autoinst nosplash 4"
+                    },
+                    "netinst": {
+                        "short": "netinst",
+                        "long": "Network Installation",
+                        "extra": "netinst 4"
+                    },
+                    "verify": {
+                        "short": "check",
+                        "long": "Verify and",
+                        "extra": "check"
+                    }
                    }
         menu_options = self._get_menu_options()
         menus = menu_options.split(";")
@@ -455,7 +495,8 @@ menu color cmdline 0 #ffffffff #00000000
                 long = "Boot %s(%s)" % (self.name, kernel[7:])
             else:
                 long = "Boot %s(%s)" % (self.name, kernel)
-            oldmenus["verify"]["long"] = "%s %s" % (oldmenus["verify"]["long"], long)
+            oldmenus["verify"]["long"] = "%s %s" % (oldmenus["verify"]["long"],
+                                                    long)
 
             cfg += self.__get_image_stanza(is_xen,
                                            fslabel = self.fslabel,
@@ -607,11 +648,12 @@ hiddenmenu
                                                long = name,
                                                extra = "", index = index)
             if checkisomd5:
-                cfg += self.__get_efi_image_stanza(fslabel = self.fslabel,
-                                                   liveargs = kernel_options,
-                                                   long = "Verify and Boot " + name,
-                                                   extra = "check",
-                                                   index = index)
+                cfg += self.__get_efi_image_stanza(
+                                               fslabel = self.fslabel,
+                                               liveargs = kernel_options,
+                                               long = "Verify and Boot " + name,
+                                               extra = "check",
+                                               index = index)
             break
 
         return cfg
@@ -639,14 +681,18 @@ hiddenmenu
 
         # first gen mactel machines get the bootloader name wrong apparently
         if rpmmisc.getBaseArch() == "i386":
-            os.link(isodir + "/EFI/boot/grub.efi", isodir + "/EFI/boot/boot.efi")
-            os.link(isodir + "/EFI/boot/grub.conf", isodir + "/EFI/boot/boot.conf")
+            os.link(isodir + "/EFI/boot/grub.efi",
+                    isodir + "/EFI/boot/boot.efi")
+            os.link(isodir + "/EFI/boot/grub.conf",
+                    isodir + "/EFI/boot/boot.conf")
 
         # for most things, we want them named boot$efiarch
         efiarch = {"i386": "ia32", "x86_64": "x64"}
         efiname = efiarch[rpmmisc.getBaseArch()]
-        os.rename(isodir + "/EFI/boot/grub.efi", isodir + "/EFI/boot/boot%s.efi" %(efiname,))
-        os.link(isodir + "/EFI/boot/grub.conf", isodir + "/EFI/boot/boot%s.conf" %(efiname,))
+        os.rename(isodir + "/EFI/boot/grub.efi",
+                  isodir + "/EFI/boot/boot%s.efi" %(efiname,))
+        os.link(isodir + "/EFI/boot/grub.conf",
+                isodir + "/EFI/boot/boot%s.conf" %(efiname,))
 
 
     def _configure_bootloader(self, isodir):
index 7498a97..e378d48 100644 (file)
@@ -45,21 +45,38 @@ class LiveUSBImageCreator(LiveCDImageCreator):
         plussize=128
         kernelargs=None
 
-        if overlaysizemb > 2047 and fstype == "vfat":
-            raise CreatorError("Can't have an overlay of 2048MB or greater on VFAT")
-        if homesizemb > 2047 and fstype == "vfat":
-            raise CreatorError("Can't have an home overlay of 2048MB or greater on VFAT")
-        if swapsizemb > 2047 and fstype == "vfat":
-            raise CreatorError("Can't have an swap overlay of 2048MB or greater on VFAT")
+        if fstype == 'vfat':
+            if overlaysizemb > 2047:
+                raise CreatorError("Can't have an overlay of 2048MB or "
+                                   "greater on VFAT")
+
+            if homesizemb > 2047:
+                raise CreatorError("Can't have an home overlay of 2048MB or "
+                                   "greater on VFAT")
+
+            if swapsizemb > 2047:
+                raise CreatorError("Can't have an swap overlay of 2048MB or "
+                                   "greater on VFAT")
 
         livesize = misc.get_file_size(isodir + "/LiveOS")
 
-        usbimgsize = (overlaysizemb + homesizemb + swapsizemb + livesize + plussize) * 1024L * 1024L
-        disk = fs_related.SparseLoopbackDisk("%s/%s.usbimg" % (self._outdir, self.name), usbimgsize)
+        usbimgsize = (overlaysizemb + \
+                      homesizemb + \
+                      swapsizemb + \
+                      livesize + \
+                      plussize) * 1024L * 1024L
+
+        disk = fs_related.SparseLoopbackDisk("%s/%s.usbimg" \
+                                                 % (self._outdir, self.name),
+                                             usbimgsize)
         usbmnt = self._mkdtemp("usb-mnt")
         usbloop = PartitionedMount({'/dev/sdb':disk}, usbmnt)
 
-        usbloop.add_partition(usbimgsize/1024/1024, "/dev/sdb", "/", fstype, boot=True)
+        usbloop.add_partition(usbimgsize/1024/1024,
+                              "/dev/sdb",
+                              "/",
+                              fstype,
+                              boot=True)
 
         usbloop.mount()
 
@@ -67,12 +84,15 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             fs_related.makedirs(usbmnt + "/LiveOS")
 
             if os.path.exists(isodir + "/LiveOS/squashfs.img"):
-                shutil.copyfile(isodir + "/LiveOS/squashfs.img", usbmnt + "/LiveOS/squashfs.img")
+                shutil.copyfile(isodir + "/LiveOS/squashfs.img",
+                                usbmnt + "/LiveOS/squashfs.img")
             else:
-                fs_related.mksquashfs(os.path.dirname(self._image), usbmnt + "/LiveOS/squashfs.img")
+                fs_related.mksquashfs(os.path.dirname(self._image),
+                                      usbmnt + "/LiveOS/squashfs.img")
 
             if os.path.exists(isodir + "/LiveOS/osmin.img"):
-                shutil.copyfile(isodir + "/LiveOS/osmin.img", usbmnt + "/LiveOS/osmin.img")
+                shutil.copyfile(isodir + "/LiveOS/osmin.img",
+                                usbmnt + "/LiveOS/osmin.img")
 
             if fstype == "vfat" or fstype == "msdos":
                 uuid = usbloop.partitions[0]['mount'].uuid
@@ -87,7 +107,8 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             args = ['cp', "-Rf", isodir + "/isolinux", usbmnt + "/syslinux"]
             rc = runner.show(args)
             if rc:
-                raise CreatorError("Can't copy isolinux directory %s" % (isodir + "/isolinux/*"))
+                raise CreatorError("Can't copy isolinux directory %s" \
+                                   % (isodir + "/isolinux/*"))
 
             if os.path.isfile("/usr/share/syslinux/isolinux.bin"):
                 syslinux_path = "/usr/share/syslinux"
@@ -103,10 +124,10 @@ class LiveUSBImageCreator(LiveCDImageCreator):
                     args = ['cp', path, usbmnt + "/syslinux/"]
                     rc = runner.show(args)
                     if rc:
-                        raise CreatorError("Can't copy syslinux file %s" % (path))
+                        raise CreatorError("Can't copy syslinux file " + path)
                 else:
-                    raise CreatorError("syslinux not installed : "
-                               "syslinux file %s not found" % path)
+                    raise CreatorError("syslinux not installed: "
+                                       "syslinux file %s not found" % path)
 
             fd = open(isodir + "/isolinux/isolinux.cfg", "r")
             text = fd.read()
@@ -122,9 +143,18 @@ class LiveUSBImageCreator(LiveCDImageCreator):
                 msger.info("Initializing persistent overlay file")
                 overfile = "overlay" + overlaysuffix
                 if fstype == "vfat":
-                    args = ['dd', "if=/dev/zero", "of=" + usbmnt + "/LiveOS/" + overfile, "count=%d" % overlaysizemb, "bs=1M"]
+                    args = ['dd',
+                            "if=/dev/zero",
+                            "of=" + usbmnt + "/LiveOS/" + overfile,
+                            "count=%d" % overlaysizemb,
+                            "bs=1M"]
                 else:
-                    args = ['dd', "if=/dev/null", "of=" + usbmnt + "/LiveOS/" + overfile, "count=1", "bs=1M", "seek=%d" % overlaysizemb]
+                    args = ['dd',
+                            "if=/dev/null",
+                            "of=" + usbmnt + "/LiveOS/" + overfile,
+                            "count=1",
+                            "bs=1M",
+                            "seek=%d" % overlaysizemb]
                 rc = runner.show(args)
                 if rc:
                     raise CreatorError("Can't create overlay file")
@@ -134,7 +164,11 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             if swapsizemb > 0:
                 msger.info("Initializing swap file")
                 swapfile = usbmnt + "/LiveOS/" + "swap.img"
-                args = ['dd', "if=/dev/zero", "of=" + swapfile, "count=%d" % swapsizemb, "bs=1M"]
+                args = ['dd',
+                        "if=/dev/zero",
+                        "of=" + swapfile,
+                        "count=%d" % swapsizemb,
+                        "bs=1M"]
                 rc = runner.show(args)
                 if rc:
                     raise CreatorError("Can't create swap file")
@@ -147,9 +181,18 @@ class LiveUSBImageCreator(LiveCDImageCreator):
                 msger.info("Initializing persistent /home")
                 homefile = usbmnt + "/LiveOS/" + homefile
                 if fstype == "vfat":
-                    args = ['dd', "if=/dev/zero", "of=" + homefile, "count=%d" % homesizemb, "bs=1M"]
+                    args = ['dd',
+                            "if=/dev/zero",
+                            "of=" + homefile,
+                            "count=%d" % homesizemb,
+                            "bs=1M"]
                 else:
-                    args = ['dd', "if=/dev/null", "of=" + homefile, "count=1", "bs=1M", "seek=%d" % homesizemb]
+                    args = ['dd',
+                            "if=/dev/null",
+                            "of=" + homefile,
+                            "count=1",
+                            "bs=1M",
+                            "seek=%d" % homesizemb]
                 rc = runner.show(args)
                 if rc:
                     raise CreatorError("Can't create home file")
@@ -164,7 +207,11 @@ class LiveUSBImageCreator(LiveCDImageCreator):
                     raise CreatorError("Can't mke2fs home file")
                 if fstype == "ext2" or fstype == "ext3":
                     tune2fs = fs_related.find_binary_path("tune2fs")
-                    args = [tune2fs, "-c0", "-i0", "-ouser_xattr,acl", homefile]
+                    args = [tune2fs,
+                            "-c0",
+                            "-i0",
+                            "-ouser_xattr,acl",
+                            homefile]
                     rc = runner.show(args)
                     if rc:
                          raise CreatorError("Can't tune2fs home file")
@@ -172,11 +219,18 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             if fstype == "vfat" or fstype == "msdos":
                 syslinuxcmd = fs_related.find_binary_path("syslinux")
                 syslinuxcfg = usbmnt + "/syslinux/syslinux.cfg"
-                args = [syslinuxcmd, "-d", "syslinux", usbloop.partitions[0]["device"]]
+                args = [syslinuxcmd,
+                        "-d",
+                        "syslinux",
+                        usbloop.partitions[0]["device"]]
+
             elif fstype == "ext2" or fstype == "ext3":
                 extlinuxcmd = fs_related.find_binary_path("extlinux")
                 syslinuxcfg = usbmnt + "/syslinux/extlinux.conf"
-                args = [extlinuxcmd, "-i", usbmnt + "/syslinux"]
+                args = [extlinuxcmd,
+                        "-i",
+                        usbmnt + "/syslinux"]
+
             else:
                 raise CreatorError("Invalid file system type: %s" % (fstype))
 
@@ -192,7 +246,7 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             usbloop.unmount()
             usbloop.cleanup()
 
-        #Need to do this after image is unmounted and device mapper is closed
+        # Need to do this after image is unmounted and device mapper is closed
         msger.info("set MBR")
         mbrfile = "/usr/lib/syslinux/mbr.bin"
         if not os.path.exists(mbrfile):
@@ -202,7 +256,13 @@ class LiveUSBImageCreator(LiveCDImageCreator):
         mbrsize = os.path.getsize(mbrfile)
         outimg = "%s/%s.usbimg" % (self._outdir, self.name)
 
-        args = ['dd', "if=" + mbrfile, "of=" + outimg, "seek=0", "conv=notrunc", "bs=1", "count=%d" % (mbrsize)]
+        args = ['dd',
+                "if=" + mbrfile,
+                "of=" + outimg,
+                "seek=0",
+                "conv=notrunc",
+                "bs=1",
+                "count=%d" % (mbrsize)]
         rc = runner.show(args)
         if rc:
             raise CreatorError("Can't set MBR.")
@@ -216,12 +276,16 @@ class LiveUSBImageCreator(LiveCDImageCreator):
 
             if not self.skip_minimize:
                 fs_related.create_image_minimizer(isodir + "/LiveOS/osmin.img",
-                                       self._image, minimal_size)
+                                                  self._image,
+                                                  minimal_size)
 
             if self.skip_compression:
-                shutil.move(self._image, isodir + "/LiveOS/ext3fs.img")
+                shutil.move(self._image,
+                            isodir + "/LiveOS/ext3fs.img")
             else:
-                fs_related.makedirs(os.path.join(os.path.dirname(self._image), "LiveOS"))
+                fs_related.makedirs(os.path.join(
+                                        os.path.dirname(self._image),
+                                        "LiveOS"))
                 shutil.move(self._image,
                             os.path.join(os.path.dirname(self._image),
                                          "LiveOS", "ext3fs.img"))
index 8ffeea8..5b39fec 100644 (file)
@@ -54,8 +54,10 @@ class LoopImageCreator(BaseImageCreator):
 
         self.__blocksize = 4096
         if self.ks:
-            self.__fstype = kickstart.get_image_fstype(self.ks, "ext3")
-            self.__fsopts = kickstart.get_image_fsopts(self.ks, "defaults,noatime")
+            self.__fstype = kickstart.get_image_fstype(self.ks,
+                                                       "ext3")
+            self.__fsopts = kickstart.get_image_fsopts(self.ks,
+                                                       "defaults,noatime")
 
             allloops = []
             for part in sorted(kickstart.get_partitions(self.ks),
@@ -72,7 +74,8 @@ class LoopImageCreator(BaseImageCreator):
                 else:
                     mp = mp.rstrip('/')
                     if not label:
-                        msger.warning('no "label" specified for loop img at %s, use the mountpoint as the name' % mp)
+                        msger.warning('no "label" specified for loop img at %s,'
+                                      ' use the mountpoint as the name' % mp)
                         label = mp.split('/')[-1]
 
                 imgname = misc.strip_end(label,'.img') + '.img'
@@ -94,7 +97,8 @@ class LoopImageCreator(BaseImageCreator):
         self.__imgdir = None
 
         if self.ks:
-            self.__image_size = kickstart.get_image_size(self.ks, 4096L * 1024 * 1024)
+            self.__image_size = kickstart.get_image_size(self.ks,
+                                                         4096L * 1024 * 1024)
         else:
             self.__image_size = 0
 
@@ -196,18 +200,18 @@ class LoopImageCreator(BaseImageCreator):
     def _resparse(self, size = None):
         """Rebuild the filesystem image to be as sparse as possible.
 
-            This method should be used by subclasses when staging the final image
-            in order to reduce the actual space taken up by the sparse image file
-            to be as little as possible.
+        This method should be used by subclasses when staging the final image
+        in order to reduce the actual space taken up by the sparse image file
+        to be as little as possible.
 
-            This is done by resizing the filesystem to the minimal size (thereby
-            eliminating any space taken up by deleted files) and then resizing it
-            back to the supplied size.
+        This is done by resizing the filesystem to the minimal size (thereby
+        eliminating any space taken up by deleted files) and then resizing it
+        back to the supplied size.
 
-            size -- the size in, in bytes, which the filesystem image should be
-                    resized to after it has been minimized; this defaults to None,
-                    causing the original size specified by the kickstart file to
-                    be used (or 4GiB if not specified in the kickstart).
+        size -- the size in, in bytes, which the filesystem image should be
+                resized to after it has been minimized; this defaults to None,
+                causing the original size specified by the kickstart file to
+                be used (or 4GiB if not specified in the kickstart).
         """
         minsize = 0
         for item in self._instloops:
@@ -264,7 +268,9 @@ class LoopImageCreator(BaseImageCreator):
             else:
                 msger.error('Cannot support fstype: %s' % fstype)
 
-            loop['loop'] = MyDiskMount(fs.SparseLoopbackDisk(os.path.join(self.__imgdir, imgname), size),
+            loop['loop'] = MyDiskMount(fs.SparseLoopbackDisk(
+                                           os.path.join(self.__imgdir, imgname),
+                                           size),
                                        mp,
                                        fstype,
                                        self._blocksize,
@@ -297,7 +303,9 @@ class LoopImageCreator(BaseImageCreator):
             tar = tarfile.open(os.path.join(self._outdir, tarfile_name), 'w')
             for item in self._instloops:
                 if item['fstype'] == "ext4":
-                    runner.show('/sbin/tune2fs -O ^huge_file,extents,uninit_bg ' + item['name'])
+                    runner.show('/sbin/tune2fs '
+                                '-O ^huge_file,extents,uninit_bg %s ' \
+                                % item['name'])
                 tar.add(item['name'])
 
             tar.close()
@@ -306,4 +314,5 @@ class LoopImageCreator(BaseImageCreator):
         else:
             self._resparse()
             for item in self._instloops:
-                shutil.move(os.path.join(self.__imgdir, item['name']), os.path.join(self._outdir, item['name']))
+                shutil.move(os.path.join(self.__imgdir, item['name']),
+                            os.path.join(self._outdir, item['name']))
index 6647218..22d7626 100644 (file)
@@ -30,10 +30,10 @@ from baseimager import BaseImageCreator
 class RawImageCreator(BaseImageCreator):
     """Installs a system into a file containing a partitioned disk image.
 
-        ApplianceImageCreator is an advanced ImageCreator subclass; a sparse file
-        is formatted with a partition table, each partition loopback mounted
-        and the system installed into an virtual disk. The disk image can
-        subsequently be booted in a virtual machine or accessed with kpartx
+    ApplianceImageCreator is an advanced ImageCreator subclass; a sparse file
+    is formatted with a partition table, each partition loopback mounted
+    and the system installed into an virtual disk. The disk image can
+    subsequently be booted in a virtual machine or accessed with kpartx
     """
 
     def __init__(self, *args):
@@ -64,7 +64,8 @@ class RawImageCreator(BaseImageCreator):
             os.chdir("/")
 
         if os.path.exists(self._instroot + "/usr/bin/Xorg"):
-            subprocess.call(["/bin/chmod", "u+s", "/usr/bin/Xorg"], preexec_fn = chroot)
+            subprocess.call(["/bin/chmod", "u+s", "/usr/bin/Xorg"],
+                            preexec_fn = chroot)
 
         BaseImageCreator.configure(self, repodata)
 
@@ -77,17 +78,17 @@ class RawImageCreator(BaseImageCreator):
                     p = p1
                     break
 
-            s += "%(device)s  %(mountpoint)s         %(fstype)s   %(fsopts)s 0 0\n" %  {
-                 'device': "/dev/%s%-d" % (p['disk'], p['num']),
-                 'mountpoint': p['mountpoint'],
-                 'fstype': p['fstype'],
-                 'fsopts': "defaults,noatime" if not p['fsopts'] else p['fsopts']}
+            s += "%(device)s  %(mountpoint)s  %(fstype)s  %(fsopts)s 0 0\n" % {
+               'device': "/dev/%s%-d" % (p['disk'], p['num']),
+               'mountpoint': p['mountpoint'],
+               'fstype': p['fstype'],
+               'fsopts': "defaults,noatime" if not p['fsopts'] else p['fsopts']}
 
             if p['mountpoint'] == "/":
                 for subvol in self.__instloop.subvolumes:
                     if subvol['mountpoint'] == "/":
                         continue
-                    s += "%(device)s  %(mountpoint)s         %(fstype)s   %(fsopts)s 0 0\n" %  {
+                    s += "%(device)s  %(mountpoint)s  %(fstype)s  %(fsopts)s 0 0\n" % {
                          'device': "/dev/%s%-d" % (p['disk'], p['num']),
                          'mountpoint': subvol['mountpoint'],
                          'fstype': p['fstype'],
@@ -108,7 +109,8 @@ class RawImageCreator(BaseImageCreator):
         mkinitrd += "rootfs=\"ext3\"\n"
         mkinitrd += "rootopts=\"defaults\"\n"
 
-        msger.debug("Writing mkinitrd config %s/etc/sysconfig/mkinitrd" % self._instroot)
+        msger.debug("Writing mkinitrd config %s/etc/sysconfig/mkinitrd" \
+                    % self._instroot)
         os.makedirs(self._instroot + "/etc/sysconfig/",mode=644)
         cfg = open(self._instroot + "/etc/sysconfig/mkinitrd", "w")
         cfg.write(mkinitrd)
@@ -138,10 +140,12 @@ class RawImageCreator(BaseImageCreator):
             if parts[i].disk:
                 disk = parts[i].disk
             else:
-                raise CreatorError("Failed to create disks, no --ondisk specified in partition line of ks file")
+                raise CreatorError("Failed to create disks, no --ondisk "
+                                   "specified in partition line of ks file")
 
             if not parts[i].fstype:
-                 raise CreatorError("Failed to create disks, no --fstype specified in partition line of ks file")
+                 raise CreatorError("Failed to create disks, no --fstype "
+                                    "specified in partition line of ks file")
 
             size =   parts[i].size * 1024L * 1024L
 
@@ -158,14 +162,26 @@ class RawImageCreator(BaseImageCreator):
 
         #create disk
         for item in disks:
-            msger.debug("Adding disk %s as %s/%s-%s.raw" % (item['name'], self.__imgdir,self.name, item['name']))
-            disk = fs_related.SparseLoopbackDisk("%s/%s-%s.raw" % (self.__imgdir,self.name, item['name']),item['size'])
+            msger.debug("Adding disk %s as %s/%s-%s.raw" % (item['name'],
+                                                            self.__imgdir,
+                                                            self.name,
+                                                            item['name']))
+            disk = fs_related.SparseLoopbackDisk("%s/%s-%s.raw" % (
+                                                                self.__imgdir,
+                                                                self.name,
+                                                                item['name']),
+                                                 item['size'])
             self.__disks[item['name']] = disk
 
         self.__instloop = PartitionedMount(self.__disks, self._instroot)
 
         for p in parts:
-            self.__instloop.add_partition(int(p.size), p.disk, p.mountpoint, p.fstype, fsopts = p.fsopts, boot = p.active)
+            self.__instloop.add_partition(int(p.size),
+                                          p.disk,
+                                          p.mountpoint,
+                                          p.fstype,
+                                          fsopts = p.fsopts,
+                                          boot = p.active)
 
         self.__instloop.mount()
         self._create_mkinitrd_config()
@@ -201,14 +217,18 @@ class RawImageCreator(BaseImageCreator):
 
     def _create_syslinux_config(self):
         #Copy splash
-        splash = "%s/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg" % self._instroot
+        splash = "%s/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg" \
+                 % self._instroot
+
         if os.path.exists(splash):
-            shutil.copy(splash, "%s%s/splash.jpg" % (self._instroot, "/boot/extlinux"))
+            shutil.copy(splash, "%s%s/splash.jpg" \
+                                % (self._instroot, "/boot/extlinux"))
             splashline = "menu background splash.jpg"
         else:
             splashline = ""
 
-        (bootdevnum, rootdevnum, rootdev, prefix) = self._get_syslinux_boot_config()
+        (bootdevnum, rootdevnum, rootdev, prefix) = \
+                                            self._get_syslinux_boot_config()
         options = self.ks.handler.bootloader.appendLine
 
         #XXX don't hardcode default kernel - see livecd code
@@ -242,16 +262,20 @@ class RawImageCreator(BaseImageCreator):
         footlabel = 0
         for v in versions:
             shutil.copy("%s/boot/vmlinuz-%s" %(self._instroot, v),
-                        "%s%s/vmlinuz-%s" % (self._instroot, "/boot/extlinux/", v))
-            syslinux_conf += "label %s%d\n" % (self.distro_name.lower(), footlabel)
+                        "%s%s/vmlinuz-%s" % (self._instroot,
+                                             "/boot/extlinux/", v))
+            syslinux_conf += "label %s%d\n" \
+                             % (self.distro_name.lower(), footlabel)
             syslinux_conf += "\tmenu label %s (%s)\n" % (self.distro_name, v)
             syslinux_conf += "\tkernel vmlinuz-%s\n" % v
-            syslinux_conf += "\tappend ro root=%s quiet vga=current %s\n" % (rootdev, options)
+            syslinux_conf += "\tappend ro root=%s quiet vga=current %s\n" \
+                             % (rootdev, options)
             if footlabel == 0:
                syslinux_conf += "\tmenu default\n"
             footlabel += 1;
 
-        msger.debug("Writing syslinux config %s/boot/extlinux/extlinux.conf" % self._instroot)
+        msger.debug("Writing syslinux config %s/boot/extlinux/extlinux.conf" \
+                    % self._instroot)
         cfg = open(self._instroot + "/boot/extlinux/extlinux.conf", "w")
         cfg.write(syslinux_conf)
         cfg.close()
@@ -264,31 +288,45 @@ class RawImageCreator(BaseImageCreator):
 
         msger.debug("Installing syslinux bootloader to %s" % loopdev)
 
-        (bootdevnum, rootdevnum, rootdev, prefix) = self._get_syslinux_boot_config()
+        (bootdevnum, rootdevnum, rootdev, prefix) = \
+                                    self._get_syslinux_boot_config()
 
 
         #Set MBR
-        mbrsize = os.stat("%s/usr/share/syslinux/mbr.bin" % self._instroot)[stat.ST_SIZE]
-        rc = runner.show(['dd', "if=%s/usr/share/syslinux/mbr.bin" % self._instroot, "of=" + loopdev])
+        mbrsize = os.stat("%s/usr/share/syslinux/mbr.bin" \
+                          % self._instroot)[stat.ST_SIZE]
+        rc = runner.show(['dd',
+                          'if=%s/usr/share/syslinux/mbr.bin' % self._instroot,
+                          'of=' + loopdev])
         if rc != 0:
             raise MountError("Unable to set MBR to %s" % loopdev)
 
         #Set Bootable flag
         parted = fs_related.find_binary_path("parted")
-        rc = runner.quiet([parted, "-s", loopdev, "set", "%d" % (bootdevnum + 1), "boot", "on"])
+        rc = runner.quiet([parted,
+                           "-s",
+                           loopdev,
+                           "set",
+                           "%d" % (bootdevnum + 1),
+                           "boot",
+                           "on"])
         #XXX disabled return code check because parted always fails to
         #reload part table with loop devices. Annoying because we can't
         #distinguish this failure from real partition failures :-(
         if rc != 0 and 1 == 0:
-            raise MountError("Unable to set bootable flag to %sp%d" % (loopdev, (bootdevnum + 1)))
+            raise MountError("Unable to set bootable flag to %sp%d" \
+                             % (loopdev, (bootdevnum + 1)))
 
         #Ensure all data is flushed to disk before doing syslinux install
         runner.quiet('sync')
 
         fullpathsyslinux = fs_related.find_binary_path("extlinux")
-        rc = runner.show([fullpathsyslinux, "-i", "%s/boot/extlinux" % self._instroot])
+        rc = runner.show([fullpathsyslinux,
+                          "-i",
+                          "%s/boot/extlinux" % self._instroot])
         if rc != 0:
-            raise MountError("Unable to install syslinux bootloader to %sp%d" % (loopdev, (bootdevnum + 1)))
+            raise MountError("Unable to install syslinux bootloader to %sp%d" \
+                             % (loopdev, (bootdevnum + 1)))
 
     def _create_bootconfig(self):
         #If syslinux is available do the required configurations.
@@ -332,8 +370,8 @@ class RawImageCreator(BaseImageCreator):
             name_attributes += " release='%s'" % self.appliance_release
         xml += "  <name%s>%s</name>\n" % (name_attributes, self.name)
         xml += "  <domain>\n"
-        # XXX don't hardcode - determine based on the kernel we installed for grub
-        # baremetal vs xen
+        # XXX don't hardcode - determine based on the kernel we installed for
+        # grub baremetal vs xen
         xml += "    <boot type='hvm'>\n"
         xml += "      <guest>\n"
         xml += "        <arch>%s</arch>\n" % imgarch
@@ -344,7 +382,8 @@ class RawImageCreator(BaseImageCreator):
 
         i = 0
         for name in self.__disks.keys():
-            xml += "      <drive disk='%s-%s.%s' target='hd%s'/>\n" % (self.name,name, self.__disk_format,chr(ord('a')+i))
+            xml += "      <drive disk='%s-%s.%s' target='hd%s'/>\n" \
+                   % (self.name,name, self.__disk_format,chr(ord('a')+i))
             i = i + 1
 
         xml += "    </boot>\n"
@@ -360,12 +399,16 @@ class RawImageCreator(BaseImageCreator):
 
         if self.checksum is True:
             for name in self.__disks.keys():
-                diskpath = "%s/%s-%s.%s" % (self._outdir,self.name,name, self.__disk_format)
+                diskpath = "%s/%s-%s.%s" \
+                           % (self._outdir,self.name,name, self.__disk_format)
                 disk_size = os.path.getsize(diskpath)
                 meter_ct = 0
                 meter = progress.TextMeter()
-                meter.start(size=disk_size, text="Generating disk signature for %s-%s.%s" % (self.name,name,self.__disk_format))
-                xml += "    <disk file='%s-%s.%s' use='system' format='%s'>\n" % (self.name,name, self.__disk_format, self.__disk_format)
+                meter.start(size=disk_size,
+                            text="Generating disk signature for %s-%s.%s" \
+                                 % (self.name,name,self.__disk_format))
+                xml += "    <disk file='%s-%s.%s' use='system' format='%s'>\n" \
+                       % (self.name,name, self.__disk_format, self.__disk_format)
 
                 try:
                     import hashlib
@@ -387,20 +430,24 @@ class RawImageCreator(BaseImageCreator):
                     meter_ct = meter_ct + 65536
 
                 sha1checksum = m1.hexdigest()
-                xml +=  """      <checksum type='sha1'>%s</checksum>\n""" % sha1checksum
+                xml +=  "      <checksum type='sha1'>%s</checksum>\n" \
+                        % sha1checksum
 
                 if m2:
                     sha256checksum = m2.hexdigest()
-                    xml += """      <checksum type='sha256'>%s</checksum>\n""" % sha256checksum
+                    xml += "      <checksum type='sha256'>%s</checksum>\n" \
+                           % sha256checksum
+
                 xml += "    </disk>\n"
         else:
             for name in self.__disks.keys():
-                xml += "    <disk file='%s-%s.%s' use='system' format='%s'/>\n" % (self.name,name, self.__disk_format, self.__disk_format)
+                xml += "    <disk file='%s-%s.%s' use='system' format='%s'/>\n"\
+                       %(self.name,name, self.__disk_format, self.__disk_format)
 
         xml += "  </storage>\n"
         xml += "</image>\n"
 
-        msger.debug("writing image XML to %s/%s.xml" %  (self._outdir, self.name))
+        msger.debug("writing image XML to %s/%s.xml" %(self._outdir, self.name))
         cfg = open("%s/%s.xml" % (self._outdir, self.name), "w")
         cfg.write(xml)
         cfg.close()
index ae41894..cedcdc2 100644 (file)
@@ -51,7 +51,8 @@ class PluginMgr(object):
         path = os.path.abspath(os.path.expanduser(path))
 
         if not os.path.isdir(path):
-            msger.warning("Plugin dir is not a directory or does not exist: %s" % path)
+            msger.warning("Plugin dir is not a directory or does not exist: %s"\
+                          % path)
             return
 
         if path not in self.plugin_dirs:
@@ -72,20 +73,23 @@ class PluginMgr(object):
                         try:
                             pymod = __import__(mod)
                             self.plugin_dirs[pdir] = True
-                            msger.debug("Plugin module %s:%s imported" % (mod, pymod.__file__))
+                            msger.debug("Plugin module %s:%s imported"\
+                                        % (mod, pymod.__file__))
                         except ImportError, e:
-                            msger.warning('%s, skip plugin %s/%s' %(str(e), os.path.basename(pdir), mod))
+                            msger.warning('%s, skip plugin %s/%s'\
+                                          %(str(e), os.path.basename(pdir), mod))
 
             del(sys.path[0])
 
     def get_plugins(self, ptype):
         """ the return value is dict of name:class pairs """
-        if ptype in PLUGIN_TYPES:
-            self._add_plugindir(os.path.join(DEFAULT_PLUGIN_LOCATION, ptype))
-            self._load_all()
-        else:
+
+        if ptype not in PLUGIN_TYPES:
             raise errors.CreatorError('%s is not valid plugin type' % ptype)
 
+        self._add_plugindir(os.path.join(DEFAULT_PLUGIN_LOCATION, ptype))
+        self._load_all()
+
         return pluginbase.get_plugins(ptype)
 
 pluginmgr = PluginMgr()