From 3cc0bde4692104af9a44737da3a953a3802cb8fe Mon Sep 17 00:00:00 2001 From: Sylvain Pineau Date: Mon, 13 Jul 2020 10:51:57 +0200 Subject: bin:fresh_rate_info -> fresh_rate_info.py --- bin/fresh_rate_info | 76 -------------------------------------------------- bin/fresh_rate_info.py | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 76 deletions(-) delete mode 100755 bin/fresh_rate_info create mode 100755 bin/fresh_rate_info.py (limited to 'bin') diff --git a/bin/fresh_rate_info b/bin/fresh_rate_info deleted file mode 100755 index 838e5a6..0000000 --- a/bin/fresh_rate_info +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# fresh_rate_info -# -# This file is part of Checkbox. -# -# Copyright 2012 Canonical Ltd. -# -# Authors: Shawn Wang -# -# Checkbox is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, -# as published by the Free Software Foundation. - -# -# Checkbox 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 Checkbox. If not, see . - -""" - The fresh_rate_info got information from xrandr -""" - -import re -import sys -import subprocess - - -def xrandr_paser(data=None): - - '''return an array(xrandrs)''' - - resolution = None - xrandrs = list() - for line in str(data).split('\n'): - for match in re.finditer('(.+) connected (\d+x\d+)\+', line): - connector = match.group(1) - resolution = match.group(2) - break - if resolution is None: - continue - for match in re.finditer('{0}\s+(.+)\*'.format(resolution), - line): - refresh_rate = match.group(1) - xrandr = {'connector': connector, - 'resolution': resolution, - 'refresh_rate': refresh_rate} - xrandrs.append(xrandr) - - return xrandrs - - -def main(): - - '''main function''' - - try: - data = subprocess.check_output(['xrandr', '--current'], - universal_newlines=True) - except subprocess.CalledProcessError as exc: - return exc.returncode - - xrandrs = xrandr_paser(data) - for xrandr in xrandrs: - output_str = "Connector({0}):\t Resolution: {1} \t RefreshRate: {2}" - print(output_str.format(xrandr['connector'], - xrandr['resolution'], - xrandr['refresh_rate'])) - -if __name__ == '__main__': - sys.exit(main()) diff --git a/bin/fresh_rate_info.py b/bin/fresh_rate_info.py new file mode 100755 index 0000000..43a8f2a --- /dev/null +++ b/bin/fresh_rate_info.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# fresh_rate_info.py +# +# This file is part of Checkbox. +# +# Copyright 2012 Canonical Ltd. +# +# Authors: Shawn Wang +# +# Checkbox is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, +# as published by the Free Software Foundation. + +# +# Checkbox 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 Checkbox. If not, see . + +""" + The fresh_rate_info.py got information from xrandr +""" + +import re +import sys +import subprocess + + +def xrandr_paser(data=None): + + '''return an array(xrandrs)''' + + resolution = None + xrandrs = list() + for line in str(data).split('\n'): + for match in re.finditer('(.+) connected (\d+x\d+)\+', line): + connector = match.group(1) + resolution = match.group(2) + break + if resolution is None: + continue + for match in re.finditer('{0}\s+(.+)\*'.format(resolution), + line): + refresh_rate = match.group(1) + xrandr = {'connector': connector, + 'resolution': resolution, + 'refresh_rate': refresh_rate} + xrandrs.append(xrandr) + + return xrandrs + + +def main(): + + '''main function''' + + try: + data = subprocess.check_output(['xrandr', '--current'], + universal_newlines=True) + except subprocess.CalledProcessError as exc: + return exc.returncode + + xrandrs = xrandr_paser(data) + for xrandr in xrandrs: + output_str = "Connector({0}):\t Resolution: {1} \t RefreshRate: {2}" + print(output_str.format(xrandr['connector'], + xrandr['resolution'], + xrandr['refresh_rate'])) + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3