[postgis-tickets] [SCM] PostGIS branch master updated. 9f22d34b5a0c6a697d4e4aa303642ff5bd450019

git at osgeo.org git at osgeo.org
Tue Jan 7 03:21:03 PST 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  9f22d34b5a0c6a697d4e4aa303642ff5bd450019 (commit)
      from  694937a19831c83bc947b5a89e519b8453be819c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9f22d34b5a0c6a697d4e4aa303642ff5bd450019
Author: Kristian Thy <thy at 42.dk>
Date:   Fri Jan 3 09:18:34 2020 +0100

    pgsql2shp: Add -q toggle for quiet mode
    
    Closes #2972
    Closes https://github.com/postgis/postgis/pull/527
    
    Signed-off-by: Raúl Marín <git at rmr.ninja>

diff --git a/NEWS b/NEWS
index 83f083f..a7ab9ba 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ PostGIS 3.1.0
 
 * New features *
   - #4601, Add ST_TileEnvelope margin argument (Yuri Astrakhan)
+  - #2972, Add quiet mode (-q) to pgsql2shp (Kristian Thy)
 
 * Enhancements *
   - #4539, Unify libm includes (Raúl Marín)
diff --git a/loader/pgsql2shp-cli.c b/loader/pgsql2shp-cli.c
index 803f0c2..6fa975f 100644
--- a/loader/pgsql2shp-cli.c
+++ b/loader/pgsql2shp-cli.c
@@ -25,7 +25,7 @@
 static void
 usage(int status)
 {
-  /* TODO: if status != 0 print all to stderr */
+	/* TODO: if status != 0 print all to stderr */
 
 	printf(_( "RELEASE: %s (%s)\n" ), POSTGIS_LIB_VERSION,
 		xstr(POSTGIS_REVISION));
@@ -50,6 +50,7 @@ usage(int status)
 	         "     leading space. For example:\n"
 	         "         COLUMNNAME DBFFIELD1\n"
 	         "         AVERYLONGCOLUMNNAME DBFFIELD2\n" ));
+	printf(_("  -q Quiet mode. No messages to stdout.\n" ));
 	printf(_("  -? Display this help screen.\n\n" ));
 	exit(status);
 }
@@ -72,7 +73,7 @@ main(int argc, char **argv)
 	config = malloc(sizeof(SHPDUMPERCONFIG));
 	set_dumper_config_defaults(config);
 
-	while ((c = pgis_getopt(argc, argv, "bf:h:du:p:P:g:rkm:")) != EOF)
+	while ((c = pgis_getopt(argc, argv, "bf:h:du:p:P:g:rkm:q")) != EOF)
 	{
 		switch (c)
 		{
@@ -110,6 +111,9 @@ main(int argc, char **argv)
 		case 'k':
 			config->keep_fieldname_case = 1;
 			break;
+		case 'q':
+			config->quiet = 1;
+			break;
 		default:
 			usage(pgis_optopt == '?' ? 0 : 1);
 		}
@@ -144,25 +148,25 @@ main(int argc, char **argv)
 			char *strptr = argv[pgis_optind];
 			char *chrptr = strchr(strptr, '.');
 
-				/* OK, this is a schema-qualified table name... */
-      if (chrptr)
-      {
-        if ( chrptr == strptr )
-        {
-          /* table is ".something" display help  */
-          usage(0);
-          exit(0);
-        }
-        /* Null terminate at the '.' */
-        *chrptr = '\0';
-        /* Copy in the parts */
-        config->schema = strdup(strptr);
-        config->table = strdup(chrptr+1);
-      }
-      else
-      {
-        config->table = strdup(strptr);
-      }
+			/* OK, this is a schema-qualified table name... */
+			if (chrptr)
+			{
+				if ( chrptr == strptr )
+				{
+					/* table is ".something" display help  */
+					usage(0);
+					exit(0);
+				}
+				/* Null terminate at the '.' */
+				*chrptr = '\0';
+				/* Copy in the parts */
+				config->schema = strdup(strptr);
+				config->table = strdup(chrptr+1);
+			}
+			else
+			{
+				config->table = strdup(strptr);
+			}
 		}
 	}
 	else
@@ -188,8 +192,11 @@ main(int argc, char **argv)
 	}
 
 	/* Open the table ready to return rows */
-	fprintf(stdout, _("Initializing... \n"));
-	fflush(stdout);
+	if (!state->config->quiet)
+	{
+		fprintf(stdout, _("Initializing... \n"));
+		fflush(stdout);
+	}
 
 	ret = ShpDumperOpenTable(state);
 	if (ret != SHPDUMPEROK)
@@ -201,15 +208,18 @@ main(int argc, char **argv)
 			exit(1);
 	}
 
-	fprintf(stdout, _("Done (postgis major version: %d).\n"), state->pgis_major_version);
-	fprintf(stdout, _("Output shape: %s\n"), shapetypename(state->outshptype));
-	fprintf(stdout, _("Dumping: "));
-	fflush(stdout);
+	if (!state->config->quiet)
+	{
+		fprintf(stdout, _("Done (postgis major version: %d).\n"), state->pgis_major_version);
+		fprintf(stdout, _("Output shape: %s\n"), shapetypename(state->outshptype));
+		fprintf(stdout, _("Dumping: "));
+		fflush(stdout);
+	}
 
 	for (i = 0; i < ShpDumperGetRecordCount(state); i++)
 	{
 		/* Mimic existing behaviour */
-		if (!(state->currow % state->config->fetchsize))
+		if (!state->config->quiet && !(state->currow % state->config->fetchsize))
 		{
 			fprintf(stdout, "X");
 			fflush(stdout);
@@ -226,8 +236,11 @@ main(int argc, char **argv)
 		}
 	}
 
