From dda4f8306f194ff142d25bbedeb7ee5dabd0f523 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Wed, 12 Aug 2015 14:46:00 +0200
Subject: grc: move gui prefs file to ~/.gnuradio/grc.conf

---
 grc/python/Platform.py | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)

(limited to 'grc/python/Platform.py')

diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index feea81dae1..1497099f3f 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -18,7 +18,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 import os
+import sys
+
 from gnuradio import gr
+
 from .. base.Platform import Platform as _Platform
 from .. gui.Platform import Platform as _GUIPlatform
 from FlowGraph import FlowGraph as _FlowGraph
@@ -27,21 +30,26 @@ from Block import Block as _Block
 from Port import Port as _Port
 from Param import Param as _Param
 from Generator import Generator
-from Constants import \
-    HIER_BLOCKS_LIB_DIR, BLOCK_DTD, \
-    DEFAULT_FLOW_GRAPH, BLOCKS_DIRS, PREFS_FILE
-import Constants
+from Constants import (
+    HIER_BLOCKS_LIB_DIR, BLOCK_DTD, DEFAULT_FLOW_GRAPH, BLOCKS_DIRS,
+    PREFS_FILE, PREFS_FILE_OLD, CORE_TYPES
+)
+
+
+COLORS = [(name, color) for name, key, sizeof, color in CORE_TYPES]
 
-COLORS = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES]
 
 class Platform(_Platform, _GUIPlatform):
     def __init__(self):
         """
         Make a platform for gnuradio.
         """
-        #ensure hier dir
-        if not os.path.exists(HIER_BLOCKS_LIB_DIR): os.mkdir(HIER_BLOCKS_LIB_DIR)
-        #init
+        # ensure hier and conf directories
+        if not os.path.exists(HIER_BLOCKS_LIB_DIR):
+            os.mkdir(HIER_BLOCKS_LIB_DIR)
+        if not os.path.exists(os.path.dirname(PREFS_FILE)):
+            os.mkdir(os.path.dirname(PREFS_FILE))
+        # init
         _Platform.__init__(
             self,
             name='GNU Radio Companion',
@@ -55,12 +63,23 @@ class Platform(_Platform, _GUIPlatform):
             generator=Generator,
             colors=COLORS,
         )
-
+        self._move_old_pref_file()
         _GUIPlatform.__init__(
             self,
             prefs_file=PREFS_FILE
         )
 
+    @staticmethod
+    def _move_old_pref_file():
+        if PREFS_FILE == PREFS_FILE_OLD:
+            return  # prefs file overridden with env var
+        if os.path.exists(PREFS_FILE_OLD) and not os.path.exists(PREFS_FILE):
+            try:
+                import shutil
+                shutil.move(PREFS_FILE_OLD, PREFS_FILE)
+            except Exception as e:
+                print >> sys.stderr, e
+
     ##############################################
     # Constructors
     ##############################################
-- 
cgit v1.2.3