summaryrefslogtreecommitdiffstats
path: root/build_tools/larch8/liblarch/larcon_base.py
diff options
context:
space:
mode:
Diffstat (limited to 'build_tools/larch8/liblarch/larcon_base.py')
-rw-r--r--build_tools/larch8/liblarch/larcon_base.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/build_tools/larch8/liblarch/larcon_base.py b/build_tools/larch8/liblarch/larcon_base.py
new file mode 100644
index 0000000..9d343f5
--- /dev/null
+++ b/build_tools/larch8/liblarch/larcon_base.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python2
+#
+# larcon_base.py -- Basic backend framework for larcon applications
+#
+# (c) Copyright 2010 Michael Towers (larch42 at googlemail dot com)
+#
+# 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
+#
+#-------------------------------------------------------------------
+# 2010.08.14
+
+import os, threading
+from liblarch_conf import liblarchdir
+from rootrun import init_rootrun
+from translation import i18n_liblarch, _
+
+class Backend:
+ def __init__(self, appname, env, basedir=None):
+ """The env(ironment), i.e. the global dictionary, is needed for
+ fetching uim files.
+ If the basedir is not provided it can be derived from the appname.
+ """
+ if basedir:
+ self.basedir = basedir
+ else:
+ self.basedir = os.path.dirname(liblarchdir) + '/' + appname
+ self.appenv = env
+
+ def fss_fetch_layout(self, uim):
+ fp = os.path.join(self.basedir, 'uim', uim)
+ fh = open(fp)
+ r = fh.read()
+ fh.close()
+ return eval(r, self.appenv)
+
+ def fss_uim_fetch(self, uim):
+ fp = os.path.join(liblarchdir, 'uim', uim)
+ fh = open(fp)
+ r = fh.read()
+ fh.close()
+ return eval(r)
+
+ def setuisig(self, fn):
+ self.ui_signal = fn
+
+ def rootcall(self, cmd, fn_done):
+ self.rcall = init_rootrun(self._pwget)
+ self.rcall.run(cmd, fn_done)
+
+ def _pwget(self, cb, prompt):
+ self.pw_event = threading.Event()
+ self.ui_signal('get_password', prompt)
+ self.pw_event.wait()
+ self.rcall.cb_done(cb, *self.pw_returned)
+
+ def fss_sendpassword(self, ok, pw):
+ # The result needs to be passed to the waiting _pwget method
+ # (which is running in a different thread).
+ self.pw_returned = (ok, pw)
+ self.pw_event.set()
+ return None
+