forked from DrSpaceMonkey/script.pseudotv.live
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defrag.py
145 lines (118 loc) · 5.02 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#-------------------------------------------------------------------------------
# Name: module2
# Purpose:
#
# Author: strtmkurt
#
# Created: 22/07/2013
# Copyright: (c) strtmkurt 2013
# Licence: <your licence>
#-------------------------------------------------------------------------------
def main():
pass
import re
import os
import xbmcaddon, xbmc, xbmcgui
from resources.lib.Globals import *
from resources.lib.Settings import *
from resources.lib.FileAccess import FileAccess
flename = xbmc.translatePath(os.path.join(Globals.SETTINGS_LOC, 'settings2.xml'))
flenname = xbmc.translatePath(os.path.join(Globals.SETTINGS_LOC, 'new_settings2.xml'))
OpnFil = FileAccess.open(flename, "rb")
WrtFil = FileAccess.open(flename, "w")
WrtFil.write('<settings> \n')
WrtFil.write(' ' + '<setting id="Version" value="2.1.0" />\n')
# Number of total lines in Settings2.xml file
nr_of_lines = sum(1 for line in FileAccess.open(flename))
# def simplecount(filename):
# lines = 0
# for line in FileAccess.open(flename):
# lines += 1
# return nr_of_lines
# 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) # Start file at the first line
for line in range(1, nr_of_lines): # Equal length of file
Xstring = OpnFil.readline() #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)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_type"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0) # 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.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_2"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_3"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_4"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_rule"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_changed"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_time"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
Search_Item = "Channel_" + str(Num_Pos_Chan) + "_SetResetTime"
Xstring = OpnFil.readline()
if re.search(Search_Item, Xstring, re.I):
WrtFil.write (Xstring)
OpnFil.seek(0)
for line in range(1, nr_of_lines): # Equal length of file
#Search_Item_A = "LastExitTime"
#Search_Item_B = "LastResetTime"
Xstring = OpnFil.readline()
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()
os.remove (flename)
FileAccess.rename (flenname, flename)
if __name__ == '__main__':
main()