-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdpiswitch
executable file
·58 lines (45 loc) · 2.09 KB
/
dpiswitch
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
#! /usr/bin/env python3
import argparse
import os
import sys
from dpiswitchutils import validator, plasma, schema
from dpiswitchutils.config import get_default_config_filename_assert_exists, load_config_file
from dpiswitchutils.utils import *
parser = argparse.ArgumentParser(description="Command-line KDE Plasma DPI change utility")
parser.add_argument('--generate', action='store_true', help="Generate a profile based on the current settings")
parser.add_argument('--profile', help="Profile name being interacted with", required='--generate' in sys.argv)
parser.add_argument('--description', action='store', default='', help="Description for the profile to be generated")
parser.add_argument('--delete-profile', action='store_true', help="Remove a profile from the config file")
parser.add_argument('--config', default=get_default_config_filename_assert_exists(os.environ))
parser.add_argument('--no-logout', action='store_true', help="Do not end current desktop session")
args = parser.parse_args()
try:
validator.assert_valid_config(args.config, schema.SCHEMA)
config = load_config_file(args.config)
if args.generate:
try:
find_profile(config, args.profile)
raise Exception("Profile '{}' already exists".format(args.profile))
except ProfileNotFoundException:
pass
profile = plasma.read_current_profile()
profile["name"] = args.profile
profile["description"] = args.description
profile_save_to_file(profile, args.config)
print("Profile '{}' successfully generated!".format(args.profile))
print("Config file:", args.config)
exit(0)
profilename = args.profile if args.profile is not None else prompt_for_profile(config)
profile = find_profile(config, profilename)
if args.delete_profile:
profile_remove(profilename, args.config)
print("Profile successfully deleted")
exit(0)
plasma.apply_profile(profile)
if not args.no_logout:
plasma.session_end()
except Exception as e:
print("[ERR] {}".format(e))
exit(1)
except KeyboardInterrupt:
exit(0)