gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master bba795d 2/2: Query: log file (in case of error


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master bba795d 2/2: Query: log file (in case of error) is saved in output directory
Date: Thu, 14 Jan 2021 19:31:42 -0500 (EST)

branch: master
commit bba795dbe92284a67d2d3c00e92fb3d043b15434
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Query: log file (in case of error) is saved in output directory
    
    Until now, when the download didn't succeed for any reason, the log-file
    (containing the cause of the error from the server) would be written in the
    running directory, even when the user requested the output to be written in
    another directory.
    
    But this is not good because the 'log' file is also an output and when the
    user asks to build the output in a certain directory, the log file should
    also be built there. This also applied to the temporarily downloaded file!
    But this is very bad, because if it is a large file, this can be
    problematic.
    
    With this commit, this issue has been fixed and the temporarily downloaded
    file (and also the log file if there was an error) is stored in the output
    file.
    
    In the process a few other issues have been fixed:
    
     - In Query, when the '--quiet' option is given, the '-s' option (for
       silent) is also given to 'curl' so nothing is printed.
    
     - The option-parsing functions didn't have a check in case the value was
       an empty string (for example when the value is a shell variable that is
       empty). So such a check has been added.
---
 bin/query/query.c |  3 +++
 bin/query/tap.c   | 12 ++++++++----
 bin/query/ui.c    |  9 +++++++--
 lib/options.c     | 25 +++++++++++++++++++++++++
 4 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/bin/query/query.c b/bin/query/query.c
index ead149c..112d402 100644
--- a/bin/query/query.c
+++ b/bin/query/query.c
@@ -86,6 +86,7 @@ query_check_download(struct queryparams *p)
       /* Rename the output file to the logname file and let the user
          know. */
       rename(p->downloadname, logname);
+      if(p->cp.quiet==0) printf("\n");
       error(EXIT_FAILURE, 0, "the requested dataset could not be retrieved! "
             "For more, please see '%s'", logname);
     }
@@ -131,6 +132,8 @@ query(struct queryparams *p)
       if(p->keeprawdownload)
         printf("Query's raw downloaded file: %s\n", p->downloadname);
       printf("Query's final output: %s\n", p->cp.output);
+      printf("TIP: use the command below for column information:\n"
+             "   asttable %s --info\n", p->cp.output);
     }
 
   /* Clean up. */
diff --git a/bin/query/tap.c b/bin/query/tap.c
index 90e952c..e46e99a 100644
--- a/bin/query/tap.c
+++ b/bin/query/tap.c
@@ -164,16 +164,20 @@ tap_download(struct queryparams *p)
          'queryst', we finish the single quotes and switch to double quotes
          because we need the single quotes around 'IRCS'. So here, while we
          started it with a single quote, we finish with double quotes. */
-      if( asprintf(&command, "curl -o%s --form LANG=ADQL "
+      if( asprintf(&command, "curl%s -o%s --form LANG=ADQL "
                    "--form FORMAT=fits --form REQUEST=doQuery "
-                   "--form QUERY='%s\" %s", p->downloadname, querystr,
-                   url->v)<0 )
+                   "--form QUERY='%s\" %s", p->cp.quiet ? " -s" : "",
+                   p->downloadname, querystr, url->v)<0 )
         error(EXIT_FAILURE, 0, "%s: asprintf allocation ('command')",
               __func__);
 
       /* Print the calling command for the user to know. */
       if(p->cp.quiet==0)
