Commits

Rodrigo Bistolfi committed d89f754

Experimental support for showing custom messages in pb

  • Participants
  • Parent commits e4402fc

Comments (0)

Files changed (5)

vinstall/controller/automatic.py

         """
         disk = self.get_disk(diskindex)
 
-        yield self.partitioning, (disk,)
-        yield self.format_partitions, (disk,)
-        yield self.mount_target, (disk,)
+        yield self.partitioning, (disk,), "Partitioning %s" % disk
+        yield self.format_partitions, (disk,), "Formating partitions"
+        yield self.mount_target, (disk,), "Mounting target"
 
-        yield self.preinstall, tuple()
+        yield self.preinstall, tuple(), "Preparing package install"
         for package in self.packages():
-            yield self.installpkg, (package, disk)
-        yield self.postinstall, tuple()
-        yield self.install_kernels, tuple()
-        # Bind mounts
-        yield self.set_bind_mounts, tuple()
+            yield self.installpkg, (package, disk), "Installing %s" % package.split("/")[-1]
+        yield self.postinstall, tuple(), "Installing setup routines"
+        yield self.install_kernel, tuple(), "Installing Linux kernel"
 
-        yield self.fstab, (disk,)        
-        yield self.setup_services, tuple()
-        yield self.vector_version, tuple()
-        yield self.bootloader, (disk.path(),)
-
-        # Clear bind mounts at the very end
-        yield self.clear_bind_mounts, tuple()
+        yield self.set_bind_mounts, tuple(), "Mounting pseudo filesystems"
+        yield self.fstab, (disk,), "Creating fstab"
+        yield self.setup_services, tuple(), "Setting up services"
+        yield self.vector_version, tuple(), "Writting /etc/vector-version"
+        yield self.bootloader, (disk,), "Installing bootloader"
+        yield self.clear_bind_mounts, tuple(), "Clearing bind mounts"
 
     def previous(self):
         """Go back to the first screen
         """Jump to the basic Setup
 
         """
-        if not self._check_continue():
-            return None
         return Setup
 
     # utility methods
         else:
             swap_size = int(available_ram / 2)
 
-        disk_size = disk.size(unit="MiB")            
+        disk_size = disk.size(unit="MiB")
         partitioner = partitioning.DiskPartitioner(disk)
         if not disk.has_partition_table():
             partitioner.create_partition_table()
 
         root_size = disk.free_space("MiB") - swap_size
         partitioner.add_partition(size=root_size, units='MiB')
-        # Read how much space is left on the device.
         swap_size = disk.free_space("MiB")
         partitioner.add_partition(size=swap_size, units='MiB')
         partitioner.write_changes()
         packages first.
 
         """
+        if not self._check_continue():
+            return
+
         aaa = glob.glob("/mnt/SOURCE/packages/a/aaa_base-*.t?z")[0]
         self.installpkg(aaa, "/mnt/TARGET")
 
         installed at last, or for post install required tasks.
 
         """
+        if not self._check_continue():
+            return
+
         vlconfig = glob.glob("/mnt/SOURCE/packages/a/vlconfig2-*.t?z")[0]
         self.installpkg(vlconfig, "/mnt/TARGET")
 
