Blob Blame History Raw
From 1bda0910b4d8b05dfa94732d4bb0795621d4970f Mon Sep 17 00:00:00 2001
From: Carlos Soriano <csoriano@redhat.com>
Date: Thu, 14 Jun 2018 11:51:06 +0200
Subject: [PATCH 2/3] general: Port to python2

RHEL 7.6 doesn't have python3...
---
 gnome-tweak-tool-lid-inhibitor                |  2 +-
 gnome-tweaks                                  |  2 +-
 gtweak/app.py                                 |  1 +
 gtweak/egowrapper.py                          |  1 +
 gtweak/gsettings.py                           |  1 +
 gtweak/gshellwrapper.py                       |  3 ++-
 gtweak/gtksettings.py                         | 13 +++++++++++--
 gtweak/tweakmodel.py                          |  5 +++--
 gtweak/tweaks/tweak_group_appearance.py       |  1 +
 gtweak/tweaks/tweak_group_desktop.py          |  1 +
 gtweak/tweaks/tweak_group_font.py             |  1 +
 gtweak/tweaks/tweak_group_keymouse.py         |  1 +
 gtweak/tweaks/tweak_group_power.py            |  1 +
 gtweak/tweaks/tweak_group_shell_extensions.py |  5 +++--
 gtweak/tweaks/tweak_group_sound.py            |  1 +
 gtweak/tweaks/tweak_group_startup.py          |  5 ++++-
 gtweak/tweaks/tweak_group_test.py             |  3 +++
 gtweak/tweaks/tweak_group_top_bar.py          |  3 ++-
 gtweak/tweaks/tweak_group_windows.py          |  1 +
 gtweak/tweaks/tweak_group_workspaces.py       |  3 ++-
 gtweak/tweaks/tweak_group_xkb.py              |  5 +++--
 gtweak/tweaks/tweak_wacom.py                  |  9 +++++----
 gtweak/tweakview.py                           |  5 +++--
 gtweak/utils.py                               | 11 ++++++++---
 gtweak/widgets.py                             |  1 +
 meson-postinstall.py                          |  4 ++--
 meson.build                                   |  3 +--
 27 files changed, 65 insertions(+), 27 deletions(-)

diff --git a/gnome-tweak-tool-lid-inhibitor b/gnome-tweak-tool-lid-inhibitor
index f9d18db..499e9eb 100755
--- a/gnome-tweak-tool-lid-inhibitor
+++ b/gnome-tweak-tool-lid-inhibitor
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
diff --git a/gnome-tweaks b/gnome-tweaks
index 596d8ab..038bb9d 100755
--- a/gnome-tweaks
+++ b/gnome-tweaks
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
diff --git a/gtweak/app.py b/gtweak/app.py
index bc5b5f4..03dc99d 100644
--- a/gtweak/app.py
+++ b/gtweak/app.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/egowrapper.py b/gtweak/egowrapper.py
index 7a60f71..11caee3 100644
--- a/gtweak/egowrapper.py
+++ b/gtweak/egowrapper.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/gsettings.py b/gtweak/gsettings.py
index e0116e9..96d58e3 100644
--- a/gtweak/gsettings.py
+++ b/gtweak/gsettings.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/gshellwrapper.py b/gtweak/gshellwrapper.py
index 0e4a49b..d654f88 100644
--- a/gtweak/gshellwrapper.py
+++ b/gtweak/gshellwrapper.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -164,7 +165,7 @@ class GnomeShellFactory:
         try:
             proxy = _ShellProxy()
             settings = GSettingsSetting("org.gnome.shell")
-            v = list(map(int, proxy.version.split(".")))
+            v = map(int, proxy.version.split("."))
 
             if v >= [3, 5, 0]:
                 self.shell = GnomeShell36(proxy, settings)
diff --git a/gtweak/gtksettings.py b/gtweak/gtksettings.py
index ce09842..8d557b2 100644
--- a/gtweak/gtksettings.py
+++ b/gtweak/gtksettings.py
@@ -1,9 +1,11 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2012 Cosimo Cecchi
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
 import os.path
 import logging
+import errno
 
 from gi.repository import GLib
 
@@ -18,7 +20,14 @@ class GtkSettingsManager:
         self._path = os.path.join(GLib.get_user_config_dir(),
                                   "gtk-" + version,
                                   "settings.ini")
