This file is indexed.

/usr/bin/coily is in python-springpython 1.2.0+ds-2build1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/python
"""
   Copyright 2006-2009 SpringSource (http://springsource.com), All Rights Reserved

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.       
"""
__version__ = "1.2.0.FINAL"

import os
import re
import sys
import tarfile
import time
import getopt
import shutil
import urllib
from datetime import datetime

############################################################################
# Get external properties and load into a dictionary. NOTE: These properties
# files mimic Java props files.
############################################################################

p = {}
p["plugindir"] = os.path.expanduser("~") + "/.springpython"
sys.path.append(p["plugindir"])

if not os.path.exists(p["plugindir"]):
    os.makedirs(p["plugindir"])

############################################################################
# Statically defined functions.
############################################################################

def plugin_path(name):
    return p["plugindir"] + "/%s" % name

def list_installed_plugins():
    print "Looking for plugins in %s..." % p["plugindir"]
    if not os.path.exists(p["plugindir"]):
        os.makedirs(p["plugindir"])
    print "Currently installed plugins:"
    for plugin in os.listdir(p["plugindir"]):
        try:
            if hasattr(p[plugin], "create"):
                print "\t--" + plugin + " [name]"+ "\t"*(3-len(plugin)/8) + p[plugin].__description__
            else:
                print "\t--" + plugin + "\t"*(4-len(plugin)/8) + p[plugin].__description__
        except KeyError:
            print "\t%s is not valid plugin" % plugin
        except AttributeError:
            print "\t%s is not a valid plugin" % plugin

def list_available_plugins():
    modules = get_modules_from_s3()
    print "S3 from SpringSource has..."
    for key in modules:
        for rev in modules[key]:
            if __version__ in rev[1]:
                print "\t%s\t%s" % (key, rev[1])

def install_plugin(name):
    """Go through a series of options to look for Spring Python modules to download."""
    if not os.path.exists(plugin_path(name)):
        print "Installing plugin %s to %s" % (name, p["plugindir"])
        if fetch_from_s3(name):
            print "Found %s online. Installing." % name
            return
        if fetch_locally(name):
            print "Found %s locally. Installing." % name
            return
        print "Couldn't find %s anywhere!" % name
    else:
        print "%s is already installed. We do NOT support automated upgrades." % name

def get_modules_from_s3():
    """Read the S3 site for information about existing modules."""
    info = ""
    for bucket in ["milestone", "release"]:
        url = "http://s3browse.springsource.com/browse/dist.springframework.org/%s/EXTPY" % bucket
        info += urllib.urlopen(url).read()
    #print info
    #return []
    #choicesR = re.compile('<a href="/getObject/(.*?)">(.*?)</a>.*?<td align="right">(.*?)</td>.*?<td align="right">(.*?)</td>', re.DOTALL)
    choicesR = re.compile(r'<td class="name-column"><a href="(.*?)">(.*?)</a>', re.DOTALL)
    match = choicesR.findall(info)
    converted = []
    for item in match:
        #print "Checking out %s" % str(item)
        if "springpython-plugin" not in item[0]: continue
        if item[0].endswith(".sha1"): continue 
        #print "Parsing %s" % item[0]
        converted.append(item)
        #t = time.strptime(item[3], "%Y-%m-%d %H:%M")
        #d = datetime(year=t.tm_year, month=t.tm_mon, day=t.tm_mday, hour=t.tm_hour, minute=t.tm_min)
        #converted.append(("http://s3.amazonaws.com/" + item[0], item[1], item[2]+"K", item[3], d))
    modules = {}
    baseR = re.compile("springpython-plugin-([a-zA-Z-]*)[-.]([0-9a-zA-Z]+.*).tar.gz")
    for item in converted:
        try:
            modules[baseR.match(item[1]).group(1)].append(item)
        except KeyError:
            modules[baseR.match(item[1]).group(1)] = [item]
    return modules
  
def fetch_from_s3(name):
    """Download a selected item"""
    print "Can we find %s online? " % name
    selected = None
    try:
        s3 = get_modules_from_s3()
        print "Looking at %s" % s3
        print "Ah ha! I can see %s" % str(s3[name])
        for item in s3[name]:
            print "Is %s the version we want?" % str(item[1])
            if __version__ in item[1]:
                selected = item
    except KeyError, e:
        print "KeyError! %s" % e
        pass

    if selected is None:
        print "Couldn't find %s online!" % name
        return None
    else:
        print "Fetching %s as %s" % (selected[0], selected[1])
        urllib.urlretrieve(selected[0], selected[1])
        t = tarfile.open(selected[1], "r:gz")
        top = t.getmembers()[0]
        if os.path.exists(name):
            shutil.rmtree(name)
        for member in t.getmembers():
            t.extract(member)
        fetch_locally(name)
        shutil.rmtree(name)
        os.remove(selected[1])
        return True

