--- loader/loader.c | 44 ++++++++++++------------------------ pyanaconda/product.py | 57 ++++++++++++++++++---------------------------- scripts/mk-images | 13 +++++----- scripts/mk-images.sparc | 14 ++++++----- 4 files changed, 52 insertions(+), 76 deletions(-) diff --git a/loader/loader.c b/loader/loader.c index 187f6d0..15c091e 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -267,49 +267,35 @@ static gchar *productName = NULL; static gchar *productArch = NULL; static void initProductInfo(void) { - gchar *contents = NULL; - gchar **lines = NULL, **stamp = NULL; - GError *fileErr = NULL; + GKeyFile *key_file = g_key_file_new(); + GError *loadErr = NULL; - if (!g_file_get_contents("/.buildstamp", &contents, NULL, &fileErr)) { - logMessage(ERROR, "error reading .buildstamp: %s", fileErr->message); - g_error_free(fileErr); + if (!g_key_file_load_from_file(key_file, "/.buildstamp", G_KEY_FILE_NONE, &loadErr)) { + logMessage(ERROR, "error reading .buildstamp: %s", loadErr->message); + g_error_free(loadErr); productName = g_strdup("anaconda"); productArch = g_strdup("unknown architecture"); return; } - /* .buildstamp uses the first 3 lines in this format: - * STAMP.productArch - * productName - */ - lines = g_strsplit(contents, "\n", 0); - g_free(contents); + if (g_key_file_has_key(key_file, "Main", "Product", NULL)) + productName = g_key_file_get_string(key_file, "Main", "Product", NULL); + else + productName = g_strdup("anaconda"); - if ((lines != NULL) && (g_strv_length(lines) >= 3)) { - /* STAMP.productArch */ - stamp = g_strsplit(lines[0], ".", 0); + if (g_key_file_has_key(key_file, "Main", "UUID", NULL)) { + gchar **parts = g_strsplit(g_key_file_get_string(key_file, "Main", "UUID", NULL), ".", 0); - if ((stamp != NULL) && (g_strv_length(stamp) == 2)) { - productArch = g_strdup(stamp[1]); - } else { + if (parts != NULL && g_strv_length(parts) == 2) + productArch = g_strdup(parts[1]); + else productArch = g_strdup("unknown architecture"); - } - if (stamp) { - g_strfreev(stamp); - } - - productName = g_strdup(lines[1]); + g_strfreev(parts); } else { - productName = g_strdup("anaconda"); productArch = g_strdup("unknown architecture"); } - if (lines) { - g_strfreev(lines); - } - return; } diff --git a/pyanaconda/product.py b/pyanaconda/product.py index e271b45..49ec573 100644 --- a/pyanaconda/product.py +++ b/pyanaconda/product.py @@ -17,44 +17,31 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # +import ConfigParser import os -if os.access("/tmp/product/.buildstamp", os.R_OK): - path = "/tmp/product/.buildstamp" -elif os.access("/.buildstamp", os.R_OK): - path = "/.buildstamp" -elif os.environ.has_key("PRODBUILDPATH") and \ - os.access(os.environ["PRODBUILDPATH"], os.R_OK): - path = os.environ["PRODBUILDPATH"] -else: - path = None +# First, load in the defaults. In order of precedence: contents of +# .buildstamp, environment, stupid last ditch hardcoded defaults. +config = ConfigParser.ConfigParser({"Arch": os.environ.get("ANACONDA_PRODUCTARCH", ""), + "BugURL": os.environ.get("ANACONDA_BUGURL", "your distribution provided bug reporting tool"), + "IsBeta": os.environ.get("ANACONDA_ISBETA", "true").lower() == "true", + "Product": os.environ.get("ANACONDA_PRODUCTNAME", "anaconda"), + "UUID": "", + "Version": os.environ.get("ANACONDA_PRODUCTVERSION", "bluesky")} + ) -productStamp = "" -productName = "anaconda" -productVersion = "bluesky" -productArch = None -bugUrl = "your distribution provided bug reporting tool." +# Now read in the .buildstamp file, wherever it may be. +config.read(["/tmp/product/.buildstamp", "/.buildstamp", os.environ.get("PRODBUILDPATH", "")]) -if path is not None: - f = open(path, "r") - lines = f.readlines() - del f - if len(lines) >= 3: - productStamp = lines[0][:-1] - productArch = productStamp[productStamp.index(".")+1:] - productName = lines[1][:-1] - productVersion = lines[2][:-1] - if len(lines) >= 4: - bugUrl = lines[3][:-1] +# Set up some variables we import throughout, applying a couple transforms as necessary. +bugUrl = config.get("Main", "BugURL") +isBeta = config.get("Main", "IsBeta").lower() != "false" +productArch = config.get("Main", "Arch") +productName = config.get("Main", "Product") +productStamp = config.get("Main", "UUID") +productVersion = config.get("Main", "Version") -if os.environ.has_key("ANACONDA_PRODUCTNAME"): - productName = os.environ["ANACONDA_PRODUCTNAME"] -if os.environ.has_key("ANACONDA_PRODUCTVERSION"): - productVersion = os.environ["ANACONDA_PRODUCTVERSION"] -if os.environ.has_key("ANACONDA_PRODUCTARCH"): - productArch = os.environ["ANACONDA_PRODUCTARCH"] -if os.environ.has_key("ANACONDA_BUGURL"): - bugUrl = os.environ["ANACONDA_BUGURL"] - -if productVersion == "development": # hack to transform for now +if not productArch: + productArch = productStamp[productStamp.index(".")+1:] +if productVersion == "development": productVersion = "rawhide" diff --git a/scripts/mk-images b/scripts/mk-images index 4286fc0..a67ef84 100755 --- a/scripts/mk-images +++ b/scripts/mk-images @@ -358,12 +358,13 @@ makeproductfile() { root=$1 rm -f $root/.buildstamp - echo $IMAGEUUID > $root/.buildstamp - echo $PRODUCT >> $root/.buildstamp - echo $VERSION >> $root/.buildstamp - if [ -n "$BUGURL" ]; then - echo $BUGURL >> $root/.buildstamp - fi + cat > $root/.buildstamp << EOF +[Main] +BugURL=$BUGURL +Product=$PRODUCT +UUID=$IMAGEUUID +Version=$VERSION +EOF } instbin() { diff --git a/scripts/mk-images.sparc b/scripts/mk-images.sparc index 7faf9e4..a46eb49 100644 --- a/scripts/mk-images.sparc +++ b/scripts/mk-images.sparc @@ -37,12 +37,14 @@ makeproductfile() { root=$1 rm -f $root/.buildstamp - echo $IMAGEUUID > $root/.buildstamp - echo $PRODUCT >> $root/.buildstamp - echo $VERSION >> $root/.buildstamp - if [ -n "$BUGURL" ]; then - echo $BUGURL >> $root/.buildstamp - fi + cat > $root/.buildstamp << EOF +[Main] +BugURL=$BUGURL +Product=$PRODUCT +UUID=$IMAGEUUID +Version=$VERSION +EOF + if [ "$AMITFTP" = "1" ]; then rm -rf $root/modules/*/kernel/drivers/isdn/i4l/isdn.ko* rm -rf $root/modules/*/kernel/drivers/isdn/isdnloop/isdnloop.ko* -- 1.7.1.1 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list