[Gnucash-changes] r12946 - gnucash/trunk/src - Process the --add-price-quotes command-line option from C.

Chris Shoemaker chris at cvs.gnucash.org
Sun Jan 22 22:26:02 EST 2006


Author: chris
Date: 2006-01-22 22:26:01 -0500 (Sun, 22 Jan 2006)
New Revision: 12946
Trac: http://svn.gnucash.org/trac/changeset/12946

Modified:
   gnucash/trunk/src/bin/gnucash-bin.c
   gnucash/trunk/src/scm/main.scm
   gnucash/trunk/src/scm/price-quotes.scm
Log:
  Process the --add-price-quotes command-line option from C.
  This is done by booting guile with a custom inner_main.
  Much of the work is still handled by price-quotes.scm, which
  is now a true stand-alone guile module without the circular dependency
  on the (gnucash main) module.

  One caveat:  Since the initialization of guile-side debugging variables 
  is in main.scm, and since main.scm is no longer executed when running
  --add-price-quotes, the guile code that runs during --add-price-quote
  isn't affected by the --debug option.  A work-around is to use the 
  GNC_DEBUG environment variable: 
    $ GNC_DEBUG=yes gnucash --add-price-quote myfile

  In the longer term, we'll either move the debugging aids to a common place
  where it can be used by both main.scm and price-quotes.scm, or we'll get
  the debugging state from the C-side via gwrap.
 


Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2006-01-23 03:12:27 UTC (rev 12945)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2006-01-23 03:26:01 UTC (rev 12946)
@@ -51,6 +51,7 @@
 #else
 static int is_development_version = FALSE;
 #endif
+static char *add_quotes_file;
 
 static void
 gnc_print_unstable_message(void)
@@ -218,8 +219,8 @@
          _("Set shared data file search path"), _("SHAREPATH")},
         {"doc-path", '\0', POPT_ARG_STRING, &help_path, 0,
          _("Set the search path for documentation files"), _("DOCPATH")},
-        {"add-price-quotes", '\0', POPT_ARG_STRING, NULL, 0,
-         _("Add price quotes to given FILE"), _("FILE")},
+        {"add-price-quotes", '\0', POPT_ARG_STRING, &add_quotes_file, 0,
+         _("Add price quotes to given GnuCash datafile"), _("FILE")},
         {"namespace", '\0', POPT_ARG_STRING, &namespace_regexp, 0, 
          _("Regular expression determining which namespace commodities will be retrieved"), 
          _("REGEXP")},
@@ -233,6 +234,7 @@
     poptSetOtherOptionHelp(pc, "[OPTIONS...] [datafile]");
     
     while ((rc = poptGetNextOpt(pc)) > 0);
+    poptFreeContext(pc);
 
     if (gnucash_show_version) {
         printf("GnuCash %s %s\n", VERSION, 
@@ -243,8 +245,6 @@
 
     if (namespace_regexp)
         gnc_main_set_namespace_regexp(namespace_regexp);
-    
-    poptFreeContext(pc);
 }
 
 static void
@@ -265,53 +265,85 @@
     }   
 }
 
-
 static void
