/
DIRv3.py
74 lines (58 loc) · 1.97 KB
/
DIRv3.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
# Desktop Icon Repair
# v2 using config file
##########
import os
import getpass
import shutil
from tkinter import *
class App():
def __init__(self,master):
self.message_frame = Frame(master)
self.message_frame.pack()
self.message_text = StringVar()
self.message_text.set('Icon repair completed.')
self.message_label = Label(self.message_frame, textvariable = self.message_text)
self.message_label.pack()
def read_config_file(filename):
icons_folder = ''
options = []
with open(filename, 'r') as opened:
readtext = opened.read()
lines = readtext.split('\n')
for line in lines:
if '[ICONS_FOLDER]' in line:
icons_folder = line[14:]
if '[OPTION]' in line:
option_text = line[8:]
split_option_text = option_text.split('%USERNAME%')
first = split_option_text[0]
second = split_option_text[1]
result = first + username + second
options.append(result)
return icons_folder, options
# Main
##########
# Get the username of the logged-in user.
username = getpass.getuser()
# Read where to copy icons from, and which places to copy to, from the .ini
config_file = 'dir.ini'
icons_folder, options = read_config_file(config_file)
icons = os.listdir(icons_folder)
# Things we won't try to copy as files.
fails = ['$RECYCLE.BIN','Applications by Subject']
for option in options:
for icon in icons:
if icon not in fails:
try:
shutil.copy(icons_folder + icon,option)
except:
print('failed on',icon)
try:
shutil.copytree(icons_folder + '/Applications by Subject',option + '/Applications by Subject')
except:
print('failed')
# Report.
root = Tk()
root.title('Desktop Icon Repair')
mainapp = App(root)
root.mainloop()