-
Notifications
You must be signed in to change notification settings - Fork 0
/
desktop_spotlight.py
153 lines (117 loc) · 5.25 KB
/
desktop_spotlight.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
from os import chdir, listdir, path, getcwd
import sys
import config
import constants
import shutil
if constants.flags.DEL_FLAG in sys.argv:
config.fs.rm_from_startup(constants.BAT_FILE_NAME)
config.scheduler.delete_task(constants.TASK_NAME)
if path.exists(constants.DATA_PATH):
shutil.rmtree(constants.DATA_PATH)
print("All Desktop Spotlight files are removed.")
else:
print("No Desktop Spotlight files found.")
sys.exit(0)
if config.fs.verify_files(sys.argv):
import handlers
sys.excepthook = handlers.error_handler
handlers.flags_handler.handle_flags(sys.argv)
import utils
from utils import py_logger
else:
print("Some files are missing or corrupted")
print("Try to fix it using '-r' flag")
sys.exit(-1)
log = py_logger.get_logger(__name__, "debug")
# Choose what to apply i.e. slideshow (1) or static (2) or sync (3)
choice = constants.SYNC
SCRIPT_PATH = path.join(constants.SCRIPT_DIRECTORY, constants.SCRIPT_NAME)
if constants.TAKE_INPUT:
prompt_text = "Enter wallpaper mode [ sync | static | slideshow ]: "
choice = input(prompt_text)
if choice not in constants.CHOICES.keys():
print("Invalid choice, terminating...")
sys.exit(-2)
constants.CHOICE = constants.CHOICES[choice]
approval = ["y", "yes"]
denial = ["n", "no"]
valid_approval_inputs = ["y", "n", "yes", "no"]
to_save = input("Save your choice? [y/n] : ")
to_save = to_save.lower()
if to_save in valid_approval_inputs:
if to_save in approval:
with open(constants.PREFERENCE_FILE, "w+") as pref_file:
pref_file.write(choice)
elif to_save in denial:
save_choice = input("\n"
"[Specify the mode you want to apply by default \n"
"when running DesktopSpotlight from next time]\n"
"Enter mode: ")
if save_choice in constants.CHOICES.keys():
with open(constants.PREFERENCE_FILE, "w+") as pref_file:
pref_file.write(save_choice)
else:
print("Invalid choice.")
else:
print("Invalid input.")
to_update_startup_file = input("Use this preference at windows startup? [y/n] : ")
to_update_startup_file = to_update_startup_file.lower()
if to_update_startup_file in valid_approval_inputs:
if to_update_startup_file in approval:
constants.UPDATE_STARTUP_FILE = True
with open(constants.STARTUP_FILE, "w+") as pref_file:
pref_file.write(choice)
elif to_update_startup_file in denial:
save_choice = input("\n"
"[Specify the mode you want to apply by default \n"
"after windows startup]\n"
"Enter mode: ")
if save_choice in constants.CHOICES.keys():
with open(constants.STARTUP_FILE, "w+") as pref_file:
pref_file.write(save_choice)
else:
print("Invalid choice.")
else:
print("Invalid input.")
if constants.TAKE_INPUT:
flags = input("Enter any flags (separate with single space): ")
flags = flags.split(" ")
ignore_flags = [constants.flags.SYNC_FLAG, constants.flags.STATIC_FLAG, constants.flags.SLIDESHOW_FLAG]
handlers.flags_handler.handle_flags(flags, exclude=ignore_flags)
if constants.STARTUP_WAY == constants.START_BY_BATCH:
config.scheduler.delete_task(constants.TASK_NAME)
# Add a batch file to startup folder in windows
config.fs.add_to_startup(sys.argv, SCRIPT_PATH, constants.BAT_FILE_NAME, force=True)
elif constants.STARTUP_WAY == constants.START_BY_SCHEDULER:
config.fs.rm_from_startup(constants.BAT_FILE_NAME)
# Create a task in Task Scheduler
config.scheduler.create_task(sys.argv, SCRIPT_PATH, constants.TASK_NAME)
# if "-r" in sys.argv or constants.UPDATE_STARTUP_TASK:
# config.scheduler.create_task(sys.argv, SCRIPT_PATH, constants.TASK_NAME)
# else:
# config.scheduler.create_task(sys.argv, SCRIPT_PATH, constants.TASK_NAME)
# print("Current working directory:", os.getcwd())
log.info(f"Current working directory: {getcwd()}")
# Fetch all possible wallpapers
possible_wallpapers = utils.misc.scan_wallpapers()
# Change current directory to 'images' directory
chdir(constants.IMAGES_PATH)
# Save all wallpapers to data path
wallpapers = utils.save_wallpapers(possible_wallpapers)
# Get all file names from 'images' directory
images = listdir(getcwd())
# Filter wallpapers
filtered_wallpapers = utils.misc.filter_wallpapers(wallpapers)
try:
constants.CHOICE = constants.CHOICES[choice]
except KeyError:
pass
if constants.CHOICE == constants.SLIDE_SHOW:
utils.ld_wallpapers.start_slideshow(filtered_wallpapers)
elif constants.CHOICE == constants.STATIC:
utils.ld_wallpapers.set_static(filtered_wallpapers)
elif constants.CHOICE == constants.SYNC:
utils.ld_wallpapers.sync(filtered_wallpapers)
if constants.flags.NOSAVE_FLAG not in sys.argv:
input("Press enter to exit.\n")