-        os.makedirs(os.path.dirname(self._path), exist_ok=True)
+        try:
+            os.makedirs(os.path.dirname(self._path))
+        except OSError, e:
+            if e.errno is not errno.EEXIST:
+                raise
+        except:
+            raise
+
 
     def _get_keyfile(self):
         keyfile = None
@@ -47,4 +56,4 @@ class GtkSettingsManager:
             data = keyfile.to_data()
             GLib.file_set_contents(self._path, data[0].encode())
         except:
-            raise
+            raise
\ No newline at end of file
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index 2e9fb16..f8a9c18 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -66,7 +67,7 @@ class TweakGroup(object):
 
 class TweakModel(Gtk.ListStore):
     (COLUMN_NAME,
-     COLUMN_TWEAK) = list(range(2))
+     COLUMN_TWEAK) = range(2)
 
     def __init__(self):
         super(TweakModel, self).__init__(str, object)
@@ -140,4 +141,4 @@ class TweakModel(Gtk.ListStore):
         return tweaks, groups
 
     def get_tweakgroup_iter(self, name):
-        return self._tweak_group_iters[name]
+        return self._tweak_group_iters[name]
\ No newline at end of file
diff --git a/gtweak/tweaks/tweak_group_appearance.py b/gtweak/tweaks/tweak_group_appearance.py
index ff78735..e8b40a7 100644
--- a/gtweak/tweaks/tweak_group_appearance.py
+++ b/gtweak/tweaks/tweak_group_appearance.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_desktop.py b/gtweak/tweaks/tweak_group_desktop.py
index f55c696..d7239bd 100644
--- a/gtweak/tweaks/tweak_group_desktop.py
+++ b/gtweak/tweaks/tweak_group_desktop.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_font.py b/gtweak/tweaks/tweak_group_font.py
index 43f4d09..89986b6 100644
--- a/gtweak/tweaks/tweak_group_font.py
+++ b/gtweak/tweaks/tweak_group_font.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_keymouse.py b/gtweak/tweaks/tweak_group_keymouse.py
index 577d5cc..9553566 100644
--- a/gtweak/tweaks/tweak_group_keymouse.py
+++ b/gtweak/tweaks/tweak_group_keymouse.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_power.py b/gtweak/tweaks/tweak_group_power.py
index 305877f..b6c82c5 100644
--- a/gtweak/tweaks/tweak_group_power.py
+++ b/gtweak/tweaks/tweak_group_power.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_shell_extensions.py b/gtweak/tweaks/tweak_group_shell_extensions.py
index 8ef4bf8..82c754b 100644
--- a/gtweak/tweaks/tweak_group_shell_extensions.py
+++ b/gtweak/tweaks/tweak_group_shell_extensions.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
@@ -219,7 +220,7 @@ class ShellExtensionTweakGroup(ListBoxTweakGroup):
             ego = ExtensionsDotGnomeDotOrg(version)
             try:
                 #add a tweak for each installed extension
-                extensions = sorted(list(shell.list_extensions().values()), key=itemgetter("name"))
+                extensions = sorted(shell.list_extensions().values(), key=itemgetter("name"))
                 for extension in extensions:
                     try:
                         extension_widget = _ShellExtensionTweak(shell, extension, size_group=sg)
@@ -280,4 +281,4 @@ class ShellExtensionTweakGroup(ListBoxTweakGroup):
 
 TWEAK_GROUPS = [
         ShellExtensionTweakGroup(),
-]
+]
\ No newline at end of file
diff --git a/gtweak/tweaks/tweak_group_sound.py b/gtweak/tweaks/tweak_group_sound.py
index 78705ef..cd35f58 100644
--- a/gtweak/tweaks/tweak_group_sound.py
+++ b/gtweak/tweaks/tweak_group_sound.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2017 Canonical
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_startup.py b/gtweak/tweaks/tweak_group_startup.py
index 05f7022..ba1288c 100644
--- a/gtweak/tweaks/tweak_group_startup.py
+++ b/gtweak/tweaks/tweak_group_startup.py
@@ -1,7 +1,10 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
+from __future__ import print_function
+
 import os.path
 import subprocess
 import logging
@@ -339,7 +342,7 @@ class AutostartListBoxTweakGroup(ListBoxTweakGroup):
                     str(os.getuid()),'-o','cmd'],
                     stdout=subprocess.PIPE)
         out = cmd.communicate()[0]
