[GRASS-SVN] r56888 - in grass/trunk/lib/python/pygrass: . shell
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 23 12:13:27 PDT 2013
Author: zarch
Date: 2013-06-23 12:13:27 -0700 (Sun, 23 Jun 2013)
New Revision: 56888
Added:
grass/trunk/lib/python/pygrass/shell/
grass/trunk/lib/python/pygrass/shell/Makefile
grass/trunk/lib/python/pygrass/shell/__init__.py
grass/trunk/lib/python/pygrass/shell/conversion.py
grass/trunk/lib/python/pygrass/shell/show.py
Modified:
grass/trunk/lib/python/pygrass/Makefile
grass/trunk/lib/python/pygrass/__init__.py
Log:
Add support for ipython notebook.
Modified: grass/trunk/lib/python/pygrass/Makefile
===================================================================
--- grass/trunk/lib/python/pygrass/Makefile 2013-06-23 19:08:13 UTC (rev 56887)
+++ grass/trunk/lib/python/pygrass/Makefile 2013-06-23 19:13:27 UTC (rev 56888)
@@ -10,7 +10,7 @@
MODULES = errors functions orderdict
-CLEAN_SUBDIRS = modules raster vector gis tests
+CLEAN_SUBDIRS = modules raster vector gis shell tests
PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
@@ -20,6 +20,7 @@
-$(MAKE) -C raster || echo $(CURDIR)/raster >> $(ERRORLOG)
-$(MAKE) -C vector || echo $(CURDIR)/vector >> $(ERRORLOG)
-$(MAKE) -C gis || echo $(CURDIR)/gis >> $(ERRORLOG)
+ -$(MAKE) -C shell || echo $(CURDIR)/shell >> $(ERRORLOG)
-$(MAKE) -C tests || echo $(CURDIR)/tests >> $(ERRORLOG)
$(PYDIR):
Modified: grass/trunk/lib/python/pygrass/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/__init__.py 2013-06-23 19:08:13 UTC (rev 56887)
+++ grass/trunk/lib/python/pygrass/__init__.py 2013-06-23 19:13:27 UTC (rev 56888)
@@ -15,3 +15,4 @@
import raster
import vector
import modules
+import shell
Added: grass/trunk/lib/python/pygrass/shell/Makefile
===================================================================
--- grass/trunk/lib/python/pygrass/shell/Makefile (rev 0)
+++ grass/trunk/lib/python/pygrass/shell/Makefile 2013-06-23 19:13:27 UTC (rev 56888)
@@ -0,0 +1,32 @@
+MODULE_TOPDIR = ../../../..
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+include $(MODULE_TOPDIR)/include/Make/Python.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+PYDIR = $(ETC)/python
+GDIR = $(PYDIR)/grass
+PGDIR = $(GDIR)/pygrass
+DSTDIR= $(PGDIR)/shell
+
+MODULES = conversion show
+
+PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
+PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
+
+default: $(PYFILES) $(PYCFILES) $(GDIR)/__init__.py $(GDIR)/__init__.pyc
+
+$(PYDIR):
+ $(MKDIR) $@
+
+$(GDIR): | $(PYDIR)
+ $(MKDIR) $@
+
+$(DSTDIR): | $(GDIR)
+ $(MKDIR) $@
+
+$(DSTDIR)/%: % | $(DSTDIR)
+ $(INSTALL_DATA) $< $@
+
+#doxygen:
+DOXNAME = pythonpygrass
Added: grass/trunk/lib/python/pygrass/shell/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/shell/__init__.py (rev 0)
+++ grass/trunk/lib/python/pygrass/shell/__init__.py 2013-06-23 19:13:27 UTC (rev 56888)
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sun Jun 23 15:06:46 2013
+
+ at author: pietro
+"""
+
+import conversion
Added: grass/trunk/lib/python/pygrass/shell/conversion.py
===================================================================
--- grass/trunk/lib/python/pygrass/shell/conversion.py (rev 0)
+++ grass/trunk/lib/python/pygrass/shell/conversion.py 2013-06-23 19:13:27 UTC (rev 56888)
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sun Jun 23 13:40:19 2013
+
+ at author: pietro
+"""
+
+
+dcont = """ <tr>
+ <td>{key}</td>
+ <td>{value}</td>
+ </tr>"""
+
+
+def dict2html(dic, keys=None, border='',
+ kfmt='%s', kdec='', kfun=None,
+ vfmt='%s', vdec='', vfun=None):
+ """Return a html repr of a dictionary.
+
+ Parameters
+ -----------
+
+ dic: dictionary, required
+ Dictionary or object with `keys` and `items` methods
+ keys: iterable, optional
+ Iterable objectwith only the keys that we want to display
+ border: string, optional
+ Could be: "0", "1", etc.
+ kfmt: string, optional
+ String to format the key string (i.e. "%r", etc.)
+ kdec: string, optional
+ String to decorate the key (i.e. "b", "i", etc.)
+ vfmt: string, optional
+ String to format the value string (i.e. "%r", etc.)
+ vdec: string, optional
+ String to decorate the value (i.e. "b", "i", etc.)
+
+ Examples
+ ---------
+
+ ::
+
+ >>> dic = {'key 0': 0, 'key 1': 1}
+ >>> print dict2html(dic)
+ <table>
+ <tr>
+ <td>key 0</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>key 1</td>
+ <td>1</td>
+ </tr>
+ </table>
+ >>> print dict2html(dic, border="1")
+ <table border='1'>
+ <tr>
+ <td>key 0</td>
+ <td>0</td>
+ </tr>
+ <tr>
+ <td>key 1</td>
+ <td>1</td>
+ </tr>
+ </table>
+ >>> print dict2html(dic, kdec='b', vfmt='%05d', vdec='i')
+ <table>
+ <tr>
+ <td><b>key 0</b></td>
+ <td><i>00000</i></td>
+ </tr>
+ <tr>
+ <td><b>key 1</b></td>
+ <td><i>00001</i></td>
+ </tr>
+ </table>
+ >>> dic = {'key 0': (2, 3), 'key 1': (10, 5)}
+ >>> print dict2html(dic, kdec='b', vdec='i',
+ ... vfun=lambda x: "%d<sup>%.1f</sup>" % x)
+ <table>
+ <tr>
+ <td><b>key 0</b></td>
+ <td><i>2<sup>3.0</sup></i></td>
+ </tr>
+ <tr>
+ <td><b>key 1</b></td>
+ <td><i>10<sup>5.0</sup></i></td>
+ </tr>
+ </table>
+ """
+ def fun(x):
+ return x
+
+ keys = keys if keys else sorted(dic.keys())
+ header = "<table border=%r>" % border if border else "<table>"
+ kd = "<%s>%s</%s>" % (kdec, kfmt, kdec) if kdec else kfmt
+ vd = "<%s>%s</%s>" % (vdec, vfmt, vdec) if vdec else vfmt
+ kfun = kfun if kfun else fun
+ vfun = vfun if vfun else fun
+ content = [dcont.format(key=kd % kfun(k), value=vd % vfun(dic[k]))
+ for k in keys]
+ return '\n'.join([header, ] + content + ['</table>', ])
Added: grass/trunk/lib/python/pygrass/shell/show.py
===================================================================
--- grass/trunk/lib/python/pygrass/shell/show.py (rev 0)
+++ grass/trunk/lib/python/pygrass/shell/show.py 2013-06-23 19:13:27 UTC (rev 56888)
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sun Jun 23 19:58:54 2013
+
+ at author: pietro
+"""
+import io
+
+
+def raw_figure(figpath):
+ with io.OpenWrapper(figpath, mode='rb') as data:
+ res = data.read()
+ return res
More information about the grass-commit
mailing list