[gnome-boxes] Store hostname as an UnattendedInstaller property



commit 21a8c2b62a121f2edc94070b499f59cafc49adeb
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Sat May 26 11:41:45 2012 +0200

    Store hostname as an UnattendedInstaller property
    
    This allows to make the code setting the host name in unattended
    files much less convoluted.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677038

 src/fedora-installer.vala     |    4 ++--
 src/unattended-installer.vala |   20 +++++++++++---------
 src/win7-installer.vala       |    4 ++--
 src/winxp-installer.vala      |    4 ++--
 4 files changed, 17 insertions(+), 15 deletions(-)
---
diff --git a/src/fedora-installer.vala b/src/fedora-installer.vala
index de2b0db..609a7c2 100644
--- a/src/fedora-installer.vala
+++ b/src/fedora-installer.vala
@@ -91,8 +91,8 @@ private class Boxes.FedoraInstaller: UnattendedInstaller {
         }
     }
 
-    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
-        var str = base.fill_unattended_data (data, hostname);
+    protected override string fill_unattended_data (string data) throws RegexError {
+        var str = base.fill_unattended_data (data);
 
         str = kbd_regex.replace (str, str.length, 0, kbd);
 
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index f5d392d..08cea19 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -51,6 +51,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
 
     protected string timezone;
     protected string lang;
+    protected string hostname;
 
     protected AvatarFormat avatar_format;
 
@@ -117,12 +118,13 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         setup_ui ();
     }
 
-    public async void setup (string hostname, Cancellable? cancellable) throws GLib.Error {
+    public async void setup (string vm_name, Cancellable? cancellable) throws GLib.Error {
         if (!express_toggle.active) {
             debug ("Unattended installation disabled.");
 
             return;
         }
+        this.hostname = vm_name.replace (" ", "-");
 
         try {
             if (yield unattended_disk_exists (cancellable))
@@ -131,7 +133,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
                 yield create_disk_image (cancellable);
 
             foreach (var unattended_file in unattended_files)
-                yield unattended_file.copy (hostname, cancellable);
+                yield unattended_file.copy (cancellable);
             yield prepare_direct_boot (cancellable);
         } catch (GLib.Error error) {
             clean_up ();
@@ -175,7 +177,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
                         (_("Password required for express installation of %s"), label);
     }
 
-    public virtual string fill_unattended_data (string data, string hostname) throws RegexError {
+    public virtual string fill_unattended_data (string data) throws RegexError {
         var str = username_regex.replace (data, data.length, 0, username_entry.text);
         str = password_regex.replace (str, str.length, 0, password);
         str = timezone_regex.replace (str, str.length, 0, timezone);
@@ -330,8 +332,8 @@ private interface Boxes.UnattendedFile : GLib.Object {
 
     protected abstract UnattendedInstaller installer  { get; set; }
 
-    public async void copy (string hostname, Cancellable? cancellable) throws GLib.Error {
-        var unattended_tmp = yield create (hostname, cancellable);
+    public async void copy (Cancellable? cancellable) throws GLib.Error {
+        var unattended_tmp = yield create (cancellable);
 
         debug ("Copying unattended file '%s' into disk drive/image '%s'", dest_name, installer.disk_path);
         // FIXME: Perhaps we should use libarchive for this?
@@ -346,7 +348,7 @@ private interface Boxes.UnattendedFile : GLib.Object {
         debug ("Deleted temporary file '%s'", unattended_tmp.get_path ());
     }
 
-    protected abstract async File create (string hostname, Cancellable? cancellable)  throws GLib.Error;
+    protected abstract async File create (Cancellable? cancellable)  throws GLib.Error;
 }
 
 private class Boxes.UnattendedTextFile : GLib.Object, Boxes.UnattendedFile {
@@ -361,7 +363,7 @@ private class Boxes.UnattendedTextFile : GLib.Object, Boxes.UnattendedFile {
        this.dest_name = dest_name;
     }
 
-    protected async File create (string hostname, Cancellable? cancellable)  throws GLib.Error {
+    protected async File create (Cancellable? cancellable)  throws GLib.Error {
         var source = File.new_for_path (src_path);
         var destination_path = get_user_unattended (dest_name);
         var destination = File.new_for_path (destination_path);
@@ -377,7 +379,7 @@ private class Boxes.UnattendedTextFile : GLib.Object, Boxes.UnattendedFile {
         data_stream.newline_type = DataStreamNewlineType.ANY;
         string? str;
         while ((str = yield data_stream.read_line_async (Priority.DEFAULT, cancellable)) != null) {
-            str = installer.fill_unattended_data (str, hostname);
+            str = installer.fill_unattended_data (str);
 
             str += (installer.newline_type == DataStreamNewlineType.LF) ? "\n" : "\r\n";
 
@@ -405,7 +407,7 @@ private class Boxes.UnattendedAvatarFile : GLib.Object, Boxes.UnattendedFile {
         this.dest_format = dest_format;
     }
 
-    protected async File create (string hostname, Cancellable? cancellable)  throws GLib.Error {
+    protected async File create (Cancellable? cancellable)  throws GLib.Error {
         dest_name = installer.username + dest_format.extension;
         var destination_path = get_user_unattended (dest_name);
 
diff --git a/src/win7-installer.vala b/src/win7-installer.vala
index dfbcebc..7e805e5 100644
--- a/src/win7-installer.vala
+++ b/src/win7-installer.vala
@@ -14,8 +14,8 @@ private class Boxes.Win7Installer: WindowsInstaller {
         }
     }
 
-    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
-        var str = base.fill_unattended_data (data, hostname);
+    protected override string fill_unattended_data (string data) throws RegexError {
+        var str = base.fill_unattended_data (data);
 
         switch (os_media.architecture) {
             case "x86_64":
diff --git a/src/winxp-installer.vala b/src/winxp-installer.vala
index dd51d2c..73caf76 100644
--- a/src/winxp-installer.vala
+++ b/src/winxp-installer.vala
@@ -74,8 +74,8 @@ private class Boxes.WinXPInstaller: WindowsInstaller {
         key_inserted_id = key_entry.insert_text.connect (on_key_text_inserted);
     }
 
-    protected override string fill_unattended_data (string data, string hostname) throws RegexError {
-        var str = base.fill_unattended_data (data, hostname);
+    protected override string fill_unattended_data (string data) throws RegexError {
+        var str = base.fill_unattended_data (data);
         var admin_pass = (password != "") ? password : "*";
         str = admin_pass_regex.replace (str, str.length, 0, admin_pass);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]