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

Function ExpandArg

recipes/Python/577440_extensiDopy__Win32/recipe-577440.py:61–103  ·  view source on GitHub ↗

Expand single command line argument

(pArg, pFilePath, pDefaultPath, pLeft='{', pSep=';', pQuote='"', 
                              pPref='{<-}', pJoin='\\')

Source from the content-addressed store, hash-verified

59 return lPath
60
61def ExpandArg(pArg, pFilePath, pDefaultPath, pLeft='{', pSep=';', pQuote='"',
62 pPref='{<-}', pJoin='\\'):
63 ''&#x27;
64 Expand single command line argument
65 ''&#x27;
66# Expand argument
67 if pArg.find(pLeft) >= 0:
68 lArg = Do.Expand(pArg, pFilePath)
69 else:
70 lArg = pArg
71
72# If starts with {<-} and single path scan parent folders for
73# first matching file. Each folder above specified path will
74# be checked until file is found.
75 if lArg.startswith(pPref) and lArg.find(pSep) < 0:
76 lArg = os.path.abspath(lArg[2:])
77 print 'Parent Search 1'
78 lArg = ParentSearch(lArg, pDefaultPath, pJoin=pJoin)
79
80# If multiple paths separated by pSep(';') select first valid path
81 lFound = ''
82 if lArg.find(pSep) >= 0:
83 lPaths = lArg.split(pSep)
84 for lPath in lPaths:
85 if lPath.startswith(pPref):
86 lPath = os.path.abspath(lPath[4:])
87 lPath = ParentSearch(lPath, pDefaultPath, pJoin=pJoin) # 01/19/11
88 if lPath == '': #
89 continue #
90 lPath = os.path.abspath(lPath)
91 if os.path.exists(lPath):
92 lFound = lPath
93 break
94 else:
95 lFound = os.path.abspath(pDefaultPath)
96 else:
97 lFound = lArg
98
99# If argument contains space enclose it within quotes
100 lFound = lFound.strip()
101 if lFound.find(' ') > 0 and lFound[0] != pQuote:
102 lFound = pQuote + lFound + pQuote
103 return lFound
104
105def submitnow(pCommand):
106 ''&#x27;

Callers 3

ExpandFunction · 0.85
recipe-577462.pyFile · 0.85
recipe-577440.pyFile · 0.85

Calls 6

ParentSearchFunction · 0.85
startswithMethod · 0.80
findMethod · 0.45
splitMethod · 0.45
existsMethod · 0.45
stripMethod · 0.45

Tested by

no test coverage detected