Hello,

I tried to make a little patch for nALFS to permit some conditionnal execution. That works for me but I can't find why the RUN_STATUS_SKIPPED is'nt print on screen

This patch adds 2 new attributes on <PARAM>, <PACKAGE> and <STAGE> : if_cmd and if_args

For example :

<PARAM if_cmd="test" if_args="-d /opt/opensll">--with-ssl=/opt/openssl</PARAM> would execute the command test -d /opt/openssl and if it return 0 then this PARAM will be added


JC Passard

diff -Naur nALFS-SVN.orig/doc/ALFS.dtd nALFS-SVN/doc/ALFS.dtd
--- nALFS-SVN.orig/doc/ALFS.dtd 2006-12-11 04:25:05.000000000 +0100
+++ nALFS-SVN/doc/ALFS.dtd      2007-04-04 20:46:53.000000000 +0200
@@ -108,13 +108,18 @@
 <!ELEMENT package        (packageinfo?, stage+)>
 <!ATTLIST package
           name           CDATA #REQUIRED
-          version        CDATA #REQUIRED>
+          version        CDATA #REQUIRED
+         if_command     CDATA #IMPLIED
+         if_args        CDATA #IMPLIED>
 
 <!ELEMENT packageinfo    (description?, requires*, utilizes*)>
 
 <!ELEMENT para           (#PCDATA)>
 
 <!ELEMENT param          (#PCDATA)>
+<!ATTLIST param
+         if_command     CDATA #IMPLIED
+         if_args        CDATA #IMPLIED>
 
 <!ELEMENT patch          ((param | prefix)+)>
 <!ATTLIST patch
@@ -145,7 +150,9 @@
 
 <!ELEMENT stage          (stageinfo?, (alfs | %ops;)*)>
 <!ATTLIST stage
-          name           CDATA #IMPLIED>
+          name           CDATA #IMPLIED
+         if_command     CDATA #IMPLIED
+         if_args        CDATA #IMPLIED>
 
 <!ELEMENT stageinfo      (root?, user?, environment?, base?)>
 
diff -Naur nALFS-SVN.orig/src/handlers/package.c 
nALFS-SVN/src/handlers/package.c
--- nALFS-SVN.orig/src/handlers/package.c       2005-03-07 22:17:29.000000000 
+0100
+++ nALFS-SVN/src/handlers/package.c    2007-04-04 20:43:51.000000000 +0200
@@ -247,7 +247,12 @@
        }
 
        if (status == 0) {
-               status = execute_children(el);
+               if (evaluate_condition(el) == 0) {
+                       status = execute_children(el);
+               } else {
+                       el->run_status = RUN_STATUS_SKIPPED;
+               }
+               
        }
 
        log_end_time(el, status);
diff -Naur nALFS-SVN.orig/src/handlers/stage.c nALFS-SVN/src/handlers/stage.c
--- nALFS-SVN.orig/src/handlers/stage.c 2004-07-04 07:51:11.000000000 +0200
+++ nALFS-SVN/src/handlers/stage.c      2007-04-04 21:48:29.000000000 +0200
@@ -386,10 +386,15 @@
 
        log_start_time(el);
 
-       if ((stageinfo = first_param("stageinfo", el))) {
-               status = parse_stageinfo_and_execute_children(el, stageinfo);
+       if (evaluate_condition(el) ==0) {
+               if ((stageinfo = first_param("stageinfo", el))) {
+                       status = parse_stageinfo_and_execute_children(el, 
stageinfo);
+               } else {
+                       status = execute_children(el);
+               }
        } else {
-               status = execute_children(el);
+               el->run_status = RUN_STATUS_SKIPPED;
+               status = 0;
        }
 
        log_end_time(el, status);
diff -Naur nALFS-SVN.orig/src/handlers.c nALFS-SVN/src/handlers.c
--- nALFS-SVN.orig/src/handlers.c       2003-11-03 22:45:06.000000000 +0100
+++ nALFS-SVN/src/handlers.c    2007-04-04 20:44:12.000000000 +0200
@@ -50,6 +50,24 @@
 
 static char **parameters;
 
+int evaluate_condition (element_s *el)
+{
+       char *if_command;
+       int condition = 0;
+       if (if_command=attr_value("if_command", el)) {
+               char *if_args;
+       
+               if (if_args = attr_value("if_args", el)) {
+                       append_str (&if_command, " ");
+                       append_str (&if_command, if_args);
+                       xfree (if_args);
+               }
+               condition = execute_command("%s", if_command);
+               Nprint_warn ("Conditionnal command: %s has result %d", 
if_command, condition);
+               xfree (if_command);
+       }
+       return condition;
+}
 
 /*
  * Returns a pointer to handler_s if element (name/version) has a handler,
@@ -446,7 +463,7 @@
                        if (*string) {
                                append_str(string, " ");
                        }
-                       append_str(string, content);
+                       if (!evaluate_condition(tmp)) append_str(string, 
content);
 
                        xfree(content);
 
diff -Naur nALFS-SVN.orig/src/handlers.h nALFS-SVN/src/handlers.h
--- nALFS-SVN.orig/src/handlers.h       2003-10-28 02:18:57.000000000 +0100
+++ nALFS-SVN/src/handlers.h    2007-04-04 20:36:32.000000000 +0200
@@ -91,6 +91,7 @@
 void check_options(int total, int *opts, const char *string_, element_s *el);
 char *append_param_elements(char **string, element_s *el);
 char *append_prefix_elements(char **string, element_s *el);
+int  evaluate_condition (element_s *el);
 
 
 #endif /* H_HANDLER_ */
diff -Naur nALFS-SVN.orig/src/nalfs.c nALFS-SVN/src/nalfs.c
--- nALFS-SVN.orig/src/nalfs.c  2005-04-11 21:40:08.000000000 +0200
+++ nALFS-SVN/src/nalfs.c       2007-04-04 21:59:23.000000000 +0200
@@ -317,6 +317,9 @@
                case RUN_STATUS_RUNNING:
                        mark = '>';
                        break;
+               case RUN_STATUS_SKIPPED:
+                        mark = '<';
+                       break;
        }
 
        return mark;
@@ -339,10 +342,12 @@
                case RUN_STATUS_DONE:
                        pair = COLP_STATUS_DONE;
                        break;
+               case RUN_STATUS_SKIPPED:
+                        pair = COLP_STATUS_SKIPPED;
+                        break;
                case RUN_STATUS_NONE:
                        return;
        }