-inner_main (void *closure, int argc, char **argv)
+load_gnucash_modules()
 {
-    SCM main_mod;
     int i, len;
     struct {
-      gchar * name;
-      int version;
-      gboolean optional;
+        gchar * name;
+        int version;
+        gboolean optional;
     } modules[] = {
-      { "gnucash/app-utils", 0, FALSE },
-      { "gnucash/engine", 0, FALSE },
-      { "gnucash/register/ledger-core", 0, FALSE },
-      { "gnucash/register/register-core", 0, FALSE },
-      { "gnucash/register/register-gnome", 0, FALSE },
-      { "gnucash/import-export/binary-import", 0, FALSE },
-      { "gnucash/import-export/qif-import", 0, FALSE },
-      { "gnucash/import-export/ofx", 0, TRUE },
-      { "gnucash/import-export/mt940", 0, TRUE },
-      { "gnucash/import-export/log-replay", 0, TRUE },
-      { "gnucash/import-export/hbci", 0, TRUE },
-      { "gnucash/report/report-system", 0, FALSE },
-      { "gnucash/report/stylesheets", 0, FALSE },
-      { "gnucash/report/standard-reports", 0, FALSE },
-      { "gnucash/report/utility-reports", 0, FALSE },
-      { "gnucash/report/locale-specific/us", 0, FALSE },
-      { "gnucash/report/report-gnome", 0, FALSE },
-      { "gnucash/business-gnome", 0, TRUE }
+        { "gnucash/app-utils", 0, FALSE },
+        { "gnucash/engine", 0, FALSE },
+        { "gnucash/register/ledger-core", 0, FALSE },
+        { "gnucash/register/register-core", 0, FALSE },
+        { "gnucash/register/register-gnome", 0, FALSE },
+        { "gnucash/import-export/binary-import", 0, FALSE },
+        { "gnucash/import-export/qif-import", 0, FALSE },
+        { "gnucash/import-export/ofx", 0, TRUE },
+        { "gnucash/import-export/mt940", 0, TRUE },
+        { "gnucash/import-export/log-replay", 0, TRUE },
+        { "gnucash/import-export/hbci", 0, TRUE },
+        { "gnucash/report/report-system", 0, FALSE },
+        { "gnucash/report/stylesheets", 0, FALSE },
+        { "gnucash/report/standard-reports", 0, FALSE },
+        { "gnucash/report/utility-reports", 0, FALSE },
+        { "gnucash/report/locale-specific/us", 0, FALSE },
+        { "gnucash/report/report-gnome", 0, FALSE },
+        { "gnucash/business-gnome", 0, TRUE }
     };
+    
+    /* module initializations go here */
+    len = sizeof(modules) / sizeof(*modules);
+    for (i = 0; i < len; i++) {
+        gnc_update_splash_screen(modules[i].name);
+        if (modules[i].optional)
+            gnc_module_load_optional(modules[i].name, modules[i].version);
+        else
+            gnc_module_load(modules[i].name, modules[i].version);
+    } 
+}
 
+static void
+inner_main_add_price_quotes(void *closure, int argc, char **argv)
+{
+    SCM mod, add_quotes, scm_filename, scm_result;
+    
+    mod = scm_c_resolve_module("gnucash price-quotes");
+    scm_set_current_module(mod);
+
+    load_gnucash_modules();
+
+    gnc_engine_suspend_events();
+    g_message("Beginning to install price-quote sources");
+    scm_c_eval_string("(gnc:price-quotes-install-sources)");
+
+    add_quotes = scm_c_eval_string("gnc:add-quotes-to-book-at-url");
+    scm_filename = scm_makfrom0str (add_quotes_file);
+    scm_result = scm_call_1(add_quotes, scm_filename);
+
+    if (!SCM_NFALSEP(scm_result)) {
+        g_error("Failed to add quotes to %s.", add_quotes_file);
+        shutdown(1);
+    }
+    gnc_engine_resume_events();
+    shutdown(0);
+    return;
+}
+
+static void
+inner_main (void *closure, int argc, char **argv)
+{
+    SCM main_mod;
+ 
     main_mod = scm_c_resolve_module("gnucash main");
     scm_set_current_module(main_mod);
 
     /* Can't show splash screen here unless we init gnome first */
     //gnc_show_splash_screen();
 
-    /* module initializations go here */
-    len = sizeof(modules) / sizeof(*modules);
-    for (i = 0; i < len; i++) {
-      gnc_update_splash_screen(modules[i].name);
-      if (modules[i].optional)
-	gnc_module_load_optional(modules[i].name, modules[i].version);
-      else
-	gnc_module_load(modules[i].name, modules[i].version);
-    }
-
+    load_gnucash_modules();
     load_system_config();
     load_user_config();
 
@@ -338,6 +370,10 @@
     gnc_print_unstable_message();
     gnc_gnome_init (argc, argv, VERSION);
 
+    if (add_quotes_file) {
+        scm_boot_guile(argc, argv, inner_main_add_price_quotes, 0);
+    }
+
     scm_boot_guile(argc, argv, inner_main, 0);
     exit(0); /* never reached */
 }

Modified: gnucash/trunk/src/scm/main.scm
===================================================================
--- gnucash/trunk/src/scm/main.scm	2006-01-23 03:12:27 UTC (rev 12945)
+++ gnucash/trunk/src/scm/main.scm	2006-01-23 03:26:01 UTC (rev 12946)
@@ -29,7 +29,7 @@
 (use-modules (srfi srfi-8))
 
 (use-modules (gnucash gnc-module))
