5 """ Base class of the operations.
9 # opName -- name of the operation
11 def __init__(self
, opName
):
17 def applyOp(self
, driver
):
18 """ Perform operation - intended for override in subclasses.
20 logging
.getLogger("OperationBase").error(
21 "OperationBase.applyOp called");
23 def addSelf(self
, opBundle
):
24 """ Helper callback for adding to a bundle.
26 opBundle
.internal_addOp(self
);
28 def subSelf(self
, opBundle
):
29 """ Helper callback for removing from a bundle.
31 opBundle
.internal_subOp(self
);
34 # ===========================================================================
37 class GroupingOperation(OperationBase
):
38 """ Group of operations.
40 If a group is added to a bundle all the operations in that group
41 will be added and likewise for removal.
42 Watch out when using multiple groups that contain the same operation,
43 there will only be one instance of the operation in the bundle and it
44 is removed when the first group that contains it is removed.
48 # opNameList -- list of operation names
50 def __init__(self
, opName
):
51 OperationBase
.__init
__(self
, opName
);
54 def applyOp(self
, driver
):
55 """ Do nothing -- all operations in this group were added individually.
57 logging
.getLogger("GroupingOperation").error(
58 "GroupingOperation.applyOp called.");
60 def addOp(self
, opName
):
61 """ Add an operation to this group
63 if opName
not in self
.opNameList
:
64 self
.opNameList
.append(opName
);
66 def subOp(self
, opName
):
67 """ Remove an operation from this group
69 if opName
in self
.opNameList
:
70 self
.opNameList
.remove(opName
);
72 # returns list of grouped operations
73 def getOpNameList(self
):
74 """ Get a list of operations in this group - names only
76 return self
.opNameList
;
78 # add all ops in this group in opBundle
79 def addSelf(self
, opBundle
):
80 """ Helper callback for adding to a bundle - adds all op in this group.
82 for opName
in self
.opNameList
:
83 opBundle
.addOp(opName
);
85 # remove all ops in this group from opBundle
86 def subSelf(self
, opBundle
):
87 """ Helper callback for removing from a bundle - removes all op
90 for opName
in self
.opNameList
:
91 opBundle
.subOp(opName
);
95 # ===========================================================================
98 class SimpleReplaceOperation(OperationBase
):
99 """ Perform a simple replace of one string with another.
103 # replaceString -- string to replace
104 # replacementString -- string to replace with
106 def __init__(self
, opName
, replace
, replacement
):
107 OperationBase
.__init
__(self
, opName
);
108 self
.replaceString
= replace
;
109 self
.replacementString
= replacement
;
111 def applyOp(self
, driver
):
112 """ perform the replacement on the file currently loaded by the driver.
114 log
= logging
.getLogger("SimpleReplaceOperation");
115 log
.debug(">> apply");
116 log
.info("Replace \"%s\" with \"%s\"." % (self
.replaceString
, self
.replacementString
));
117 fileContent
= driver
.getCurrFileContent();
118 fileContent
= fileContent
.replace(self
.replaceString
, self
.replacementString
);
119 driver
.setCurrFileContent(fileContent
);
120 log
.debug("<< apply");
122 def getReplace(self
):
123 return self
.replaceString
;
125 def getReplacement(self
):
126 return replacementString
;