1#!/usr/bin/env python3

2# This file is part of Checkbox.

3#

4# Copyright 2014-2018 Canonical Ltd.

5# Written by:

6# Daniel Manrique <roadmr@ubuntu.com>

7# Sylvain Pineau <sylvain.pineau@canonical.com>

8#

9# Checkbox is free software: you can redistribute it and/or modify

10# it under the terms of the GNU General Public License version 3,

11# as published by the Free Software Foundation.

12#

13# Checkbox is distributed in the hope that it will be useful,

14# but WITHOUT ANY WARRANTY; without even the implied warranty of

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

16# GNU General Public License for more details.

17#

18# You should have received a copy of the GNU General Public License

19# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.

20"""

21 manage_compiz_plugin.py

22=======================

23

24 This script allows enabling or disabling compiz plugins using

25 gsettings. Changes take effect on the fly.

26"""

27

28 from gettext import gettext as _

29 import argparse

30 import gettext

31 import os

32 import subprocess

33 import time

34

35 KEY = "/org/compiz/profiles/unity/plugins/core/active-plugins"

36

37 gettext.textdomain("com.canonical.certification.checkbox")

38 gettext.bindtextdomain(

39 "com.canonical.certification.checkbox",

40 os.getenv("CHECKBOX_PROVIDER_LOCALE_DIR", None),

41)

42

43 plugins = eval(subprocess.check_output(["dconf", "read", KEY]))

44

45 parser = argparse.ArgumentParser(

46 description=_("enable/disable compiz plugins"),

47 epilog=_("Available plugins: {}").format(plugins),

48)

49 parser.add_argument("plugin", type=str, help=_("Name of plugin to control"))

50 parser.add_argument(

51 "action",

52 type=str,

53 choices=["enable", "disable"],

54 help=_("What to do with the plugin"),

55)

56

57 args = parser.parse_args()

58

59 if args.action == "enable":

60 if args.plugin in plugins:

61 raise SystemExit(_("Plugin {} already enabled").format(args.plugin))

62 plugins.append(args.plugin)

63 else:

64 if args.plugin not in plugins:

65 raise SystemExit(_("Plugin {} doesn't exist").format(args.plugin))

66 plugins.remove(args.plugin)

67 subprocess.call(["dconf", "write", KEY, str(plugins)])

68

69 time.sleep(3)