-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremove_int.py
132 lines (120 loc) · 2.91 KB
/
remove_int.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
#!/usr/bin/python
import curses
import sys
import string
import locale
import os
class Screen:
def __init__(self):
locale.setlocale(locale.LC_ALL,"")
self.scr=curses.initscr()
curses.noecho()
curses.cbreak()
self.scr.keypad(1)
def destroy(self):
curses.nocbreak()
self.scr.keypad(0)
curses.echo()
curses.endwin()
def select(self, variants):
if len(variants)<2:
return
if len(variants)>9:
return
while 1:
self.scr.clear()
i=1
for fn in variants:
self.scr.addstr("%d) " % i)
self.scr.addstr(fn)
self.scr.addstr("\n")
i+=1
self.scr.addstr(25, 0, "(%d of %d) Which will stay (1..9, n, q):" %(self.curpos, self.allcount))
self.scr.refresh()
c = self.scr.getch()
if c in(ord('q'),ord('Q')):
self.destroy()
sys.exit(0)
if c in(ord('n'), ord('N'), ord('S'), ord('s')):
#just skip
return
#n=string.atoi(c)
if c<=ord('9') and c>ord('0'):
n=c-ord('0')-1
if n<len(variants):
i=0
self.scr.addstr(25, 0, "Is it correct? (y/N) ")
self.scr.refresh()
win=curses.newwin(12, 180, 11, 0)
for fn in variants:
if i!=n:
win.addstr(i, 0, "rm %s" % (variants[i]))
i+=1
win.refresh()
c=win.getch()
if c in(ord('y'), ord('Y')):
i=0
for fn in variants:
if i!=n:
try:
os.remove(variants[i])
except:
print "shit"
i+=1
return
win.clear()
win.refresh()
del win
def load(self, fname):
fl=file(fname, "r")
self.groups=list()
cur_group=list()
for str in fl:
if str=="\n":
self.groups.append(cur_group)
del cur_group
cur_group=list()
else:
cur_group.append(str.rstrip())
if len(cur_group)!=0:
self.groups.append(cur_group)
fl.close()
def go(self):
self.allcount=len(self.groups)
self.curpos=1
for gr in self.groups:
self.select(gr)
self.curpos+=1
def check_librusec(self, variants):
found=-1
i=0
for t in variants:
if t.find("SpeccyMania/Games")!=-1:
found=i
break
i+=1
if found!=-1:
nl=list()
for t in variants:
if t.find("SpeccyMania/Games")==-1:
try:
#os.remove(t)
print "rm -f \""+t+"\""
except:
print "shit"
else:
nl.append(t)
variants=nl
return variants
def parse_librusec(self):
groups_tmp=list()
for gr in self.groups:
gr2=self.check_librusec(gr)
if len(gr2)>1:
groups_tmp.append(gr2)
self.groups=groups_tmp
s = Screen()
s.load(sys.argv[1])
s.parse_librusec()
#s.go()
s.destroy()