def fetch_locally(name):
    """Scan the local directory for Spring Python modules to install."""
    try:
        shutil.copytree(name, plugin_path(name))
        return True
    except OSError:
        print "Couldn't find %s locally!" % name
        return None

def uninstall_plugin(name):
    if os.path.exists(plugin_path(name)):
        print "Uninstalling plugin %s from %s" % (name, p["plugindir"])
        shutil.rmtree(plugin_path(name))
    else:
        print "Plugin %s is NOT installed." % name

############################################################################
# Print out a listing of existing commands, including hooks to installed
# plugins.
############################################################################

def usage():
    """This tool helps you create Spring Python apps, install plug-ins, and much more."""
    print
    print "Usage: coily [command]"
    print
    print "\t--help\t\t\t\tprint this help message"
    print "\t--list-installed-plugins\tlist currently installed plugins"
    print "\t--list-available-plugins\tlist plugins available for download"
    print "\t--install-plugin [name]\t\tinstall coily plugin"
    print "\t--uninstall-plugin [name]\tuninstall coily plugin"
    print "\t--reinstall-plugin [name]\treinstall coily plugin"
    for plugin in p["plugins"]:
        try:
            if hasattr(p[plugin], "create"):
                print "\t--" + plugin + " [name]"+ "\t"*(3-len(plugin)/8) + p[plugin].__description__
            else:
                print "\t--" + plugin + "\t"*(4-len(plugin)/8) + p[plugin].__description__
        except AttributeError, e:
            print "\t%s/%s is not a valid plugin => %s" % (p["plugindir"], plugin, e)
    print

print "Coily v%s - the command-line management tool for Spring Python, http://springpython.webfactional.com" % __version__
print "==============================================================================="
print "Copyright 2006-2009 SpringSource (http://springsource.com), All Rights Reserved"
print "Licensed under the Apache License, Version 2.0"
print

############################################################################
# Read the command-line, and assemble commands. Any invalid command, print
# usage info, and EXIT.
############################################################################

p["plugins"] = []
import_errors = False
for plugin in os.listdir(p["plugindir"]):
    try:
        p[plugin] = __import__(plugin)
        p["plugins"].append(plugin)
    except ImportError:
        #print "\tWARNING: %s is not a python package, making it an invalid plugin." % plugin
        #import_errors = True
        pass
if import_errors:
    print

try:
    cmds = ["help",
            "list-installed-plugins",
            "list-available-plugins",
            "install-plugin=", 
            "uninstall-plugin=",
            "reinstall-plugin="]
    cmds.extend([plugin + "=" for plugin in p["plugins"] if hasattr(p[plugin], "create")])
    cmds.extend([plugin       for plugin in p["plugins"] if not hasattr(p[plugin], "create")])
    optlist, args = getopt.getopt(sys.argv[1:], "h", cmds)
except getopt.GetoptError:
    # print help information and exit:
    print "Invalid command found in %s" % sys.argv
    usage()
    sys.exit(2)

# Check for help requests, which cause all other options to be ignored. Help can offer version info, which is
# why it comes as the second check
for option in optlist:
    if option[0] in ("--help", "-h"):
        usage()
        sys.exit(1)
        
############################################################################
# Main commands. Skim the options, and run each command as its found.
# Commands are run in the order found ON THE COMMAND LINE.
############################################################################

# Parse the arguments, in order
for option in optlist:
    if option[0] in ("--list-installed-plugins"):
        list_installed_plugins()

    if option[0] in ("--list-available-plugins"):
        list_available_plugins()

    if option[0] in ("--install-plugin"):
        install_plugin(option[1])

    if option[0] in ("--uninstall-plugin"):
        uninstall_plugin(option[1])

    if option[0] in ("--reinstall-plugin"):
        uninstall_plugin(option[1])
        install_plugin(option[1])

    cmd = option[0][2:]  # Command name with "--" stripped out
    if cmd in p["plugins"]:
        try:
            p[cmd].create(p["plugindir"] + "/" + cmd, option[1])
        except AttributeError, e:
            print e
            p[cmd].apply(p["plugindir"] + "/" + cmd)