-        for l in out.decode('utf8').split('\n'):
+        for l in out.split('\n'):
             exe = l.split(' ')[0]
             if exe and exe[0] != '[': #kernel process
                 exes.append( os.path.basename(exe) )
diff --git a/gtweak/tweaks/tweak_group_test.py b/gtweak/tweaks/tweak_group_test.py
index f056111..004815b 100644
--- a/gtweak/tweaks/tweak_group_test.py
+++ b/gtweak/tweaks/tweak_group_test.py
@@ -1,7 +1,10 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
 
+from __future__ import print_function
+
 from gi.repository import Gtk, Gdk
 
 from gtweak.tweakmodel import Tweak
diff --git a/gtweak/tweaks/tweak_group_top_bar.py b/gtweak/tweaks/tweak_group_top_bar.py
index 0979720..05a3d31 100644
--- a/gtweak/tweaks/tweak_group_top_bar.py
+++ b/gtweak/tweaks/tweak_group_top_bar.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -10,7 +11,7 @@ from gtweak.utils import XSettingsOverrides
 _shell = GnomeShellFactory().get_shell()
 _shell_loaded = _shell is not None
 
-class ApplicationMenuTweak(GetterSetterSwitchTweak):
+class ApplicationMenuTweak(GetterSetterSwitchTweak,  _GSettingsTweak):
     def __init__(self, **options):
         self._xsettings = XSettingsOverrides()
         name = _("Application Menu")
diff --git a/gtweak/tweaks/tweak_group_windows.py b/gtweak/tweaks/tweak_group_windows.py
index 3ac8964..0743689 100644
--- a/gtweak/tweaks/tweak_group_windows.py
+++ b/gtweak/tweaks/tweak_group_windows.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/gtweak/tweaks/tweak_group_workspaces.py b/gtweak/tweaks/tweak_group_workspaces.py
index 1805861..dd28b4c 100644
--- a/gtweak/tweaks/tweak_group_workspaces.py
+++ b/gtweak/tweaks/tweak_group_workspaces.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -89,7 +90,7 @@ class StaticWorkspaceTweak(Gtk.ListBox, _GSettingsTweak):
             self.check1.hide()
             self.check2.show()
 
-class PrimaryWorkspaceTweak(Gtk.ListBox, Tweak):
+class PrimaryWorkspaceTweak(Gtk.ListBox,  _GSettingsTweak):
 
     def __init__(self, **options):
         name = _("Workspaces")
diff --git a/gtweak/tweaks/tweak_group_xkb.py b/gtweak/tweaks/tweak_group_xkb.py
index 9cb3670..659b08a 100644
--- a/gtweak/tweaks/tweak_group_xkb.py
+++ b/gtweak/tweaks/tweak_group_xkb.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2012 Red Hat, Inc.
 # Authors:
 #       Rui Matos
@@ -117,7 +118,7 @@ class _XkbOption(Gtk.Expander, Tweak):
                 if w:
                     _set_active(w, True)
         else:
-            for w in list(self._widgets.values()):
+            for w in self._widgets.values():
                 if w._val in self._values:
                     _set_active(w, True)
                 else:
@@ -134,7 +135,7 @@ class _XkbOption(Gtk.Expander, Tweak):
         elif active and not w._val in self._values and w._val:
             self._parent_settings.setting_add_to_list(TypingTweakGroup.XKB_GSETTINGS_NAME, w._val)
 
-class TypingTweakGroup(Gtk.Box):
+class TypingTweakGroup(Gtk.Box, TweakGroup):
 
     XKB_GSETTINGS_SCHEMA = "org.gnome.desktop.input-sources"
     XKB_GSETTINGS_NAME = "xkb-options"
diff --git a/gtweak/tweaks/tweak_wacom.py b/gtweak/tweaks/tweak_wacom.py
index ed227ca..2e89246 100644
--- a/gtweak/tweaks/tweak_wacom.py
+++ b/gtweak/tweaks/tweak_wacom.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2013 Red Hat, Inc.
 # Author: Joaquim Rocha <jrocha@redhat.com>
 # SPDX-License-Identifier: GPL-3.0+
@@ -6,7 +7,7 @@
 from gtweak.tweakmodel import TweakGroup
 from gtweak.widgets import GSettingsSwitchTweak
 import subprocess
