Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-09-23 15:23:54 (GMT)
committer Sascha Silbe <sascha@silbe.org>2009-09-30 14:22:44 (GMT)
commitc4c635709ec347a4997c06dce3b27d1070cf2bc2 (patch)
tree926892888d9ed8e74c1aa928f0e16c17e645d2c2
parentaf2d14e3b62b403f102a7cd0a6b13a040a35203f (diff)
turn bin/sugar into a Python scriptsugar-py
-rw-r--r--.gitignore1
-rw-r--r--bin/Makefile.am6
-rw-r--r--bin/sugar115
-rw-r--r--bin/sugar.in24
-rw-r--r--configure.ac1
5 files changed, 118 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index 047a849..92ee5b7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -51,7 +51,6 @@ m4/intltool.m4
sugar/browser/_sugarbrowser.c
browser/sugar-marshal.c
browser/sugar-marshal.h
-bin/sugar
shell/extensions/_extensions.c
data/sugar.gtkrc
data/sugar.xml
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 05a9215..58b53a0 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -5,10 +5,10 @@ python_scripts = \
sugar-install-bundle \
sugar-launch \
sugar-session \
- sugar-ui-check
+ sugar-ui-check \
+ sugar
bin_SCRIPTS = \
- sugar \
$(python_scripts)
-EXTRA_DIST = $(python_scripts) sugar.in
+EXTRA_DIST = $(python_scripts)
diff --git a/bin/sugar b/bin/sugar
new file mode 100644
index 0000000..02e0baf
--- /dev/null
+++ b/bin/sugar
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+# 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
+"""Start up Sugar.
+
+This is meant to be called by the user to start a (native) Sugar session.
+For trying out Sugar from within a running session of a different window
+manager / desktop system, please see sugar-emulator (which will run this
+script after setting up an "emulated" X server).
+"""
+
+import os
+import os.path
+import subprocess
+import sys
+
+import jarabe.config
+
+
+def _parse_debug():
+ """Apply settings from ~/.sugar/debug.
+
+ Format of the file:
+
+ # comment
+ var1='this is used as-is (but single quotes removed): $NOISE'
+ NOISE=noise
+ var2="double quotes are just $NOISE"
+ var3=without $NOISE
+ """
+ for line in file(os.path.expanduser('~/.sugar/debug')):
+ old_style = False
+ line = line.strip()
+ if not line or line.startswith('#'):
+ continue
+
+ if line.startswith('export '):
+ if not old_style:
+ # TODO: release note entry
+ sys.stderr.write('sugar: WARNING: old-style ~/.sugar/debug')
+ old_style = True
+
+ line = line[6:].strip()
+
+ name, separator, value = line.partition('=')
+ if not separator:
+ sys.stderr.write('sugar: ~/.sugar/debug: malformed line: %r\n' % (
+ line, ))
+ continue
+
+ name = name.strip()
+ value = value.strip()
+ if value.startswith("'") and value.endswith("'"):
+ value = value[1:-1]
+ else:
+ if value.startswith('"') and value.endswith('"'):
+ value = value[1:-1]
+
+ value = os.path.expanduser(os.path.expandvars(value.strip()))
+
+ os.environ[name] = value
+
+
+def _setup_environment():
+ """Set environment variables."""
+ if 'SUGAR_SCALING' not in os.environ:
+ os.environ['SUGAR_SCALING'] = str(72)
+
+ scaling = int(os.environ['SUGAR_SCALING'])
+ gtkrc = os.path.join(jarabe.config.data_path,
+ 'sugar-%d.gtkrc' % (scaling, ))
+ os.environ['GTK2_RC_FILES'] = gtkrc
+ if not os.path.exists(gtkrc):
+ raise IOError('Gtk theme for scaling value %d not available '
+ 'at %s' % (scaling, gtkrc))
+
+ os.environ['PATH'] += ':/sbin:/usr/sbin'
+
+
+def _start_window_manager():
+ """Start the window manager in the background."""
+ subprocess.Popen(['metacity', '--no-force-fullscreen'])
+
+
+def _run_session():
+ """Hand over control to sugar-session."""
+ os.execlp('sugar-session')
+
+
+def main():
+ """Script-level operations"""
+ try:
+ _setup_environment()
+ _parse_debug()
+ _start_window_manager()
+ _run_session()
+
+ # pylint: disable-msg=W0703
+ except Exception, exc:
+ sys.stderr.write('sugar: ERROR: %s\n' % (exc, ))
+ return 1
+
+
+sys.exit(main())
diff --git a/bin/sugar.in b/bin/sugar.in
deleted file mode 100644
index 1c29a12..0000000
--- a/bin/sugar.in
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-if test -z "$SUGAR_SCALING"; then
- export SUGAR_SCALING=72
-fi
-
-export GTK2_RC_FILES="@prefix@/share/sugar/data/sugar-$SUGAR_SCALING.gtkrc"
-
-# Needed for executing wpa_passphrase
-export PATH="$PATH":/sbin:/usr/sbin
-
-if ! test -f "$GTK2_RC_FILES"; then
- echo "sugar: ERROR: Gtk theme for scaling $SUGAR_SCALING not available in path $GTK2_RC_FILES"
- exit 1
-fi
-
-# Source debug definitions
-if [ -f ~/.sugar/debug ]; then
- . ~/.sugar/debug
-fi
-
-metacity --no-force-fullscreen &
-
-exec sugar-session
diff --git a/configure.ac b/configure.ac
index fe3e6eb..287f1c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,6 @@ AM_GCONF_SOURCE_2
AC_CONFIG_FILES([
bin/Makefile
-bin/sugar
data/icons/Makefile
data/Makefile
data/sugar-emulator.desktop