-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphics
More file actions
executable file
·60 lines (53 loc) · 2.09 KB
/
graphics
File metadata and controls
executable file
·60 lines (53 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Jared Daniel Carbonell Recomendable.
import sys
import subprocess
def run(flag=0):
'''Carry out the process of switching graphics card. If NVIDIA is being
used, the graphics card is switched to Intel, and vice versa.'''
result = str(subprocess.check_output(['prime-select', 'query']))
if 'intel' in result:
result = 'intel'
print('Currently Active Graphics Card: Intel (Integrated)')
elif 'nvidia' in result:
result = 'nvidia'
print('Currently Active Graphics Card: NVIDIA (Dedicated)')
else:
flag = 0
print('Failed to get information on the currently active graphics card.')
print('Exiting...')
if flag == 1:
start_message = 'Attempting to switch to {} Graphics Card.'
start_command = 'x-terminal-emulator -e "echo FROM {} TO {} && sudo prime-select {}"'
end_message1 = 'The switch will be carried out in a new terminal window.'
end_message2 = 'After the switch, please restart your system for the changes to take effect.'
if result == 'intel':
print(start_message.format('NVIDIA (Dedicated)'))
to_run = start_command.format('intel', 'nvidia', 'nvidia')
elif result == 'nvidia':
print(start_message.format('Intel (Integrated)'))
to_run = start_command.format('nvidia', 'intel', 'intel')
print()
print(end_message1)
print(end_message2)
print()
subprocess.run(['bash', '-c', to_run])
def show_help():
'''Show the help documentation for the program.'''
help_doc = '''Usage: graphics [options]
Options:
-h, --help show this help message and exit
-s, --switch switch to the currently inactive graphics card
-v, --view get the currently active graphics card'''
print(help_doc)
if __name__ == '__main__':
if len(sys.argv) == 2:
if sys.argv[1] in ('-s', '--switch'):
run(1)
elif sys.argv[1] in ('-v', '--view'):
run()
else:
show_help()
else:
show_help()