-
        Xmvwaddch(windows.main->name, csr, strlen(*opt_cursor) + 3,
                status_to_mark(status));
 
@@ -393,8 +398,9 @@
 {
        run_status_e status;
 
-
-       if (! el->children) {
+       if (el->run_status == RUN_STATUS_SKIPPED) {
+               status = RUN_STATUS_SKIPPED;
+       } else if (! el->children) {
                status = RUN_STATUS_DONE;
 
        } else if (has_child_with_run_status(el, RUN_STATUS_RUNNING)) {
@@ -404,17 +410,18 @@
                status = RUN_STATUS_FAILED;
 
        } else if (! has_child_with_run_status(el, RUN_STATUS_NONE)
-       && ! has_child_with_run_status(el, RUN_STATUS_SOME_DONE)) {
+       && ! has_child_with_run_status(el, RUN_STATUS_SOME_DONE) 
+       && ! has_child_with_run_status(el, RUN_STATUS_SKIPPED)) {
                status = RUN_STATUS_DONE;
 
        } else if (has_child_with_run_status(el, RUN_STATUS_DONE)
-       || has_child_with_run_status(el, RUN_STATUS_SOME_DONE)) {
+       || has_child_with_run_status(el, RUN_STATUS_SOME_DONE)
+       || has_child_with_run_status(el, RUN_STATUS_SKIPPED)) {
                status = RUN_STATUS_SOME_DONE;
 
        } else {
                status = RUN_STATUS_NONE;
        }
-
        return status;
 }
 
@@ -864,6 +871,7 @@
 static int handle_ctrl_msg(void)
 {
        ctrl_msg_s *message;
+       element_s *current_ended;
 
 
        if ((message = comm_read_ctrl_message(FRONTEND_CTRL_SOCK)) != NULL) {
@@ -920,7 +930,6 @@
 {
        element_s *child;
 
-
        el->should_run = 0;
 
        for (child = el->children; child; child = child->next) {
@@ -2861,6 +2873,9 @@
                case RUN_STATUS_RUNNING:
                        Xwaddstr(windows.main->name, "Running\n");
                        break;
+               case RUN_STATUS_SKIPPED:
+                       Xwaddstr(windows.main->name, "Skipped\n");
+                       break;
        }
 
        Xwprintw(windows.main->name, "Should run    : %s\n",
@@ -3085,7 +3100,9 @@
        element_s *child;
 
 
-       if (el->run_status == RUN_STATUS_DONE || ! Can_run(el)) {
+       if (el->run_status == RUN_STATUS_DONE 
+               || el->run_status == RUN_STATUS_SKIPPED
+               || ! Can_run(el)) {
                return;
        }
 
diff -Naur nALFS-SVN.orig/src/parser.h nALFS-SVN/src/parser.h
--- nALFS-SVN.orig/src/parser.h 2003-10-24 00:02:56.000000000 +0200
+++ nALFS-SVN/src/parser.h      2007-04-03 22:14:53.000000000 +0200
@@ -41,7 +41,8 @@
        RUN_STATUS_RUNNING,
        RUN_STATUS_SOME_DONE,
        RUN_STATUS_DONE,
-       RUN_STATUS_NONE
+       RUN_STATUS_NONE,
+       RUN_STATUS_SKIPPED
 } run_status_e;
 
 typedef enum el_type_e {
diff -Naur nALFS-SVN.orig/src/win.h nALFS-SVN/src/win.h
--- nALFS-SVN.orig/src/win.h    2003-11-06 23:28:22.000000000 +0100
+++ nALFS-SVN/src/win.h 2007-04-04 02:02:37.000000000 +0200
@@ -50,6 +50,7 @@
 #define COLP_STATUS_RUNNING    COLP_CYAN
 #define COLP_STATUS_SOME_DONE  COLP_GREEN
 #define COLP_STATUS_DONE       COLP_GREEN
+#define COLP_STATUS_SKIPPED    COLP_RED
 
 /* Colors. */
 #define COL_CYAN       (COLOR_PAIR(COLP_CYAN))
-- 
http://linuxfromscratch.org/mailman/listinfo/alfs-discuss
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to