-	fprintf(stdout, _(" [%d rows].\n"), ShpDumperGetRecordCount(state));
-	fflush(stdout);
+	if (!state->config->quiet)
+	{
+		fprintf(stdout, _(" [%d rows].\n"), ShpDumperGetRecordCount(state));
+		fflush(stdout);
+	}
 
 	ret = ShpDumperCloseTable(state);
 	if (ret != SHPDUMPEROK)
diff --git a/loader/pgsql2shp-core.c b/loader/pgsql2shp-core.c
index 168511d..1596dc2 100644
--- a/loader/pgsql2shp-core.c
+++ b/loader/pgsql2shp-core.c
@@ -832,16 +832,16 @@ projFileCreate(SHPDUMPERSTATE *state)
 				}
 				else
 				{
-				    result = fputs (srtext,fp);
-                    LWDEBUGF(3, "\n result %d proj SRText is %s .\n", result, srtext);
-                    if (result == EOF)
-                    {
-                        fclose( fp );
-                        free( pszFullname );
-                        PQclear(res);
-                        free(query);
-                        return 0;
-                    }
+					result = fputs (srtext,fp);
+					LWDEBUGF(3, "\n result %d proj SRText is %s .\n", result, srtext);
+					if (result == EOF)
+					{
+						fclose( fp );
+						free( pszFullname );
+						PQclear(res);
+						free(query);
+						return 0;
+					}
 				}
 				fclose( fp );
 				free( pszFullname );
@@ -883,14 +883,14 @@ getTableInfo(SHPDUMPERSTATE *state)
 			query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->schema) + strlen(state->table));
 
 			sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY 3",
-			state->geo_col_name, state->geo_col_name, state->schema, state->table);
+			        state->geo_col_name, state->geo_col_name, state->schema, state->table);
 		}
 		else
 		{
 			query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->table));
 
 			sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY 3",
-			state->geo_col_name, state->geo_col_name, state->table);
+			        state->geo_col_name, state->geo_col_name, state->table);
 		}
 	}
 	else
@@ -1144,6 +1144,7 @@ set_dumper_config_defaults(SHPDUMPERCONFIG *config)
 	config->keep_fieldname_case = 0;
 	config->fetchsize = 100;
 	config->column_map_filename = NULL;
+	config->quiet = 0;
 }
 
 /* Create a new shapefile state object */
@@ -1535,11 +1536,11 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
 		 * use this to create the dbf field name from
 		 * the PostgreSQL column name */
 		{
-		  const char *mapped = colmap_dbf_by_pg(&state->column_map, dbffieldname);
-		  if (mapped)
-		  {
-			  strncpy(dbffieldname, mapped, 10);
-			  dbffieldname[10] = '\0';
+			const char *mapped = colmap_dbf_by_pg(&state->column_map, dbffieldname);
+			if (mapped)
+			{
+				strncpy(dbffieldname, mapped, 10);
+				dbffieldname[10] = '\0';
 			}
 		}
 
@@ -1569,7 +1570,7 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
 		if (strcasecmp(dbffieldname, pgfieldname))
 		{
 			if ( snprintf(buf, 256, _("Warning, field %s renamed to %s\n"),
-							 pgfieldname, dbffieldname) >= 256 )
+			              pgfieldname, dbffieldname) >= 256 )
 			{
 				buf[255] = '\0';
 			}
@@ -1884,7 +1885,7 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
 		else
 		{
 			sprintf(buf, "asbinary(%s::geometry, 'XDR') AS _geoX",
-				quote_identifier(state->geo_col_name) );
+			        quote_identifier(state->geo_col_name) );
 		}
 #else
 		if (state->pgis_major_version > 0)
@@ -1894,7 +1895,7 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
 		else
 		{
 			sprintf(buf, "asbinary(%s::geometry, 'NDR') AS _geoX",
-				quote_identifier(state->geo_col_name) );
+			        quote_identifier(state->geo_col_name) );
 		}
 #endif
 
diff --git a/loader/pgsql2shp-core.h b/loader/pgsql2shp-core.h
index b26a288..6b26702 100644
--- a/loader/pgsql2shp-core.h
+++ b/loader/pgsql2shp-core.h
@@ -88,6 +88,9 @@ typedef struct shp_dumper_config
 	/* Name of the column map file if specified */
 	char *column_map_filename;
 
+	/* 0=normal output to stdout, 1=no output to stdout */
+	int quiet;
+
 } SHPDUMPERCONFIG;
 
 
@@ -182,7 +185,7 @@ typedef struct shp_dumper_state
 	char message[SHPDUMPERMSGLEN];
 
 	/* Column map */
-  colmap column_map;
+	colmap column_map;
 
 } SHPDUMPERSTATE;
 

-----------------------------------------------------------------------

Summary of changes:
 NEWS                    |  1 +
 loader/pgsql2shp-cli.c  | 73 +++++++++++++++++++++++++++++--------------------
 loader/pgsql2shp-core.c | 41 +++++++++++++--------------
 loader/pgsql2shp-core.h |  5 +++-
 4 files changed, 69 insertions(+), 51 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list