MCPcopy Create free account
hub / github.com/ActiveState/code / Expand

Function Expand

recipes/Python/577038_Simple_Buttonbar_Utility/recipe-577038.py:84–155  ·  view source on GitHub ↗

Replace {?} macros

(pCommand, pFilePath)

Source from the content-addressed store, hash-verified

82mCmds = {}
83
84def Expand(pCommand, pFilePath):
85 'Replace {?} macros'
86 lEndPos = pFilePath.rfind("\\")
87 lPath = pFilePath[0:lEndPos]
88 lFileName = pFilePath[lEndPos+1:]
89 lEndPos = lFileName.rfind(".")
90 lName = lFileName[:lEndPos]
91 lFilePart = lPath + "\\" + lName
92 lExtension = lFileName[lEndPos:]
93#
94 lTempFolder = "c:\\temp" # {t} <------------- Change these as necessary
95 lInstallFolder = "c:\\bin" # {i}
96 lBackupFolder = "c:\\_Backup" # {u}
97 lSourceFolder = "c:\\source" # {c}
98 lSystemFolder = "c:\\sys" # {y}
99 lWindowsFolder = "c:\\windows\\system32" # {w}
100 lArchiveFolder = "j:\\_Backup" # {v}
101 lLibraryFolder = "c:\\Library" # {l}
102 lProgramFolder = "c:\\Program Files" # {g}
103
104 lCommand = pCommand
105 lPos = lCommand.rfind("{a}")
106 if lPos > 0:
107 lCommand = lCommand.replace("{a}",pFilePath)
108 lPos = lCommand.rfind("{b}")
109 if lPos > 0:
110 lCommand = lCommand.replace("{b}",lFilePart)
111 lPos = lCommand.rfind("{p}")
112 if lPos > 0:
113 lCommand = lCommand.replace("{p}",lPath)
114 lPos = lCommand.rfind("{f}")
115 if lPos > 0:
116 lCommand = lCommand.replace("{f}",lFileName)
117 lPos = lCommand.rfind("{n}")
118 if lPos > 0:
119 lCommand = lCommand.replace("{n}",lName)
120 lPos = lCommand.rfind("{e}")
121 if lPos > 0:
122 lCommand = lCommand.replace("{e}",lExtension)
123
124 lPos = lCommand.rfind("%1")
125 if lPos > 0:
126 lCommand = lCommand.replace("%1",pFileName)
127
128 lPos = lCommand.rfind("{t}")
129 if lPos > 0:
130 lCommand = lCommand.replace("{t}",lTempFolder)
131 lPos = lCommand.rfind("{i}")
132 if lPos > 0:
133 lCommand = lCommand.replace("{i}",lInstallFolder)
134 lPos = lCommand.rfind("{u}")
135 if lPos > 0:
136 lCommand = lCommand.replace("{u}",lBackupFolder)
137 lPos = lCommand.rfind("{o}")
138 if lPos > 0:
139 lCommand = lCommand.replace("{o}",lSourceFolder)
140 lPos = lCommand.rfind("{y}")
141 if lPos > 0:

Callers 1

BuildFunction · 0.70

Calls 2

rfindMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected