-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebase_help.py
More file actions
executable file
·59 lines (51 loc) · 1.51 KB
/
rebase_help.py
File metadata and controls
executable file
·59 lines (51 loc) · 1.51 KB
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
#!/usr/bin/python
import sys
import os
import re
import copy
import commands
p1 = re.compile(r'\n')
class rebase:
def __init__(self, fname):
self.slists = []
self.elists = []
self.fname = fname
self.dicts = {}
pass
def replace_regions(self,start,end):
ret = commands.getstatusoutput("grep -n " + start + " " + self.fname + "| grep -v \"========\"| cut -d : -f 1")
if (ret[0] == 0):
temp = ret[1:]
self.slists = p1.split(temp[0])
print 'start list',self.slists
del ret
ret = commands.getstatusoutput("grep -n " + end + " " + self.fname + "| cut -d : -f 1")
if (ret[0] == 0):
temp = ret[1:]
self.elists = p1.split(temp[0])
del ret
print 'end list',self.elists
if (len(self.slists) != len(self.elists)):
print "file match error"
return -1
self.dicts = dict(zip(self.slists,self.elists))
print "dictions", self.dicts
for i in self.dicts:
command = "sed " + "-i " +"\'" + i + "," + self.dicts[i] + "s/^.*/QWERTYUI/\'" + " " + self.fname
ret = commands.getstatusoutput(command)
del self.dicts
del self.slists
del self.elists
command = "sed -i " + "\'/" + "QWERTYUI" + "/d\'" + " " + self.fname
print command
ret = commands.getstatusoutput(command)
return 0
def replace_heads(self,head):
command = "sed -i " + "\'/" + head + "/d\'" + " " + self.fname
print command
ret = commands.getstatusoutput(command)
myrebase = rebase(sys.argv[1])
ret = myrebase.replace_regions("=======","\>\>\>\>\>\>\>")
if (ret != 0):
sys.exit(1)
myrebase.replace_heads("<<<<<<")