-import configparser
+import ConfigParser
 import io
 
 def N_(x): return x
@@ -88,10 +89,10 @@ class WacomConfigs(object):
                 match_id = config.get(DEVICE_SECTION, DEVICE_MATCH_LINE)
                 # Use a dict to discard possible repeated devices
                 configs_dict[match_id] = config
-        return list(configs_dict.values())
+        return configs_dict.values()
 
     def _text_to_config(self, text):
-        config = configparser.RawConfigParser(allow_no_value=True)
+        config = ConfigParser.RawConfigParser(allow_no_value=True)
         config.readfp(io.BytesIO(text))
         return config
 
@@ -108,4 +109,4 @@ class WacomSwitchTweak(GSettingsSwitchTweak):
                                       **options)
 wg = WacomGroup()
 if wg.tweaks:
-    TWEAK_GROUPS = (wg,)
+    TWEAK_GROUPS = (wg,)
\ No newline at end of file
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index a130fea..6c640ba 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -157,7 +158,7 @@ class Window(Gtk.ApplicationWindow):
             row.add(lbl)
             return row
 
-        groups = list(self._model._tweak_group_names.keys())
+        groups = self._model._tweak_group_names.keys()
         groups = sorted(groups)
 
         for g in groups:
@@ -263,4 +264,4 @@ class Window(Gtk.ApplicationWindow):
             if t in tweaks:
                 t.show_all()
             else:
-                t.hide()
+                t.hide()
\ No newline at end of file
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 6f0c25c..258acf4 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
@@ -161,7 +162,11 @@ class AutostartFile:
             self._extra_exec_args = "\n"
 
         user_autostart_dir = os.path.join(GLib.get_user_config_dir(), "autostart")
-        os.makedirs(user_autostart_dir, exist_ok=True)
+        if not os.path.isdir(user_autostart_dir):
+            try:
+                os.makedirs(user_autostart_dir)
+            except:
+                logging.critical("Could not create autostart dir: %s" % user_autostart_dir)
 
         self._user_autostart_file = os.path.join(user_autostart_dir, self._autostart_desktop_filename)
 
@@ -269,7 +274,7 @@ class XSettingsOverrides:
 
     def _dup_variant_as_dict(self):
         items = {}
-        for k in list(self._variant.keys()):
+        for k in self._variant.keys():
             try:
                 #variant override doesnt support .items()
                 v = self._variant[k]
@@ -352,4 +357,4 @@ class LogoutNotification:
                        '/org/gnome/SessionManager',
                        'org.gnome.SessionManager',
                        None)
-        proxy.Logout('(u)', 0)
+        proxy.Logout('(u)', 0)
\ No newline at end of file
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index 3d48a51..11cd557 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 # Copyright (c) 2011 John Stowers
 # SPDX-License-Identifier: GPL-3.0+
 # License-Filename: LICENSES/GPL-3.0
diff --git a/meson-postinstall.py b/meson-postinstall.py
index 115d8e0..3b41cc4 100755
--- a/meson-postinstall.py
+++ b/meson-postinstall.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
 
 import sysconfig
 from compileall import compile_dir
@@ -16,4 +16,4 @@ if not destdir:
 
 print('Compiling python bytecode...')
 moduledir = sysconfig.get_path('purelib', vars={'base': str(prefix)})
-compile_dir(destdir + path.join(moduledir, 'gtweak'), optimize=2)
+compile_dir(destdir + path.join(moduledir, 'gtweak'))
diff --git a/meson.build b/meson.build
index 4d24fa5..f5ea92d 100644
--- a/meson.build
+++ b/meson.build
@@ -5,7 +5,6 @@ project('gnome-tweaks',
 
 gnome = import('gnome')
 i18n = import('i18n')
-python3 = import('python3')
 
 prefix = get_option('prefix')
 
@@ -13,7 +12,7 @@ bindir = join_paths(prefix, get_option('bindir'))
 datadir = join_paths(prefix, get_option('datadir'))
 libexecdir = join_paths(prefix, get_option('libexecdir'))
 localedir = join_paths(prefix, get_option('localedir'))
-pythondir = join_paths(prefix, python3.sysconfig_path('purelib'))
+pythondir = join_paths(prefix, '/usr/lib/python2.7/site-packages')
 
 pkgdatadir = join_paths(datadir, meson.project_name())
 
-- 
2.17.0