Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2015 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of toktokkie. 

5 

6toktokkie is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11toktokkie is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

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

17along with toktokkie. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20import os 

21import sys 

22from subprocess import Popen, check_output, CalledProcessError 

23from toktokkie.utils.iconizing.procedures.Procedure import Procedure 

24 

25 

26class GnomeProcedure(Procedure): 

27 """ 

28 Iconizing Procedure that uses the gio command line tool to set the 

29 icon file in gnome-based systems 

30 """ 

31 

32 @classmethod 

33 def iconize(cls, directory: str, png_icon_path: str): # pragma: no cover 

34 """ 

35 Iconizes the directory using gio 

36 :param directory: The directory to iconize 

37 :param png_icon_path: The path to the png icon file 

38 :return: None 

39 """ 

40 Popen([ 

41 "gio", "set", "-t", "string", directory, 

42 "metadata::custom-icon", "file://" + png_icon_path 

43 ]).wait() 

44 

45 @classmethod 

46 def is_applicable(cls) -> bool: # pragma: no cover 

47 """ 

48 Checks if this procedure is applicable to the current system. 

49 The Gnome procedure is applicable if the system is running Linux 

50 as well as a Gnome environment, like the Gnome DE or Cinnamon 

51 :return: True if applicable, else False 

52 """ 

53 path_divider = ";" if sys.platform == "win32" else ":" 

54 paths = os.environ["PATH"].split(path_divider) 

55 gvfs_installed = False 

56 for path in paths: 

57 if os.access(os.path.join(path, "gio"), os.X_OK): 

58 gvfs_installed = True 

59 

60 gvfs_check = False 

61 if gvfs_installed: 

62 

63 try: 

64 gvfs_out = check_output([ 

65 "gio", "set", "-t", "string", ".", 

66 "metadata::custom-icon", "a"]).decode() 

67 except CalledProcessError: 

68 gvfs_out = "Not Supported" 

69 

70 if gvfs_out.rstrip().lstrip() == "": 

71 Popen(["gio", "set", "-t", "unset", ".", 

72 "metadata::custom-icon"]).wait() 

73 gvfs_check = True 

74 

75 try: 

76 return sys.platform.startswith("linux") \ 

77 and gvfs_installed and gvfs_check 

78 except KeyError: 

79 return False 

80 

81 else: 

82 return False