changed: disable boost std::atomic use by default
[opensg.git] / Tools / convScript / Operations.py
blobfb9ec60d463414fdeef0d2be2a7563be56d2ef80
2 import logging;
4 class OperationBase:
5 """ Base class of the operations.
6 """
8 #### member
9 # opName -- name of the operation
11 def __init__(self, opName):
12 self.opName = opName;
14 def getName(self):
15 return self.opName;
17 def applyOp(self, driver):
18 """ Perform operation - intended for override in subclasses.
19 """
20 logging.getLogger("OperationBase").error(
21 "OperationBase.applyOp called");
23 def addSelf(self, opBundle):
24 """ Helper callback for adding to a bundle.
25 """
26 opBundle.internal_addOp(self);
28 def subSelf(self, opBundle):
29 """ Helper callback for removing from a bundle.
30 """
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.
45 """
47 #### member
48 # opNameList -- list of operation names
50 def __init__(self, opName):
51 OperationBase.__init__(self, opName);
52 self.opNameList = [];
54 def applyOp(self, driver):
55 """ Do nothing -- all operations in this group were added individually.
56 """
57 logging.getLogger("GroupingOperation").error(
58 "GroupingOperation.applyOp called.");
60 def addOp(self, opName):
61 """ Add an operation to this group
62 """
63 if opName not in self.opNameList:
64 self.opNameList.append(opName);
66 def subOp(self, opName):
67 """ Remove an operation from this group
68 """
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
75 """
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.
81 """
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
88 in this group.
89 """
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.
102 #### member
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;