[gnome-code-assistance] Bourne shell backend



commit 1df84e3a959188b6710508c4751b35be01ebf558
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Nov 9 11:24:19 2013 +0100

    Bourne shell backend

 backends/Makefile.am                           |    4 +
 backends/sh/Makefile.am                        |   13 ++++
 backends/sh/__init__.py                        |   76 ++++++++++++++++++++++++
 backends/sh/org.gnome.CodeAssist.sh.service.in |    3 +
 backends/sh/sh.in                              |    7 ++
 backends/vala/Makefile.am                      |    2 +-
 configure.ac                                   |   25 ++++++++-
 7 files changed, 128 insertions(+), 2 deletions(-)
---
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 12f1d04..5130d20 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -38,4 +38,8 @@ if BACKENDS_JS_ENABLE
 include backends/js/Makefile.am
 endif
 
+if BACKENDS_SH_ENABLE
+include backends/sh/Makefile.am
+endif
+
 GITIGNOREDEPS += backends/Makefile.am
diff --git a/backends/sh/Makefile.am b/backends/sh/Makefile.am
new file mode 100644
index 0000000..a3abc3f
--- /dev/null
+++ b/backends/sh/Makefile.am
@@ -0,0 +1,13 @@
+shbackenddir = $(GCA_PYBACKENDS_DIR)/sh
+shbackend_PYTHON =                             \
+       backends/sh/__init__.py
+
+shbackendexecdir = $(GCA_BACKENDS_EXEC_DIR)
+shbackendexec_SCRIPTS = \
+       backends/sh/sh
+
+shbackendservicedir = $(datadir)/dbus-1/services
+shbackendservice_DATA = \
+       backends/sh/org.gnome.CodeAssist.sh.service
+
+GITIGNOREDEPS += backends/sh/Makefile.am
diff --git a/backends/sh/__init__.py b/backends/sh/__init__.py
new file mode 100644
index 0000000..0f62081
--- /dev/null
+++ b/backends/sh/__init__.py
@@ -0,0 +1,76 @@
+# gnome code assistance sh backend
+# Copyright (C) 2013  Paolo Borelli <pborelli gnome org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import re
+import subprocess
+
+try:
+    from subprocess import DEVNULL # py3k
+except ImportError:
+    import os
+    DEVNULL = open(os.devnull, 'wb')
+
+from gnome.codeassistance import transport, types
+
+class Service(transport.Service):
+    language = 'sh'
+
+    pattern = re.compile("^.*line ([0-9]+).*: (.*)$")
+
+    def parse(self, path, cursor, unsaved, options, doc):
+        path = self.data_path(path, unsaved)
+
+        errors = []
+
+        try:
+            p = subprocess.Popen(["/bin/sh", "-n", path], stdout=DEVNULL, stderr=subprocess.PIPE)
+            for l in iter(p.stderr.readline, ''):
+                if not l:
+                    break
+
+                m = Service.pattern.match(l.decode())
+                if m:
+                    loc = types.SourceLocation(line=m.group(1))
+                    errors.append(types.Diagnostic(severity=types.Diagnostic.Severity.ERROR,
+                                                   locations=[loc.to_range()],
+                                                    message=m.group(2)))
+        except Error as e:
+            pass
+
+        if doc is None:
+            doc = self.document()
+
+        doc.errors = errors
+
+        return doc
+
+    def dispose(self, doc):
+        pass
+
+class Document(transport.Document, transport.Diagnostics):
+    errors = None
+
+    def diagnostics(self):
+        return self.errors
+
+def run():
+    transport.Transport(Service, Document).run()
+
+if __name__ == '__main__':
+    run()
+
+# ex:ts=4:et:
diff --git a/backends/sh/org.gnome.CodeAssist.sh.service.in b/backends/sh/org.gnome.CodeAssist.sh.service.in
new file mode 100644
index 0000000..335b139
--- /dev/null
+++ b/backends/sh/org.gnome.CodeAssist.sh.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.CodeAssist.sh
+Exec= backendexecdir@/sh --transport dbus
diff --git a/backends/sh/sh.in b/backends/sh/sh.in
new file mode 100644
index 0000000..db6faec
--- /dev/null
+++ b/backends/sh/sh.in
@@ -0,0 +1,7 @@
+#!/usr/bin/env python
+
+import sys
+sys.path.insert(0, '@GCA_PYBACKENDS_ROOT_EX@')
+
+from gnome.codeassistance import sh
+sh.run()
diff --git a/backends/vala/Makefile.am b/backends/vala/Makefile.am
index 1163e22..9e48723 100644
--- a/backends/vala/Makefile.am
+++ b/backends/vala/Makefile.am
@@ -13,7 +13,7 @@ backends_vala_vala_VALAFLAGS =                        \
        --target-glib=2.36                      \
        --pkg gio-2.0                           \
        --pkg gee-0.8                           \
-       --pkg libvala-0.20
+       --pkg libvala-0.22
 
 backends_vala_vala_CFLAGS = $(BACKEND_VALA_CFLAGS) -w
 backends_vala_vala_LDADD = $(BACKEND_VALA_LIBS)
diff --git a/configure.ac b/configure.ac
index e2bff9f..1b83035 100644
--- a/configure.ac
+++ b/configure.ac
@@ -300,7 +300,7 @@ AC_ARG_ENABLE([vala],
               [enable_vala=$enableval],
               [enable_vala=auto])
 
-BACKEND_VALA_MODULES="gobject-2.0 >= 2.36 glib-2.0 >= 2.36 gio-2.0 >= 2.36 gee-0.8 libvala-0.20"
+BACKEND_VALA_MODULES="gobject-2.0 >= 2.36 glib-2.0 >= 2.36 gio-2.0 >= 2.36 gee-0.8 libvala-0.22"
 
 if test "x$enable_vala" != "xno"; then
        AM_PROG_VALAC
@@ -371,6 +371,26 @@ color_enable_var("$enable_go", [enable_go_msg])
 
 AM_CONDITIONAL(BACKENDS_GO_ENABLE, test "x$enable_go" = "xyes")
 
+
+dnl ================================================================
+dnl shell backend configuration
+dnl ================================================================
+AC_ARG_ENABLE([sh],
+              AS_HELP_STRING([--enable-sh],[enable shell backend]),
+              [enable_sh=$enableval],
+              [enable_sh=yes])
+
+if test "x$enable_sh" != "xno"; then
+       # we assume /bin/sh is always there or we would not be
+       # running this scrip
+       enable_sh=yes
+fi
+
+color_enable_var("$enable_sh", [enable_sh_msg])
+
+AM_CONDITIONAL(BACKENDS_SH_ENABLE, test "x$enable_sh" = "xyes")
+
+
 backendexecdir_unex="$libexecdir/gnome-code-assistance"
 adl_RECURSIVE_EVAL("$backendexecdir_unex", [backendexecdir])
 AC_SUBST(backendexecdir)
@@ -449,6 +469,8 @@ backends/vala/org.gnome.CodeAssist.vala.service
 backends/go/org.gnome.CodeAssist.go.service
 backends/js/org.gnome.CodeAssist.js.service
 backends/js/js
+backends/sh/org.gnome.CodeAssist.sh.service
+backends/sh/sh
 ])
 
 AC_OUTPUT
@@ -470,5 +492,6 @@ Configuration:
                go:             $enable_go_msg
                ruby:           $enable_ruby_msg
                javascript:     $enable_js_msg
+               shell:          $enable_sh_msg
 "
 


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