1#!/usr/bin/env python3

2# -*- coding: utf-8 -*-

3#

4# color_depth_info.py

5#

6# This file is part of Checkbox.

7#

8# Copyright 2012 Canonical Ltd.

9#

10# Authors: Alberto Milone <alberto.milone@canonical.com>

11#

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

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

14# as published by the Free Software Foundation.

15

16#

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

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

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

20# GNU General Public License for more details.

21#

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

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

24

25"""

26 The get_color_depth got information from Xorg.*.log

27"""

28

29 import os

30 import re

31 import sys

32

33 from glob import glob

34

35

36 def get_color_depth(log_dir="/var/log/"):

37 """Return color depth and pixmap format"""

38

39 # find the most recent X.org log

40 depth = 8

41 pixmap_format = 8

42 log = None

43 max_time = 0

44 for log in glob(os.path.join(log_dir, "Xorg.*.log")):

45 mtime = os.stat(log).st_mtime

46 if mtime > max_time:

47 max_time = mtime

48 current_log = log

49 if current_log is None:

50 depth = 0

51 pixmap_format = 0

52 return (depth, pixmap_format)

53

54 with open(current_log, "rb") as stream:

55 for match in re.finditer(

56 r"Depth (\d+) pixmap format is (\d+) bpp", str(stream.read())

57 ):

58 depth = int(match.group(1))

59 pixmap_format = int(match.group(2))

60

61 return (depth, pixmap_format)

62

63

64 def main():

65 """main function"""

66

67 depth, pixmap_format = get_color_depth()

68 print(

69 "Color Depth: {0}\nPixmap Format: {1} bpp".format(depth, pixmap_format)

70 )

71 if depth == 8:

72 return 1

73 return 0

74

75

76 if __name__ == "__main__":

77 sys.exit(main())