[GRASS-SVN] r56685 - grass/trunk/vector/v.colors

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 12 07:06:20 PDT 2013


Author: neteler
Date: 2013-06-12 07:06:20 -0700 (Wed, 12 Jun 2013)
New Revision: 56685

Modified:
   grass/trunk/vector/v.colors/thumbnails.py
Log:
thumbnails.py: convert tab to spaces

Modified: grass/trunk/vector/v.colors/thumbnails.py
===================================================================
--- grass/trunk/vector/v.colors/thumbnails.py	2013-06-12 08:16:27 UTC (rev 56684)
+++ grass/trunk/vector/v.colors/thumbnails.py	2013-06-12 14:06:20 UTC (rev 56685)
@@ -16,11 +16,11 @@
 
 def cleanup():
     if tmp_img:
-	grass.try_remove(tmp_img)
+        grass.try_remove(tmp_img)
     if tmp_grad_rel:
-	grass.run_command('g.remove', rast = tmp_grad_rel, quiet = True)
+        grass.run_command('g.remove', rast = tmp_grad_rel, quiet = True)
     if tmp_grad_abs:
-	grass.run_command('g.remove', rast = tmp_grad_abs, quiet = True)
+        grass.run_command('g.remove', rast = tmp_grad_abs, quiet = True)
 
 # def rotate(src, dst):
 #     grass.call(["convert", "-rotate", "90", src, dst])
@@ -32,17 +32,17 @@
     i = 0
     j = text.find('\n', i)
     if text[i:j] != 'P6':
-	raise IOError
+        raise IOError
     i = j + 1
     j = text.find('\n', i)
     w, h = text[i:j].split()
     if int(w) != width or int(h) != height:
-	raise IOError
+        raise IOError
     i = j + 1
     j = text.find('\n', i)
     maxval = text[i:j]
     if int(maxval) != 255:
-	raise IOError
+        raise IOError
     i = j + 1
     return array.array('B', text[i:])
 
@@ -57,35 +57,35 @@
 def rotate_ppm(srcd):
     dstd = array.array('B', len(srcd) * '\0')
     for y in xrange(height):
-	for x in xrange(width):
-	    for c in xrange(3):
-		dstd[(x * height + (height - 1 - y)) * 3 + c] = srcd[(y * width + x) * 3 + c]
+        for x in xrange(width):
+            for c in xrange(3):
+                dstd[(x * height + (height - 1 - y)) * 3 + c] = srcd[(y * width + x) * 3 + c]
     return dstd
 
 def flip_ppm(srcd):
     dstd = array.array('B', len(srcd) * '\0')
     stride = width * 3
     for y in xrange(height):
-	dy = (height - 1 - y)
-	dstd[dy * stride:(dy + 1) * stride] = srcd[y * stride:(y + 1) * stride]
+        dy = (height - 1 - y)
+        dstd[dy * stride:(dy + 1) * stride] = srcd[y * stride:(y + 1) * stride]
     return dstd
 
 def ppmtopng(dst, src):
     if grass.find_program("g.ppmtopng", ["help"]):
-	grass.run_command('g.ppmtopng', input = src, output = dst, quiet = True)
+        grass.run_command('g.ppmtopng', input = src, output = dst, quiet = True)
     elif grass.find_program("pnmtopng"):
-	fh = open(dst, 'wb')
-	grass.call(["pnmtopng", src], stdout = fh)
-	fh.close()
+        fh = open(dst, 'wb')
+        grass.call(["pnmtopng", src], stdout = fh)
+        fh.close()
     elif grass.find_program("convert"):
-	grass.call(["convert", src, dst])
+        grass.call(["convert", src, dst])
     else:
-	grass.fatal(_("Cannot find g.ppmtopng, pnmtopng or convert"))
+        grass.fatal(_("Cannot find g.ppmtopng, pnmtopng or convert"))
 
 def convert_and_rotate(src, dst, flip = False):
     ppm = read_ppm(src)
     if flip:
