[gnome-tweak-tool] Add AutostartManager utility class



commit 2405aeaf0caba7fc3ecc9429ea98ec80257c8796
Author: John Stowers <john stowers gmail com>
Date:   Wed Apr 27 08:16:10 2011 +1200

    Add AutostartManager utility class

 gtweak/utils.py |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gtweak/utils.py b/gtweak/utils.py
new file mode 100644
index 0000000..f0a1538
--- /dev/null
+++ b/gtweak/utils.py
@@ -0,0 +1,62 @@
+# This file is part of gnome-tweak-tool.
+#
+# Copyright (c) 2011 John Stowers
+#
+# gnome-tweak-tool 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 3 of the License, or
+# (at your option) any later version.
+#
+# gnome-tweak-tool 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 gnome-tweak-tool.  If not, see <http://www.gnu.org/licenses/>.
+
+import os.path
+
+from gi.repository import GLib
+
+class AutostartManager:
+    def __init__(self, DATA_DIR, desktop_filename, extra_exec_args=""):
+        self._desktop_file = os.path.join(DATA_DIR, desktop_filename)
+        self._autostart_file = os.path.join(
+                                    GLib.get_user_config_dir(), "autostart", desktop_filename)
+        self._extra_exec_args = " %s\n" % extra_exec_args
+
+    def is_start_at_login_enabled(self):
+        if os.path.exists(self._autostart_file):
+            #if it contains X-GNOME-Autostart-enabled=false then it has
+            #has been disabled by the user in the session applet, otherwise
+            #it is enabled
+            return open(self._autostart_file).read().find("X-GNOME-Autostart-enabled=false") == -1
+        else:
+            return False
+
+    def update_start_at_login(self, update):
+
+        if os.path.exists(self._autostart_file):
+            log.info("Removing autostart desktop file")
+            os.remove(self._autostart_file)
+
+        if update:
+            if not os.path.exists(self._desktop_file):
+                log.critical("Could not find desktop file: %s" % self._desktop_file)
+                return
+
+            log.info("Adding autostart desktop file")
+            #copy the original file to the new file, but add the extra exec args
+            old = open(self._desktop_file, "r")
+            new = open(self._autostart_file, "w")
+
+            for l in old.readlines():         
+                if l.startswith("Exec="):
+                    new.write(l[0:-1])
+                    new.write(self._extra_exec_args)
+                else:
+                    new.write(l)
+
+            old.close()
+            new.close()



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