forked from Lunatixz/script.pseudotv.live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defrag.py
127 lines (103 loc) · 4.55 KB
/
defrag.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
def main():
pass
if __name__ == '__main__':
main()
import os, sys, re, shutil
import xbmc, xbmcgui, xbmcaddon, xbmcvfs
from resources.lib.Globals import *
from resources.lib.FileAccess import *
settingsFile = xbmc.translatePath(os.path.join(SETTINGS_LOC, 'settings2.xml'))
nsettingsFile = xbmc.translatePath(os.path.join(SETTINGS_LOC, 'new_settings2.xml'))
OpnFil = FileAccess.open(settingsFile, "r")
WrtFil = FileAccess.open(settingsFile, "w")
WrtFil.write('<settings> \n')
# Number of total lines in Settings2.xml file
nr_of_lines = len(OpnFil.readlines())
# Procedure to get the total number of channels for this Settings2.xml file
# High_Chan_Num variable will be the highest channel for the user
# ChanNum variable is used to compare the current input channel with the
# current highest channel (High_Chan_Num)
High_Chan_Num = 0
OpnFil.seek(0, 2) # Start file at the first line
for line in range(1, nr_of_lines): # Equal length of file
Xstring = str(OpnFil.readlines()) #Input line as string from Settings2.xml file
ins = Xstring.split("_") # Split the line into parts using "_" delimeter
# If the first part <> this string, then get next line
if ins[0] == " <setting id=" + chr(34) + "Channel":
n=ins[1] # assign variable to channel # string
ChanNum=int(n) # convert Channel Number to integer
if ChanNum > High_Chan_Num: #If > High_Chan_Num then
High_Chan_Num=ChanNum # assign to High_Chan_Num
High_Chan_Num = High_Chan_Num + 1 #Add 1 for following procedures.
for Num_Pos_Chan in range(1, High_Chan_Num): # Equal number of possible channels
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_type"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2) # Start file at the first line
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_1"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_2"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_3"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_4"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_rule"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_changed"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_time"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_SetResetTime"
Xstring = OpnFil.readlines()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0, 2)
for line in range(1, nr_of_lines): # Equal length of file
#Search_Item_A = "LastExitTime"
#Search_Item_B = "LastResetTime"
Xstring = str(OpnFil.readlines())
if re.search("LastExitTime", Xstring, re.I):
WrtFil.write (Xstring)
elif re.search("LastResetTime", Xstring, re.I):
WrtFil.write (Xstring)
WrtFil.write('</settings> \n')
OpnFil.close()
WrtFil.close()
# try:
xbmcvfs.delete(settingsFile)
FileAccess.rename(nsettingsFile, settingsFile)
# except:
# pass