-
Notifications
You must be signed in to change notification settings - Fork 2
/
goto_aux
executable file
·177 lines (154 loc) · 6.15 KB
/
goto_aux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/python
import os
import sys
def getArg(n):
try:
return sys.argv[n]
except:
return False
def usage():
return """Usage: goto command [param]\\n
\\nCommands can be one of the following:\\n
\\troot \\t\\t\\tcd into the root directory of your installation.\\n
\\tapp \\t\\t\\tcd into the app/ directory.\\n
\\tskin [theme] \\t\\tcd into the skin/ directory. If theme is provided cd into skin/frontend/theme/default.\\n
\\tdesign [theme] \\t\\tcd into the app/design directory. If theme is provided cd into app/design/frontend/theme/default.\\n
\\tfrontend [theme] \\tcd into the app/design/frontend/ directory. If theme is provided cd into app/design/frontend/theme/default.\\n
\\ttemplate theme \\t\\tcd into the app/design/frontend/theme/default/template/ directory.\\n
\\tlayout theme \\t\\tcd into the app/design/frontend/theme/default/layout/ directory.\\n
\\tcode [codepool] \\tcd into the app/code/codepool directory. Can be local, community or core.\\n
\\tmodman [module] \\tcd into the .modman directory. If module is provided cd into .modman/module/.\\n
\\tlog \\t\\t\\tcd into the var/log/ directory.\\n
\\tswitch [package] \\tcd into another package, with the eqiuvilant path to your current working directory. If package is provided use this package, use 'base' otherwise.\\n
\\thelp \\t\\t\\tprint this usage message."""
def error(msg):
sys.stderr.write(msg + '\n')
sys.stderr.flush()
def isRootPath(path):
contents = os.listdir(path)
results = map(lambda x: x in contents, ['app', 'skin'])
return all(results);
def getRootPath():
while True:
cwd = os.getcwd()
if cwd == '/':
error('Magento root not found.')
return invocationPath
if isRootPath(cwd):
return cwd
else:
os.chdir('../');
def expandTheme(theme, directory):
path = ''
if directory == 'skin':
path += rootPath + '/skin/frontend/'
elif directory == 'app':
path += rootPath + '/app/design/frontend/'
packages = os.listdir(path)
expandedTheme = False
if theme not in packages:
res = filter(lambda x:x.startswith(theme), packages)
if len(res) == 1:
# We've found a single theme which is a shortcut. E.g. goto template b == goto template base
expandedTheme = res[0]
elif len(res) == 0:
error("There were no themes which match %s" % theme)
else:
# If there are more than one, let them know
error("Several packages match this shorthand: %s. Please be more specific." % (", ".join(res)));
return expandedTheme
def getFilePath(loc):
if loc == 'root':
print 'cd ' + rootPath
elif loc == 'app':
print 'cd ' + rootPath + '/app/'
elif loc == 'skin':
theme = getArg(2)
if theme == False:
print 'cd ' + rootPath + '/skin/'
else:
expandedTheme = expandTheme(theme, 'skin')
if expandedTheme:
print 'cd ' + rootPath + '/skin/frontend/' + expandedTheme + '/default'
elif loc == 'design':
theme = getArg(2)
if theme == False:
print 'cd ' + rootPath + '/app/design/'
else:
expandedTheme = expandTheme(theme, 'app')
if expandedTheme:
print 'cd ' + rootPath + '/app/design/frontend/' + expandedTheme
elif loc == 'frontend':
theme = getArg(2)
if theme == False:
print 'cd ' + rootPath + '/app/design/frontend/'
else:
expandedTheme = expandTheme(theme, 'app')
if expandedTheme:
print 'cd ' + rootPath + '/app/design/frontend/' + expandedTheme
elif loc == 'template':
theme = getArg(2)
if theme == False:
error('No theme provided')
print 'cd ' + rootPath;
else:
expandedTheme = expandTheme(theme, 'app')
if expandedTheme:
print 'cd ' + rootPath + '/app/design/frontend/' + expandedTheme + '/default/template/'
elif loc == 'layout':
theme = getArg(2)
if theme == False:
error('No theme provided')
print 'cd ' + rootPath;
else:
expandedTheme = expandTheme(theme, 'app')
if expandedTheme:
print 'cd ' + rootPath + '/app/design/frontend/' + expandedTheme + '/default/layout/'
elif loc == 'code':
codebase = getArg(2)
if codebase == False:
print 'cd ' + rootPath + '/app/code/'
else:
print 'cd ' + rootPath + '/app/code/' + codebase
elif loc == 'modman':
module = getArg(2)
if module == False:
print 'cd ' + rootPath + '/.modman/'
else:
print 'cd ' + rootPath + '/.modman/' + module
elif loc == 'log':
filePath = rootPath + '/var/log/'
print 'cd ' + filePath
elif loc == 'base' or loc == 'switch':
#print invocationPath
filepath = invocationPath.split('/')
theme = getArg(2)
if 'frontend' in filepath:
for i in [i for i,x in enumerate(filepath) if x == 'frontend']:
if theme:
if 'app' in filepath:
theme = expandTheme(theme, 'app')
elif 'skin' in filepath:
theme = expandTheme(theme, 'skin')
filepath[i+1] = theme
else:
theme = 'base'
filepath[i+1] = 'base'
if theme:
filepath = '/'.join(filepath)
break;
if theme:
print 'cd ' + filepath;
else:
error('Not in a template directory.')
print 'cd ' + invocationPath
elif loc == 'help' or loc == '--help':
print 'echo "' + usage() + '"'
else:
error('Invalid option passed.\n')
print 'echo "%s" && cd %s' % (usage(), invocationPath)
# BEGIN SCRIPT
loc = getArg(1);
invocationPath = os.getcwd()
rootPath = getRootPath()
getFilePath(loc)