+    def install_kernel(self):
+        """Copy the kernel from the initrd to the target
+
+        kernel is in the ISO as 'sata' in isolinux/kernel/
+        Represented in VINSTALL.INI as "sata=version"
+
+        """
+        if not self._check_continue():
+            return
+
+        install_media = self.config["install_media"]
+        kernel_version = install_media.config.get("kernels", "sata")
+        kernel_version = kernel_version.replace("\"", "")
+        source = os.path.join('/mnt', 'SOURCE', 'isolinux', 'kernel',
+                'sata')
+        target = os.path.join('/mnt', 'TARGET', 'boot', 'vmlinuz-%s' %
+            kernel_version)
+        shutil.copyfile(source, target)
+
     def fstab(self, disk):
         """Create and install a fstab file in disk
 
         print "Installing fstab in", disk
         if not self._check_continue():
             return
+
         fstab_obj = fstab.Fstab("/mnt/TARGET/etc/fstab")
         root_entry = fstab.FstabEntry(device = "%s1" % disk.path(),
-                                      mountpoint = "/",
-                                      filesystem = self.ROOT_FS)
+                mountpoint = "/", filesystem = self.ROOT_FS)
         swap_entry = fstab.FstabEntry(device = "%s2" % disk.path(),
-                                      mountpoint = "none",
-                                      filesystem="swap")
+                mountpoint = "none", filesystem="swap")
         for entry in (root_entry, swap_entry):
             fstab_obj.add_entry(entry)
 
-
-    def set_bind_mounts(self):
-        """Bind mount some paths into the target.
-        Later steps will need this when we chroot there """
-        if not self._check_continue():
-            return
-        for point in ("sys","proc","dev"):
-            subprocess.check_call(["mount","-o","bind","/%s"% point,"/mnt/TARGET/%s"%point])
-        return
-
-    def clear_bind_mounts(self):
-        """Clear the mountpoints that were mounted for the configuration"""
-        if not self._check_continue():
-            return
-        for point in ("sys","proc","dev"):
-            subprocess.check_call(["umount","-f","/mnt/TARGET/%s"%point])
-        return
-    
     def setup_services(self):
-        """Setup default system services"""
-        #FIXME:  Define the default set of services for each runlevel
+        """Setup default system services
+
+        """
+        #XXX:  Define the default set of services for each runlevel
         # At some other location so they can be used by advanced.py too
-        
+
         if not self._check_continue():
             return
 
-        svcbasic = [ "cron","portmap","lm_sensors","gpm","inetd" ]
-        svc2 = svcbasic
-        svc3 = svcbasic
-        svc3.extend(["samba","cups","sshd"])
-        svc4 = svcbasic
-        svc4.extend(["bluetooth","fuse","cups"])
-        svc5 = svc3
-        svc5.extend(["bluetooth","fuse"])
+        svcbasic = [ "cron", "portmap", "lm_sensors", "gpm", "inetd" ]
+        svc2 = svcbasic[:]
+        svc3 = svcbasic[:]
+        svc3.extend(["samba", "cups", "sshd"])
+        svc4 = svcbasic[:]
+        svc4.extend(["bluetooth", "fuse", "cups"])
+        svc5 = svc3[:]
+        svc5.extend(["bluetooth", "fuse"])
 
-        
         for svc in service.Service.all("/mnt/TARGET"):
-            for model, runlevel in ((svc2, 2), (svc3, 3), (svc4, 4), (svc5, 5)):
-                if svc.name in model:
+            for s, runlevel in ((svc2, 2), (svc3, 3), (svc4, 4), (svc5, 5)):
+                if svc.name in s:
                     svc.enable(runlevel)
-        return
-
 
     def bootloader(self, disk):
         """Install the default bootloader in disk
 
         """
+        print "Installing bootloader in", disk
+
         if not self._check_continue():
             return
 
-        print "Installing bootloader in", disk
-	print " installing to MBR in ", disk
-        vga_size = "800x600" # screen resolution
-        vga_quality = "16" # color depth
-        timeout = 5 # seconds
-        grub = bootloader.Grub2(target=disk,
-                               vga_size = vga_size,
-                               vga_quality = vga_quality,
-                               timeout = timeout)
+        vga_size = "800x600"
+        vga_quality = "16"
+        timeout = 5
+        grub = bootloader.Grub2(target=disk.path(), vga_size=vga_size,
+                vga_quality=vga_quality, timeout=timeout)
         with utils.Chroot("/mnt/TARGET"):
             grub.write_config("/etc/default/grub")
             grub.install()
 
-    def install_kernels(self):
-        """Copy the kernels from the initrd to the target"""
-        # kernel is in the ISO as 'sata' in isolinux/kernel/
-        # Represented in VINSTALL.INI as "sata=version"
-
-        src = self.config["install_media"]
-        kver = src.config.get("kernels", "sata").replace("\"","")
-        ksrc = os.path.join('/mnt', 'SOURCE', 'isolinux','kernel', 'sata')
-        ktgt = os.path.join('/mnt', 'TARGET', 'boot', 'vmlinuz-%s'% kver)
-        shutil.copyfile(ksrc, ktgt)
-        
     def vector_version(self):
         """write /etc/vector-version based on the information
-        in VINSTALL.INI"""
+        in VINSTALL.INI
 
+        """
         print "Writing vector-version"
-        installed = self.config["install_media"]
-        distro = installed.config.get("general", "distro").replace("\"","")
-        version = installed.config.get("general", "version").replace("\"","")
-        build_date = installed.config.get("general","build_date").replace("\"","")
-        vecver =  "%s built on %s"% (version, build_date)
-        f = open("/mnt/TARGET/etc/vector-version", 'w')
-        f.writelines([vecver, "\n"])
-        f.close()
+
+        if not self._check_continue():
+            return
+
+        install_media = self.config["install_media"]
+        distro = install_media.config.get("general", "distro").replace("\"", "")
+        version = install_media.config.get("general", "version").replace("\"", "")
+        build_date = install_media.config.get("general",
+                "build_date").replace("\"", "")
+        vector_version =  "%s built on %s\n" % (version, build_date)
+        with open("/mnt/TARGET/etc/vector-version", 'w') as f:
+            f.write(vector_version)
+
+    def set_bind_mounts(self):
+        """Bind mount some paths into the target.
+        Later steps will need this when we chroot there
+
+        """
+        if not self._check_continue():
+            return
+
+        for point in ("sys","proc","dev"):
+            cmd = "mount -o bind /%s /mnt/TARGET/%s" % (point, point)
+            subprocess.check_call(cmd.split())
+
+    def clear_bind_mounts(self):
+        """Clear the mountpoints that were mounted for the configuration
+
+        """
+        if not self._check_continue():
+            return
+
+        for point in ("sys","proc","dev"):
+            cmd = "umount -f /mnt/TARGET/%s" % point
+            subprocess.check_call(cmd.split())
 
     def _check_continue(self):
         return 'I_MEAN_IT' in os.environ
 
