Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2010-08-21 21:39:32 (GMT)
committer Walter Bender <walter@sugarlabs.org>2010-08-21 21:39:32 (GMT)
commitcd2a65042fc618635083a87723516f8466480934 (patch)
treeea044b0eb82994f6674cda3799c8affb5c90a41b
parent7b697bd192e8c3c9681b44de9727a771b567d4f4 (diff)
parent72814a7e6ec144c656e7016c8adef86090eef2fd (diff)
Merge branch 'master' of git://git.sugarlabs.org/turtleart/config-file-in-config-dir
-rwxr-xr-xturtleart.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/turtleart.py b/turtleart.py
index fb384c1..bb01dea 100755
--- a/turtleart.py
+++ b/turtleart.py
@@ -28,6 +28,8 @@ import getopt
import sys
import os
import os.path
+import cStringIO
+import errno
try:
import pycurl
@@ -37,6 +39,14 @@ except ImportError, e:
print "Import Error: %s. Project upload is disabled." % (e)
_UPLOAD_AVAILABLE = False
+try:
+ # Try to use XDG Base Directory standard for config files
+ import xdg.BaseDirectory
+ CONFIG_HOME = os.path.join(xdg.BaseDirectory.xdg_config_home, 'turtleart')
+except ImportError, e:
+ # Default to `.config` per the spec.
+ CONFIG_HOME = os.path.expanduser(os.path.join('~', '.config', 'turtleart'))
+
argv = sys.argv[:] # Workaround for import behavior of gst in tagplay
sys.argv[1:] = [] # Execution of import gst cannot see '--help' or '-h'
@@ -56,6 +66,14 @@ _HELP_MSG = 'turtleart.py: ' + _('usage is') + """
_MAX_FILE_SIZE = 950000
+def mkdir_p(path):
+ '''Create a directory in a fashion similar to `mkdir -p`'''
+ try:
+ os.makedirs(path)
+ except OSError as exc:
+ if exc.errno == errno.EEXIST:
+ pass
+ else: raise
def _make_sub_menu(menu, name):
""" add a new submenu to the toolbar """
@@ -143,9 +161,19 @@ class TurtleMain():
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
try:
- data_file = open('.turtleartrc', 'r')
+ data_file = open(os.path.join(CONFIG_HOME, 'turtleartrc'), 'r')
except IOError:
- data_file = open('.turtleartrc', 'a+')
+ # Opening the config file failed
+ # We'll assume it needs to be created
+ try:
+ mkdir_p(CONFIG_HOME)
+ data_file = open(os.path.join(CONFIG_HOME, 'turtleartrc'), 'a+')
+ except IOError:
+ # We can't write to the configuration file, use
+ # a faux file that will persist for the length of
+ # the session.
+ print 'Configuration directory not writable.'
+ data_file = cStringIO.StringIO()
data_file.write(str(50) + '\n')
data_file.write(str(50) + '\n')
data_file.write(str(800) + '\n')