-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremStartup.py
113 lines (87 loc) · 3.2 KB
/
remStartup.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
# IFTTT: Allows Google Home integration with a computer
# Copyright (C) 2019 Anguianoewi
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# NOTE: This script deletes files that are found in home folder
# to prevent event loops and potentially cause a system to become
# unmanageable. It is recommended to not remove this file from the
# code.
import configparser
from datetime import datetime
import os
from shutil import copyfile
def rem():
# config gets information from file,
# configRaw gets amount in group
config = configparser.ConfigParser()
configRaw = configparser.RawConfigParser()
# Read them files
config.read('files.ini')
configRaw.read('files.ini')
# Gets defines system path for command files
sysPath = config.get('MISC', 'FILES_LOCATION')
#defines save location
saveLoc = open('Log.txt', 'a+')
writeLog = saveLoc.write
# Gets commands and then is converted into command amounts
items = configRaw.items('FILES')
cmdAmt = len(items)
var1 = 0
# Checks for potential files that can cause loops at start.
for i in range(cmdAmt):
# assigns variable with string of a number to check for number
cmdNum = str(i)
f = config.get('FILES', cmdNum)
# Adds file append in case append varies
append = config.get('MISC', 'FILE_APPEND')
# Assigns file path by mixing a very lovely cocktail of abomination
path = (sysPath + f.lower() + append)
# Checks to see if file exists
if os.path.exists(path):
var1 = 1
# Declares file found in log
writeLog(datetime.now().isoformat(' ', 'seconds')
+ ': Startup - '
+ f
+ ' file found.\n')
# Deletes file
os.remove(path)
# Declares file deleted in log
writeLog(datetime.now().isoformat(' ', 'seconds')
+ ': Startup - '
+ f
+ ' file deleted.\n')
saveLoc.flush()
try:
for i in range(100):
num = str(i)
copyfile('Log.txt',config.get('MISC','LOG_BACKUP_'
+ num))
except:
pass
else:
continue
# This is for when no files are found at startup.
if var1 == 0:
writeLog(datetime.now().isoformat(' ', 'seconds')
+ ': Startup - No potential loop files declared found.\n')
saveLoc.flush()
try:
for i in range(100):
num = str(i)
copyfile('Log.txt',config.get('MISC','LOG_BACKUP_'
+ num))
except:
pass
# This is for when all files listed in files.ini are found
if var1 == 1:
writeLog(datetime.now().isoformat(' ', 'seconds')
+ ': Startup - All potential loop files declared are deleted.\n')
saveLoc.flush()
try:
for i in range(100):
num = str(i)
copyfile('Log.txt',config.get('MISC','LOG_BACKUP_'
+ num))
except:
pass