-        
+
 
 class Setup(Controller):
     """Minimal configuration - Ask for username and passwords
         """Create a user and setup passwords
 
         """
-        print "Creating user and setting passwords:", username, password, rootpassword
-        yield self.set_root_password, (rootpassword,)
-        yield self.create_user_account, (username, password)
-    
+        yield self.set_root_password, (rootpassword,), "Creating users"
+        yield self.create_user_account, (username, password), "Setting passwords"
+
     def set_root_password(self, rootpassword):
-        """Set the root password"""
+        """Set the root password
+
+        """
+        if not self._check_continue():
+            return
+
         admin = users.User()
         admin.root = "/mnt/TARGET"
         admin.login = "root"
         with utils.Chroot("/mnt/TARGET"):
             admin.change_password(rootpassword)
-        return
-    
+
     def create_user_account(self, username, userpassword):
-        """Create a user account and set its password"""
+        """Create a user account and set its password
+
+        """
+        if not self._check_continue():
+            return
+
         account = users.User()
         account.root = "/mnt/TARGET"
         account.login = username
         account.password = userpassword
         with utils.Chroot("/mnt/TARGET"):
             account.create()
-        
-        return
+
+    def _check_continue(self):
+        return 'I_MEAN_IT' in os.environ
+
 

vinstall/core/application.py

             func, args = item
             if isgeneratorfunction(func):
                 LOG.debug("Command function %s is a generator function" % func)
-                for f, a in func(*args):
+                for f, a, desc in func(*args):
                     LOG.debug("Adding %s to the queue, with args: %s" % (f, a))
-                    processing.add_command(f, *a)
+                    processing.add_command(f, args=a, description=desc)
             else:
                 LOG.debug("Adding function %s to the queue, with args: %s"
                           % (func, args))
-                processing.add_command(func, *args)
+                processing.add_command(func, args=args, description=func.__doc__)
 
         LOG.debug("Processing commands")
         render = type(self.current_render)

vinstall/core/command.py

 
 class Command(object):
 
-    def __init__(self, func, *args, **kwargs):
+    def __init__(self, func, args=None, kwargs=None, description=None):
         """Store the callable and its arguments.
 
         Example:
         self.func = func
         self.args = args or tuple()
         self.kwargs = kwargs or {}
+        self.description = description or ""
 
     def __call__(self):
         """Call the command.
         self.observer = observer
         self.processing = BatchProcessor(input_queue)
 
-    def add_command(self, func, *args, **kwargs):
+    def add_command(self, func, args=None, kwargs=None, description=None):
         """Create a Command instance and add it to the stack.
 
         """
-        command = Command(func, *args, **kwargs)
+        command = Command(func, args, kwargs, desc)
         self.input_queue.put(command)
 
     def execute_all(self):
 
     def testCommand(self):
 
-        command = Command(lambda x, y: x + y, 1, 2)
+        command = Command(lambda x, y: x + y, (1, 2))
         self.assertEquals(command(), 3)
 
 
         queue = Queue()
         f = ProcessingFacade(queue)
         func = lambda x: x + 1
-        f.add_command(func, 1)
+        f.add_command(func, (1,))
 
     def testObserver(self):
 
         facade.observer = ProcessingObserver()
 
         for i in range(2):
-            queue.put(Command(lambda x: x+1, i))
+            queue.put(Command(lambda x: x+1, (i,)))
 
         facade.execute_all()
         queue.join()
 
         queue = Queue()
         facade = ProcessingFacade(queue)
-        facade.add_command(f1, 2)
-        facade.add_command(f2, 2)
+        facade.add_command(f1, (2,))
+        facade.add_command(f2, (2,))
         facade.execute_all()
         time.sleep(1)
         self.assertEquals(results, [2, 4])
 
 
         for i in range(2):
-            queue.put(Command(lambda x: x+1, i))
+            queue.put(Command(lambda x: x+1, (i,)))
 
         bp.start()
         queue.join()

vinstall/ui/gtk.py

         """Called before processing the item
 
         """
-        self.caption.set_text("Processing " + str(item))
+        self.caption.set_text(item.description)
 
     def on_item_end(self, args):
         """Called after item is complete. Args is a tuple with

vinstall/ui/urwid.py

         """Called before processing the item
 
         """
-        self.caption.set_text("Processing " + str(item))
+        self.caption.set_text(item.description)
         os.write(UrwidMainWindow.pipe, "update")
 
     def on_item_end(self, args):