[GRASS-SVN] r57969 - in grass/trunk: lib/python/script lib/python/temporal scripts/r.unpack scripts/v.unpack
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 9 19:45:16 PDT 2013
Author: annakrat
Date: 2013-10-09 19:45:16 -0700 (Wed, 09 Oct 2013)
New Revision: 57969
Modified:
grass/trunk/lib/python/script/core.py
grass/trunk/lib/python/temporal/stds_import.py
grass/trunk/scripts/r.unpack/r.unpack.py
grass/trunk/scripts/v.unpack/v.unpack.py
Log:
unpacking maps: show projection file difference
Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py 2013-10-09 19:10:50 UTC (rev 57968)
+++ grass/trunk/lib/python/script/core.py 2013-10-10 02:45:16 UTC (rev 57969)
@@ -866,6 +866,23 @@
'a': len(dict_a)})
return True
+def diff_files(filename_a, filename_b):
+ """!Diffs two text files and returns difference.
+
+ @param filename_a first file path
+ @param filename_b second file path
+
+ @return list of strings
+ """
+ import difflib
+ differ = difflib.Differ()
+ fh_a = open(filename_a, 'r')
+ fh_b = open(filename_b, 'r')
+ result = list(differ.compare(fh_a.readlines(),
+ fh_b.readlines()))
+ return result
+
+
# interface to g.gisenv
Modified: grass/trunk/lib/python/temporal/stds_import.py
===================================================================
--- grass/trunk/lib/python/temporal/stds_import.py 2013-10-09 19:10:50 UTC (rev 57968)
+++ grass/trunk/lib/python/temporal/stds_import.py 2013-10-10 02:45:16 UTC (rev 57969)
@@ -230,6 +230,9 @@
core.warning(_("Projection information does not match. "
"Proceeding..."))
else:
+ diff = ''.join(core.diff_files(temp_name, proj_name))
+ core.warning(_("Difference between PROJ_INFO file of imported map "
+ "and of current location:\n{diff}").format(diff=diff))
core.fatal(_("Projection information does not match. Aborting."))
# Create a new location based on the projection information and switch
Modified: grass/trunk/scripts/r.unpack/r.unpack.py
===================================================================
--- grass/trunk/scripts/r.unpack/r.unpack.py 2013-10-09 19:10:50 UTC (rev 57968)
+++ grass/trunk/scripts/r.unpack/r.unpack.py 2013-10-10 02:45:16 UTC (rev 57969)
@@ -88,11 +88,27 @@
os.chdir(data_name)
# check projection compatibility in a rather crappy way
- if not grass.compare_key_value_text_files('PROJ_INFO', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')) or \
- not grass.compare_key_value_text_files('PROJ_UNITS', os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')):
+ diff_result_1 = diff_result_2 = None
+ proj_info_file_1 = 'PROJ_INFO'
+ proj_info_file_2 = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')
+ if not grass.compare_key_value_text_files(proj_info_file_1, proj_info_file_2):
+ diff_result_1 = grass.diff_files(proj_info_file_1, proj_info_file_2)
+
+ proj_units_file_1 = 'PROJ_UNITS'
+ proj_units_file_2 = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')
+ if not grass.compare_key_value_text_files(proj_units_file_1, proj_units_file_2):
+ diff_result_2 = grass.diff_files(proj_units_file_1, proj_units_file_2)
+
+ if diff_result_1 or diff_result_2:
if flags['o']:
grass.warning(_("Projection information does not match. Proceeding..."))
else:
+ if diff_result_1:
+ grass.warning(_("Difference between PROJ_INFO file of packed map "
+ "and of current location:\n{diff}").format(diff=''.join(diff_result_1)))
+ if diff_result_2:
+ grass.warning(_("Difference between PROJ_UNITS file of packed map "
+ "and of current location:\n{diff}").format(diff=''.join(diff_result_2)))
grass.fatal(_("Projection information does not match. Aborting."))
# install in $MAPSET
Modified: grass/trunk/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/trunk/scripts/v.unpack/v.unpack.py 2013-10-09 19:10:50 UTC (rev 57968)
+++ grass/trunk/scripts/v.unpack/v.unpack.py 2013-10-10 02:45:16 UTC (rev 57969)
@@ -98,13 +98,26 @@
# check projection compatibility in a rather crappy way
loc_proj = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_INFO')
loc_proj_units = os.path.join(mset_dir, '..', 'PERMANENT', 'PROJ_UNITS')
- if not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_INFO'), loc_proj) or \
- not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_UNITS'), loc_proj_units):
+
+ diff_result_1 = diff_result_2 = None
+ if not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_INFO'), loc_proj):
+ diff_result_1 = grass.diff_files(os.path.join(tmp_dir,'PROJ_INFO'), loc_proj)
+
+ if not grass.compare_key_value_text_files(os.path.join(tmp_dir,'PROJ_UNITS'), loc_proj_units):
+ diff_result_2 = grass.diff_files(os.path.join(tmp_dir,'PROJ_UNITS'), loc_proj_units)
+
+ if diff_result_1 or diff_result_2:
if flags['o']:
grass.warning(_("Projection information does not match. Proceeding..."))
else:
+ if diff_result_1:
+ grass.warning(_("Difference between PROJ_INFO file of packed map "
+ "and of current location:\n{diff}").format(diff=''.join(diff_result_1)))
+ if diff_result_2:
+ grass.warning(_("Difference between PROJ_UNITS file of packed map "
+ "and of current location:\n{diff}").format(diff=''.join(diff_result_2)))
grass.fatal(_("Projection information does not match. Aborting."))
-
+
# new db
fromdb = os.path.join(tmp_dir, 'db.sqlite')
# copy file
More information about the grass-commit
mailing list