def help(self, arg): """gets help with a specific command or shows the README for general help""" if arg: raise Content("<b>" + escape(arg) + "</b><br />" + str(getattr(self, arg).__doc__)) else: raise Content(self._help_html())
def alias(self, arg): """aliases one shortcut to another. ex: alias p profile. alias p will show what p is aliased to. alias with no args will show all aliases.""" words = arg.split() cookie = cherrypy.response.cookie try: alias = words[0] real = words[1] cookie["alias." + alias] = real raise Content("aliased <b>%s</b> to <b>%s</b>" % (escape(alias), escape(real))) except IndexError: try: alias = words[0] try: raise Content( "<b>%s</b> is aliased to <b>%s</b>" % (escape(alias), escape( cherrypy.request.cookie["alias." + alias].value))) except KeyError: raise Content("<b>%s</b> is not aliased to anything." % escape(arg)) except IndexError: html = "usage:<br />alias <i>alias</i> <i>real-command</i><br />or<br />alias <i>alias</i><br /><hr />" cookie = cherrypy.request.cookie for name in cookie.keys(): if str(name).startswith("alias."): html += "<b>%s</b> is aliased to <b>%s</b><br />" % ( escape(name[6:]), escape(cookie[name].value)) raise Content(html)
def unalias(self, arg): """unaliases an alias. ex: unalias p""" if not arg: raise Content("usage:<br />unalias <i>alias</i>") cherrypy.response.cookie["alias." + arg] = "" cherrypy.response.cookie["alias." + arg]["expires"] = 0 raise Content("unaliased <b>%s</b>" % escape(arg))
def list(self, arg): """show the list of methods you can use or search that list""" def is_exposed_method((name, method)): return not name.startswith("__") and callable(method) \ and method.__doc__ and not getattr(method, "dont_expose", False) \ and not getattr(method, "unlisted", False) arg_lower = None if arg: arg_lower = arg.lower() html = "" search_predicate = lambda (name, method): is_exposed_method((name,method)) and \ (arg_lower in name.lower() or arg_lower in method.__doc__) else: html = self._popularity_html( 10) + "<hr ><b><i>All Commands</i></b><br />" search_predicate = is_exposed_method attr_names = dir(self) def attr_getter(name): return getattr(self, name) html += '<table>' html += ''.join([ '<tr><td><b>%s</b></td><td>%s</td></tr>' % (name, escape(method.__doc__)) for name, method in ifilter( search_predicate, izip(attr_names, imap(attr_getter, attr_names))) ]) html += '<table>' raise Content(html)
def _info(self, arg): """shows some info about this instance of bunny1""" raise Content("<code>" + repr({ "_info": { "base_url": self._b1.base_url, }, "os_env": os.environ, }) + "</code>")
def url(self, arg): """goes to the URL that is specified""" if arg: if ":" not in arg: return "http://%s" % arg else: return arg else: raise Content("no url specified")
def _cookies(self, arg): """show the cookies set on this server or search through them""" cookie = cherrypy.request.cookie html = "" for name in cookie.keys(): val = cookie[name].value if not arg or (arg in name or arg in val): html += "<b>%s</b><br />%s<br /><br />" % (escape( str(name)), escape(str(val))) raise Content(html)
def history(self, arg): """show the history of queries made to this server""" html = "<pre><b>history</b>\n" for entry in self.history[:-50:-1]: html += '<a href="/?%(url)s">%(label)s</a>\n' % { "url": entry, "label": entry, } html += "</pre>" raise Content(html)
def _opensearch(self, arg): """returns the OpenSearch description for this server""" m = self._opensearch_metadata() raise Content( """<?xml version="1.0" encoding="UTF-8" ?> <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> <ShortName>""" + m["short_name"] + """</ShortName> <Description>""" + m["description"] + """</Description> <InputEncoding>UTF-8</InputEncoding> <Url type="text/html" template=\"""" + escape(m["template"]) + """\" /> </OpenSearchDescription> """, "application/xml")
def _setpasswd(self, arg): """sets the password for password protected instances of bunny1""" args = arg.split() passwd = args[0] if not arg: return None if len(args) > 1: next = " ".join(args[1:]) else: next = None save("b1passwd", passwd) if next: return next raise Content("password set.")
def __init__(self, error_message): Content.__init__(self) self.html = "<span style='color: red; font-family: Courier New, Courier, Fixed-width; font-weight: bold;'>%s</span>" % escape(error_message)
def _meta(self, arg): """an example of the convention of prefixing meta commands with an underscore""" raise Content( "if you make a meta command, the convention is to use an underscore at the beginning of the name." )
def _hostname(self, arg): """shows the hostname of this server""" import socket raise Content(socket.gethostname())
def echo(self, arg): """returns back what you give to it""" raise Content(escape(arg))
def __init__(self, error_message): Content.__init__(self) self.html = "<span style='color: red; font-family: Courier New, Courier, Fixed-width; font-weight: bold;'>%s</span>" % escape( error_message)
def popular(self, arg): """shows the most popular commands""" raise Content(self._popularity_html())
def readme(self, arg): """shows the README for this tool""" raise Content(self._help_html())