Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Installable from PyPi with all commands.

Code was refactored. Cony is a module now with submodule repos,
containing all 3-party commands. Also, exacutable command was renamed
from ./cony.py into the ./cony-server.
  • Loading branch information...
commit 2e4051ed2a9b96248eb455fe4162683719b08b4a 1 parent ab959f1
@svetlyak40wt authored
View
1  .gitignore
@@ -7,3 +7,4 @@ dist/
*.pyc
local_settings.py
.vim/ide.session
+build
View
31 README.markdown
@@ -12,7 +12,7 @@ What the difference between Cony and Bunny1?
micro web framework without dependencies.
* Cony could be easily extended. You have no need to inherit any classes like
you do with Bunny1. With Cony, you place your commands in a separate
- file and fire `./cony.py`.
+ file and fire `./cony-server`.
Introduction
------------
@@ -51,16 +51,19 @@ Installation
Ways to install Cony:
-* Just clone the repository and to run `./cony.py`.
-* `easy_install cony; cony.py`
-* `pip install cony; cony.py`
+* Just clone the repository and to run `./cony-server`.
+* `easy_install cony; cony-server`
+* `pip install cony; cony-server`
Now you have server up and running. It binds to the localhost:8080 by
default. Open the <http://localhost:8080> in your browser to see the help.
-You can configure Cony by editing the top of "cony.py" and looking for the
-"SERVER_*" entries. These can be adjusted to change the port, change what
-interface is bound to (use '' to bind to all interfaces).
+You can configure Cony by overwriting `SERVER_*` variables in your
+`local_settings.py` file. Your could define:
+
+ SERVER_MODE = 'STANDALONE' # or 'WSGI', or 'CGI'
+ SERVER_PORT = 8080
+ SERVER_HOST = 'localhost' # or '' to allow on all interfaces
You can also configure CGI or WSGI modes if you want to integrate this into
an existing web server such as Apache.
@@ -73,7 +76,7 @@ Create "local_settings.py" which contains:
In your Apache configuration, add:
- ScriptAlias /cony/ /path/to/cony.py
+ ScriptAlias /cony/ /path/to/cony-server
Re-start Apache and you should now be able to use
"http://servername/cony/?s=%s" as the Cony URL in your browser
@@ -91,7 +94,7 @@ mod_wsgi").
In your Apache configuration, add:
WSGIPythonPath /path/to/cony/directory
- WSGIScriptAlias /cony/ /path/to/cony/directory/cony.py
+ WSGIScriptAlias /cony/ /path/to/cony/directory/cony-server
Re-start Apache and you should now be able to use
"http://servername/cony/?s=%s" as the Cony URL in your browser
@@ -203,6 +206,15 @@ such as `rich_help('--help')`, then the link adds that argument to the
command link. This is meant so that you can have the main help page link
to help pages for the individual commands.
+Contributing
+------------
+
+There are many commands in `cony.repo` submodule. To plug them all,
+do `from cony.repo import *` or import only those you need for.
+
+If you wrote a command, useful to other users, [fork this project][GitHub] on a
+GitHub and add you command somewhere in the `cony.repo` submodule. Then send me
+a pull request.
Contributors
------------
@@ -210,6 +222,7 @@ Contributors
* Alexander Artemenko (author)
* Sean Reifschneider
+[GitHub]: http://github.com/svetlyak40wt/cony
[smart-bm]: http://en.wikipedia.org/wiki/Smart_bookmark
[bunny1]: https://github.com/facebook/bunny1
[Keywurl]: http://alexstaubo.github.com/keywurl/
View
4 cony-server
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+
+import cony
+cony.main()
View
110 cony.py → cony/__init__.py
@@ -3,12 +3,12 @@
import sys
import bottle
-import urllib2
from bottle import SimpleTemplate, template
-from bottle import route, run, request, redirect
+from bottle import route, run, request
from itertools import groupby
+
################
# CONFIGURATION
#
@@ -26,95 +26,12 @@
##################
# Default commands
##################
-
-def rich_help(help_argument = ''):
- """Decorator for command functions to mark them as providing help.
-
- It causes the default cmd_help to link to them. The optional
- `help_argument`, if set, is the argument passed to the linked command
- for help.
-
- Usage:
-
- @rich_help('help')
- def cmd_some_command(term):
- \"\"\"Short help\"\"\"
- ...
-
- or
-
- @rich_help
- def cmd_some_command(term):
- \"\"\"Short help\"\"\"
- ...
- """
- if callable(help_argument): # it means decorator was applied without args
- func = help_argument
- func.rich_help = ''
- return func
- else:
- def decorator(handler):
- handler.rich_help = help_argument
- return handler
- return decorator
-
-
-def cmd_g(term):
- """Google search."""
- redirect('http://www.google.com/search?q=%s' % term)
-
+from cony.repo.search import cmd_google as cmd_g
+from cony.repo.search import cmd_python as cmd_p
+from cony.repo.search import cmd_pypi
cmd_fallback = cmd_g
-def cmd_pypi(term):
- """Python package index search.
-
- If there is exact match, then redirects right to the package's page.
- """
- import urllib
- try:
- direct_url = 'http://pypi.python.org/pypi/%s/' % term
- result = urllib.urlopen(direct_url)
- except Exception, e:
- pass
- else:
- if result.code == 200:
- redirect(direct_url)
-
- redirect('http://pypi.python.org/pypi?:action=search&term=%s&submit=search' % term)
-
-
-@rich_help('--help')
-def cmd_p(term):
- '''Python documentation search.'''
-
- if term == '--help' or term == '?' or term == '-?':
- _template = """
- <p>Search the Python documentation pages for the specified string.
- If the term is:</p>
-
- <ul>
- <li><b>No arguments</b> — Take you to the main Python
- documentation library page.</li>
- <li><b>Matches module name</b> — Go directly to that
- module's documentation page.</li>
- <li><b>Otherwise</b> — Passes the term on to the PyDoc search page.</li>
- </ul>
- %rebase layout title = 'PyDoc Help — Cony'
- """
- return dict(template=_template)
- elif not term:
- redirect('http://docs.python.org/library/index.html')
- else:
- try:
- url = 'http://docs.python.org/dev/library/%s.html' % term
- urllib2.urlopen(url)
- redirect(url)
- except urllib2.HTTPError:
- redirect('http://docs.python.org/search.html?q=%s'
- '&check_keywords=yes&area=default' % term)
-
-
def cmd_help(term):
"""Shows all available commands."""
items = []
@@ -176,6 +93,7 @@ def cmd_help(term):
"""
return dict(template=_template, items = items, title = u'Help — Cony')
+
########################
# Templates related part
########################
@@ -244,8 +162,9 @@ def __init__(self, source=None, name=None, **kwargs):
from local_settings import *
if 'TEMPLATES' in locals():
_TEMPLATES.update(TEMPLATES)
-except ImportError:
- pass
+except ImportError, e:
+ if 'local_settings' not in e.message:
+ raise
@route('/')
@@ -280,12 +199,14 @@ def do_command():
return result
-bottle.debug(DEBUG)
+def wsgi():
+ bottle.debug(DEBUG)
+ return bottle.app()
-if SERVER_MODE == 'WSGI':
- application = bottle.app()
-elif __name__ == '__main__':
+def main():
+ bottle.debug(DEBUG)
+
if SERVER_MODE == 'STANDALONE':
run(
reloader=DEBUG,
@@ -298,3 +219,4 @@ def do_command():
print 'Wrong SERVER_MODE=%r defined for running from command-line' % (SERVER_MODE,)
sys.exit(1)
sys.exit(0)
+
View
0  examples/__init__.py → cony/repo/__init__.py
File renamed without changes
View
0  examples/lang.py → cony/repo/lang.py
File renamed without changes
View
77 cony/repo/search.py
@@ -0,0 +1,77 @@
+# -*- coding: utf-8 -*-
+import urllib2
+from bottle import redirect
+from cony.utils import rich_help
+
+
+def cmd_google(term):
+ """Google search."""
+ redirect('http://www.google.com/search?q=%s' % term)
+
+
+def cmd_fl(term):
+ """Search among Flickr photos under Creative Commons license."""
+ redirect('http://www.flickr.com/search/?q=%s&l=cc&ss=0&ct=0&mt=all&w=all&adv=1' % term)
+
+
+def cmd_pep(term):
+ """Search a Python Enhancement Proposal by it's number. For example: 'pep 8'."""
+ redirect('http://www.python.org/dev/peps/pep-%0.4d/' % int(term))
+
+
+def cmd_dj(term):
+ """Django documentation search."""
+ redirect(
+ 'http://docs.djangoproject.com/en/dev/search/?cx=009763561546736975936:e88ek0eurf4&'
+ 'cof=FORID:11&q=%s&siteurl=docs.djangoproject.com/en/dev/topics/db/models/' % term
+ )
+
+
+def cmd_pypi(term):
+ """Python package index search.
+
+ If there is exact match, then redirects right to the package's page.
+ """
+ import urllib
+ try:
+ direct_url = 'http://pypi.python.org/pypi/%s/' % term
+ result = urllib.urlopen(direct_url)
+ except Exception, e:
+ pass
+ else:
+ if result.code == 200:
+ redirect(direct_url)
+
+ redirect('http://pypi.python.org/pypi?:action=search&term=%s&submit=search' % term)
+
+
+@rich_help('--help')
+def cmd_python(term):
+ '''Python documentation search.'''
+
+ if term == '--help' or term == '?' or term == '-?':
+ _template = """
+ <p>Search the Python documentation pages for the specified string.
+ If the term is:</p>
+
+ <ul>
+ <li><b>No arguments</b> — Take you to the main Python
+ documentation library page.</li>
+ <li><b>Matches module name</b> — Go directly to that
+ module's documentation page.</li>
+ <li><b>Otherwise</b> — Passes the term on to the PyDoc search page.</li>
+ </ul>
+ %rebase layout title = 'PyDoc Help — Cony'
+ """
+ return dict(template=_template)
+ elif not term:
+ redirect('http://docs.python.org/library/index.html')
+ else:
+ try:
+ url = 'http://docs.python.org/dev/library/%s.html' % term
+ urllib2.urlopen(url)
+ redirect(url)
+ except urllib2.HTTPError:
+ redirect('http://docs.python.org/search.html?q=%s'
+ '&check_keywords=yes&area=default' % term)
+
View
32 cony/utils.py
@@ -0,0 +1,32 @@
+def rich_help(help_argument = ''):
+ """Decorator for command functions to mark them as providing help.
+
+ It causes the default cmd_help to link to them. The optional
+ `help_argument`, if set, is the argument passed to the linked command
+ for help.
+
+ Usage:
+
+ @rich_help('help')
+ def cmd_some_command(term):
+ \"\"\"Short help\"\"\"
+ ...
+
+ or
+
+ @rich_help
+ def cmd_some_command(term):
+ \"\"\"Short help\"\"\"
+ ...
+ """
+ if callable(help_argument): # it means decorator was applied without args
+ func = help_argument
+ func.rich_help = ''
+ return func
+ else:
+ def decorator(handler):
+ handler.rich_help = help_argument
+ return handler
+ return decorator
+
+
View
19 examples/search.py
@@ -1,19 +0,0 @@
-from bottle import redirect
-
-
-def cmd_fl(term):
- """Search among Flickr photos under Creative Commons license."""
- redirect('http://www.flickr.com/search/?q=%s&l=cc&ss=0&ct=0&mt=all&w=all&adv=1' % term)
-
-
-def cmd_pep(term):
- """Search a Python Enhancement Proposal by it's number. For example: 'pep 8'."""
- redirect('http://www.python.org/dev/peps/pep-%0.4d/' % int(term))
-
-
-def cmd_dj(term):
- """Django documentation search."""
- redirect(
- 'http://docs.djangoproject.com/en/dev/search/?cx=009763561546736975936:e88ek0eurf4&'
- 'cof=FORID:11&q=%s&siteurl=docs.djangoproject.com/en/dev/topics/db/models/' % term
- )
View
4 setup.py
@@ -3,7 +3,7 @@
setup(
name="cony",
- version="0.2.0",
+ version="0.2.1",
description=(
'"Cony" is a tool to write smart bookmarks in '
'python and to share them across all your browsers and with a '
@@ -26,6 +26,6 @@
'Topic :: Internet :: WWW/HTTP :: WSGI :: Server',
],
packages=find_packages(),
- scripts=['cony.py'],
+ scripts=['cony-server'],
install_requires = ['bottle'],
)
Please sign in to comment.
Something went wrong with that request. Please try again.