-	ppm = flip_ppm(ppm)
+        ppm = flip_ppm(ppm)
     ppm = rotate_ppm(ppm)
     write_ppm(tmp_img, ppm)
     ppmtopng(dst, tmp_img)
@@ -98,41 +98,41 @@
     lines = text.splitlines()
     records = list()
     for line in lines:
-	if line.startswith("#"):
-	    # skip comments
-	    continue
-	records.append(line.split())
+        if line.startswith("#"):
+            # skip comments
+            continue
+        records.append(line.split())
     records = [record for record in records if record[0] != 'nv']
     relative = False
     absolute = False
     for record in records:
-	if record[0].endswith("%"):
-	    relative = True
-	    record[0] = record[0].rstrip("%")
-	else:
-	    absolute = True
+        if record[0].endswith("%"):
+            relative = True
+            record[0] = record[0].rstrip("%")
+        else:
+            absolute = True
 
     if absolute:
-	if relative:
-	    minval = -0.04
-	    maxval = 0.04
-	else:
-	    minval = float(records[0][0])
-	    maxval = float(records[-1][0])
-	    maxval = min(maxval, 2500000)
-	grad = tmp_grad_abs
-	grass.mapcalc("$grad = if(row()==1, float($min), float($max))",
-		      grad = tmp_grad_abs, min = minval, max = maxval, quiet = True)
+        if relative:
+            minval = -0.04
+            maxval = 0.04
+        else:
+            minval = float(records[0][0])
+            maxval = float(records[-1][0])
+            maxval = min(maxval, 2500000)
+        grad = tmp_grad_abs
+        grass.mapcalc("$grad = if(row()==1, float($min), float($max))",
+                      grad = tmp_grad_abs, min = minval, max = maxval, quiet = True)
     else:
-	grad = tmp_grad_rel
+        grad = tmp_grad_rel
 
     return grad
 
 def make_image(output_dir, table, grad, discrete = False):
     if discrete:
-	lines, cols = height, 1
+        lines, cols = height, 1
     else:
-	lines, cols = None, None
+        lines, cols = None, None
     grass.run_command("r.colors", map = grad, color = table, quiet = True)
     grass.run_command("d.colortable", flags = 'n', map = grad, lines = lines, cols = cols, quiet = True)
     outfile = os.path.join(output_dir, "Colortable_%s.png" % table)
@@ -147,7 +147,7 @@
     output_dir = os.path.join(os.environ['GISBASE'], "docs", "html")
 
     if not os.path.exists(output_dir):
-	os.makedirs(output_dir)
+        os.makedirs(output_dir)
 
     pid = os.getpid()
     tmp_grad_abs = "tmp_grad_abs_%d" % pid
@@ -166,8 +166,8 @@
     os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
 
     for var in ['GRASS_LINE_WIDTH', 'GRASS_ANTIALIAS']:
-	if var in os.environ:
-	    del os.environ[var]
+        if var in os.environ:
+            del os.environ[var]
 
     grass.use_temp_region()
     grass.run_command('g.region', rows = 100, cols = 100)
@@ -175,13 +175,13 @@
     grass.mapcalc("$grad = row()/1.0", grad = tmp_grad_rel, quiet = True)
     
     for table in os.listdir(color_dir):
-	path = os.path.join(color_dir, table)
-	grad = make_gradient(path)
-	make_image(output_dir, table, grad)
+        path = os.path.join(color_dir, table)
+        grad = make_gradient(path)
+        make_image(output_dir, table, grad)
     
     grass.mapcalc("$grad = row()", grad = tmp_grad_abs, quiet = True)
     for table in ['grey.eq', 'grey.log', 'random']:
-	make_image(output_dir, table, tmp_grad_abs, True)
+        make_image(output_dir, table, tmp_grad_abs, True)
  
 if __name__ == "__main__":
     atexit.register(cleanup)



More information about the grass-commit mailing list