-;;(use-modules (gnucash price-quotes))
+(use-modules (gnucash price-quotes))
 
 (use-modules (ice-9 slib))
 (require 'printf)
@@ -131,22 +131,6 @@
       (export simple-format)
       (define simple-format format)))
 
-(define gnc:use-guile-module-here!
-  ;; FIXME: this should be a temporary fix.  We need to check to see
-  ;; if there's a more approved way to do this.  As I recall, there's
-  ;; not, but I belive a better way will be added to Guile soon.
-
-  ;; module arg must be something like '(ice-9 slib)
-  (cond
-   ((or (string=? "1.3" (version))
-        (string=? "1.3.4" (version))
-	(string=? "1.4" (substring (version) 0 3)))
-    (lambda (module)
-      (process-use-modules (list module))))
-   (else
-    (lambda (module)
-      (process-use-modules (list (list module)))))))
-
 (define (gnc:safe-strcmp a b)
   (cond
    (if (and a b)
@@ -380,10 +364,7 @@
     (load-from-path "fin.scm")
 
     (gnc:update-splash-screen (_ "Checking Finance::Quote..."))
-    (gnc:use-guile-module-here! '(gnucash price-quotes))
-    (let ((sources (gnc:fq-check-sources)))
-      (if (list? sources)
-	  (gnc:quote-source-set-fq-installed sources)))
+    (gnc:price-quotes-install-sources)
 
     (set-current-module original-module))
 

Modified: gnucash/trunk/src/scm/price-quotes.scm
===================================================================
--- gnucash/trunk/src/scm/price-quotes.scm	2006-01-23 03:12:27 UTC (rev 12945)
+++ gnucash/trunk/src/scm/price-quotes.scm	2006-01-23 03:26:01 UTC (rev 12946)
@@ -23,9 +23,10 @@
 (define-module (gnucash price-quotes))
 
 (export yahoo-get-historical-quotes)
-(export gnc:fq-check-sources) ;; called in main.scm
+;;(export gnc:fq-check-sources) ;; called in main.scm
 (export gnc:book-add-quotes) ;; called from gnome/dialog-price-edit-db.c
 (export gnc:add-quotes-to-book-at-url) ;; called in command-line.scm
+(export gnc:price-quotes-install-sources)
 
 (use-modules (gnucash process))
 (use-modules (www main))
@@ -711,19 +712,23 @@
 (define (gnc:add-quotes-to-book-at-url url)
   (let* ((session (gnc:url->loaded-session url #f #f))
          (quote-ok? #f))
+    (gnc:debug "in add-quotes-to-book-at-url")
     (if session
 	(begin
+          (gnc:debug "about to call gnc:book-add-quotes")
 	  (set! quote-ok? (and (gnc:book-add-quotes
 				(gnc:session-get-book session))))
 
-	  (if (not quote-ok?) (gnc:msg "book-add-quotes failed"))
+          (gnc:debug "done gnc:book-add-quotes:" quote-ok?)
+	  (if (not quote-ok?) (gnc:error "book-add-quotes failed"))
 	  (gnc:session-save session)
 	  (if (not (eq? 'no-err
 			(gw:enum-<gnc:BackendError>-val->sym
 			 (gnc:session-get-error session) #f)))
 	      (set! quote-ok? #f))
 	  (if (not quote-ok?)
-	      (gnc:msg "session-save failed " (gnc:session-get-error session)))
+	      (gnc:error "session-save failed " 
+                         (gnc:session-get-error session)))
 	  (gnc:session-destroy session))
 	(gnc:error "book-add-quotes unable to open file"))
     quote-ok?))
@@ -741,3 +746,8 @@
 ; 	   (close-input-port (cadr quoter))
 ; 	   (close-output-port (caddr quoter))
 ; 	   result))))
+
+(define (gnc:price-quotes-install-sources)
+  (let ((sources (gnc:fq-check-sources)))
+    (if (list? sources)
+        (gnc:quote-source-set-fq-installed sources))))



More information about the gnucash-changes mailing list