-        error(EXIT_SUCCESS, 0, "running: %s", command);
+        {
+          printf("\n");
+          error(EXIT_SUCCESS, 0, "running: %s", command);
+          printf("\nDownload status:\n");
+        }
 
       /* Run the command: if it succeeds ('system' returns zero), then stop
          parsing with a break. If it fails, then see if this is the last
diff --git a/bin/query/ui.c b/bin/query/ui.c
index 97b23bf..82a431c 100644
--- a/bin/query/ui.c
+++ b/bin/query/ui.c
@@ -125,7 +125,6 @@ ui_initialize_options(struct queryparams *p,
         case GAL_OPTIONS_KEY_NUMTHREADS:
         case GAL_OPTIONS_KEY_MINMAPSIZE:
         case GAL_OPTIONS_KEY_STDINTIMEOUT:
-        case GAL_OPTIONS_KEY_KEEPINPUTDIR:
           cp->coptions[i].flags=OPTION_HIDDEN;
           break;
         }
@@ -252,6 +251,7 @@ ui_read_check_only_options(struct queryparams *p)
   size_t i;
   char *basename;
   gal_data_t *tmp;
+  int keepinputdir;
 
   /* See if database has been specified. */
   if(p->databasestr==NULL)
@@ -346,10 +346,15 @@ ui_read_check_only_options(struct queryparams *p)
     }
 
   /* Make sure the output name doesn't exist (and report an error if
-     '--dontdelete' is called. */
+     '--dontdelete' is called. Just note that for the automatic output, we
+     are basing that on the output, not the input. So we are temporarily
+     activating 'keepinputdir'. */
+  keepinputdir=p->cp.keepinputdir;
+  p->cp.keepinputdir=1;
   gal_checkset_writable_remove(p->cp.output, 0, p->cp.dontdelete);
   p->downloadname=gal_checkset_automatic_output(&p->cp, p->cp.output,
                                                 "-raw-download.fits");
+  p->cp.keepinputdir=keepinputdir;
 }
 
 
diff --git a/lib/options.c b/lib/options.c
index 82e8f3f..fe7f40d 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -898,6 +898,11 @@ gal_options_parse_csv_strings(struct argp_option *option, 
char *arg,
       /* If the option is already set, just return. */
       if(option->set) return NULL;
 
+      /* Make sure an argument is actually given. */
+      if(*arg=='\0')
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "no value "
+                      "given to '--%s'", option->name);
+
       /* Read the values. */
       values=gal_options_parse_csv_strings_raw(arg, filename, lineno);
 
@@ -960,6 +965,11 @@ gal_options_parse_sizes_reverse(struct argp_option 
*option, char *arg,
       /* If the option is already set, just return. */
       if(option->set) return NULL;
 
+      /* Make sure an argument is actually given. */
+      if(*arg=='\0')
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "no value "
+                      "given to '--%s'", option->name);
+
       /* Read the values. */
       values=gal_options_parse_list_of_numbers(arg, filename, lineno);
 
@@ -1042,6 +1052,11 @@ gal_options_parse_csv_float64(struct argp_option 
*option, char *arg,
       /* If the option is already set, just return. */
       if(option->set) return NULL;
 
+      /* Make sure an argument is actually given. */
+      if(*arg=='\0')
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "no value "
+                      "given to '--%s'", option->name);
+
       /* Read the values. */
       values=gal_options_parse_list_of_numbers(arg, filename, lineno);
 
@@ -1183,6 +1198,11 @@ gal_options_parse_name_and_values(struct argp_option 
*option, char *arg,
     }
   else
     {
+      /* Make sure an argument is actually given. */
+      if(*arg=='\0')
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "no value "
+                      "given to '--%s'", option->name);
+
       /* Parse until the comma or the end of the string.*/
       c=arg; while(*c!='\0' && *c!=',') ++c;
       values = (*c=='\0') ? NULL : c+1;
@@ -1399,6 +1419,11 @@ gal_options_parse_colon_sep_csv(struct argp_option 
*option, char *arg,
     }
   else
     {
+      /* Make sure an argument is actually given. */
+      if(*arg=='\0')
+        error_at_line(EXIT_FAILURE, 0, filename, lineno, "no value "
+                      "given to '--%s'", option->name);
+
       /* Parse the desired format and put it in this option's pointer. */
       dataset=options_parse_colon_sep_csv(arg, filename, lineno);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]