Extract command from file and replace all macros pArgs -- Args passed to program except file path #!key and any arguments pFilePath -- File to use in macro expansion pSearchPath -- File to scan for command ' pCount -- Number of lines at the s
(pArgs, pFilePath, pSearchPath, pCount, pSep='!!', pDefault='#!', pList=False, pWidth=15, pVerbose=False)
| 156 | |
| 157 | |
| 158 | def Expand(pArgs, pFilePath, pSearchPath, pCount, pSep='!!', pDefault='#!', pList=False, pWidth=15, pVerbose=False): |
| 159 | ''' |
| 160 | Extract command from file and replace all macros |
| 161 | pArgs -- Args passed to program except file path |
| 162 | #!key and any arguments |
| 163 | pFilePath -- File to use in macro expansion |
| 164 | pSearchPath -- File to scan for command ' |
| 165 | pCount -- Number of lines at the start of the file to scan |
| 166 | pSep -- String used to identify end of command, extra arguments will not be appended |
| 167 | pList -- True to display available commands |
| 168 | pWidth -- Number of columns to scan for #! |
| 169 | ''' |
| 170 | # ---- Find command |
| 171 | if len(pArgs[1]) == 0: |
| 172 | lKey = pDefault |
| 173 | lStart = 1 |
| 174 | elif pArgs[1].startswith(pDefault): |
| 175 | lKey = pArgs[1] |
| 176 | lStart = 2 |
| 177 | else: |
| 178 | lKey = pDefault |
| 179 | lStart = 1 |
| 180 | |
| 181 | lCommand = FindCommand(lKey, pFilePath, pSearchPath, pCount, pDefault=pDefault, pList=pList, pWidth=pWidth, pVerbose=pVerbose) |
| 182 | |
| 183 | if lCommand == '': |
| 184 | print 'pb.py Command', lKey, 'not found' |
| 185 | |
| 186 | # ---- Expand and insert/append any passed arguments |
| 187 | # Arguments on original pb.py command line will replace {} from left to right |
| 188 | # otherwise they will be appended to the end of the command |
| 189 | if len(lCommand) > 0: |
| 190 | if len(pArgs) > lStart: |
| 191 | for lArg in pArgs[lStart:]: |
| 192 | if lArg.find('{') >= 0: |
| 193 | lArg = Do2.ExpandArg(lArg, pFilePath, '') |
| 194 | lPos = lCommand.find('{}') |
| 195 | if lPos >= 0: |
| 196 | lCommand = lCommand[0:lPos] + lArg + lCommand[lPos+2:] |
| 197 | else: |
| 198 | lCommand += ' ' + lArg |
| 199 | |
| 200 | # ---- Prevent unwanted arguments appended to command |
| 201 | lPos = lCommand.rfind(pSep) |
| 202 | if lPos > 0: |
| 203 | lCommand = lCommand[0:lPos] |
| 204 | |
| 205 | # ---- Expand all remaining macros |
| 206 | if lCommand.find('{') >= 0: |
| 207 | lCommand = Do.Expand(lCommand, pFilePath) |
| 208 | return lCommand |
| 209 | |
| 210 | def submitnow(pArgs, pFilePath, pSearchPath, pCount, pList=False, pExtract=False, pVerbose=False, pWidth=15): |
| 211 | 'Expand and submit command' |
no test coverage detected