This repository was archived by the owner on Jul 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Query Server package code review #286
Open
iblislin
wants to merge
66
commits into
djc:master
Choose a base branch
from
iblislin:issue-268
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
b9ac81b
[server] Introduce query server package
kxepal e38397e
[server] Introduce `BaseQueryServer` and `SimpleQueryServer`
kxepal 3a71bff
[server] mv view.py to server/__main__.py
kxepal 820bda5
[server] Add server test suite
kxepal 55d7088
[server] Test suite for `server.stream`
kxepal dcbbd47
[server] Apply proper API calls to __main__.py
kxepal b47a059
[server] New cmd option `--log-level`
kxepal 76256a1
[server] New cmd option `--allow-get-update`
kxepal ce1a300
[server] New cmd option `--enable-eggs`
kxepal e217c4f
[server] New cmd option `--egg-cache`
kxepal 12893f6
[server] New cmd option `couchdb-version`
kxepal 146d969
[server] `BaseQueryServer.commands` property
kxepal 147364e
[server] Exception handlers for `BaseQueryServer`
kxepal 369f320
[server] Property `BaseQueryServer.state`
kxepal bd98047
[server] Server cmd: `log`
kxepal a0fbacd
[server] Server API: `compile`
kxepal 2f562a7
[server] Resolve dependencies of `compiler`: `maybe_export_egg`
kxepal 3bad349
[server] Resolve dependencies of `compiler`
kxepal 45682c5
[server] Resolve dependencies of `compiler`: `require`
kxepal 906c6b1
[server] Resolve dependencies of `compiler`: `compile_func`
kxepal 37798ba
[server] Server cmd: `add_lib`
kxepal 4349d51
[server] Server cmd: `add_fun`
kxepal 9c30606
[server] Server cmd: `reset`
kxepal c4e152b
[server] Server cmd: `add_ddoc`
kxepal d4f7a01
[server] Server API: `ddoc_cmd`
kxepal 698ee0e
[server] Server cmd: `map_doc`
kxepal d00497d
[server] Server cmd: `reduce`
kxepal bb91838
[server] Server cmd: `rereduce`
kxepal a2c5841
[server] Server cmd: `show_doc`
kxepal 0a457bf
[server] `render_function` required by `show_doc`
kxepal cca018d
[server] `response_with` required by `show_doc`
kxepal dbcc74d
[server] Introduce `MimeProvider`
kxepal b321342
[server] Add `util.OrderedDict` required by `mime`
iblislin 1db4916
[server] Add helper functions in module `mime`
kxepal 91abfb9
[server] Server cmd: `list_old`
kxepal 3f47ac1
[server] Server cmd: `show`
kxepal 9e9422c
[server] Server cmd: `list`
kxepal 2148e00
[server] Server cmd: `update`
kxepal ef9c855
[server] Server cmd: `filter`
kxepal 6cede86
[server] Server cmd: `validate_doc_update`
kxepal 6f365b8
[server] Server cmd: `ddoc shows`
kxepal 8e7b197
[server] Server cmd: `ddoc lists`
kxepal 64c7d14
[server] Server cmd: `ddoc updates`
kxepal 106e528
[server] Server cmd: `ddoc filters`
kxepal e60cf48
[server] Server cmd: `ddoc views`
kxepal 27facf4
[server] Server cmd: `ddoc validate_doc_update`
kxepal 60b8555
[server] Add test suite: 'cli'
kxepal e741a85
[server] unicode anywhere in stream.respond
iblislin cc4798e
[server] Fix setup.py packages options
iblislin 8bd1985
[server] update docstring of __main__ script
iblislin 439af0a
[server] move local import statement to the top
iblislin 39131fd
[server] Fix option string of cli script
iblislin 838c861
[server] Replace try-except block with assertRaises
iblislin 2b84a3a
[server] Apply `None` checking for `qs.log` properly
iblislin c1b50cd
[server] fix typo in compiler.py
iblislin 71db52b
[server] clean up legacy code in compiler.py
iblislin 2b8d345
[server] clean up legacy test case in compiler.py
iblislin 0b99d7b
[server] Reimplement compiler.maybe_b64egg
iblislin b0cc416
[server] Accept empty context in compiler.require
iblislin f0c5054
[server] code clean up in compiler.py
iblislin f373e06
[server] check side effect in test case
iblislin a2ff50d
[server] Remove obsolete var: state.line_length
iblislin f7aee62
[server] Exam the output of user map funcion
iblislin f91a237
[server] check the empty output of map_doc in test case
iblislin 13f6c8d
[server] raise exceptions in try-else block for views.py
iblislin d099408
[server] mime: update DEFAULT_TYPES
iblislin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2007-2008 Christopher Lenz | ||
# All rights reserved. | ||
# | ||
# This software is licensed as described in the file COPYING, which | ||
# you should have received as part of this distribution. | ||
|
||
"""Implementation of a query server for functions written in Python.""" | ||
import getopt | ||
import logging | ||
import os | ||
import sys | ||
|
||
from couchdb import __version__ as VERSION | ||
from couchdb import json | ||
from couchdb.server import SimpleQueryServer | ||
|
||
__all__ = ['main', 'run'] | ||
__docformat__ = 'restructuredtext en' | ||
|
||
log = logging.getLogger('couchdb.server') | ||
|
||
_VERSION = """%(name)s - CouchDB Python %(version)s | ||
|
||
Copyright (C) 2007 Christopher Lenz <[email protected]>. | ||
""" | ||
|
||
_HELP = """Usage: %(name)s [OPTION] | ||
|
||
The %(name)s command runs the CouchDB Python query server. | ||
|
||
The exit status is 0 for success or 1 for failure. | ||
|
||
Options: | ||
|
||
--version display version information and exit | ||
-h, --help display a short help message and exit | ||
--json-module=<name> set the JSON module to use ('simplejson', 'cjson', | ||
or 'json' are supported) | ||
--log-file=<file> name of the file to write log messages to, or '-' to | ||
enable logging to the standard error stream | ||
--log-level=<level> specify logging level (debug, info, warn, error). | ||
Used info level if omitted. | ||
--allow-get-update allows GET requests to call update functions. | ||
--enable-eggs enables support of eggs as modules. | ||
--egg-cache=<path> specifies egg cache dir. If omitted, PYTHON_EGG_CACHE | ||
environment variable value would be used or system | ||
temporary directory if variable not setted. | ||
--couchdb-version=<ver> define with which version of couchdb server will work | ||
default: latest implemented. | ||
Supports from 0.9.0 to 1.1.0 and trunk. Technicaly | ||
should work with 0.8.0. | ||
e.g.: --couchdb-version=0.9.0 | ||
--debug enable debug logging; requires --log-file to be | ||
specified | ||
|
||
Report bugs via the web at <https://github.com/djc/couchdb-python/issues>. | ||
""" | ||
|
||
|
||
def run(input=sys.stdin, output=sys.stdout, version=None, **config): | ||
qs = SimpleQueryServer(version, input=input, output=output, **config) | ||
return qs.serve_forever() | ||
|
||
|
||
def main(): | ||
"""Command-line entry point for running the query server.""" | ||
qs_config = {} | ||
|
||
try: | ||
option_list, argument_list = getopt.gnu_getopt( | ||
sys.argv[1:], 'h', | ||
['version', 'help', 'json-module=', 'debug', 'log-file=', | ||
'log-level=', 'allow-get-update', 'enable-eggs', | ||
'egg-cache=', 'couchdb-version='] | ||
) | ||
|
||
db_version = None | ||
message = None | ||
|
||
for option, value in option_list: | ||
if option in ('--version',): | ||
message = _VERSION % dict(name=os.path.basename(sys.argv[0]), | ||
version=VERSION) | ||
elif option in ('-h', '--help'): | ||
message = _HELP % dict(name=os.path.basename(sys.argv[0])) | ||
elif option in ('--json-module',): | ||
json.use(module=value) | ||
elif option in ('--debug',): | ||
qs_config['log_level'] = 'DEBUG' | ||
elif option in ('--log-level',): | ||
qs_config['log_level'] = value.upper() | ||
elif option in ('--log-file',): | ||
qs_config['log_file'] = value | ||
elif option in ('--allow-get-update',): | ||
qs_config['allow_get_update'] = True | ||
elif option in ('--enable-eggs',): | ||
qs_config['enable_eggs'] = True | ||
elif option in ('--egg-cache',): | ||
qs_config['egg_cache'] = value | ||
elif option in ('--couchdb-version',): | ||
db_version = _get_db_version(value) | ||
|
||
if message: | ||
sys.stdout.write(message) | ||
sys.stdout.flush() | ||
sys.exit(0) | ||
|
||
except getopt.GetoptError as error: | ||
message = '{0}\n\nTry `{1} --help` for more information.\n'.format( | ||
str(error), os.path.basename(sys.argv[0])) | ||
sys.stderr.write(message) | ||
sys.stderr.flush() | ||
sys.exit(1) | ||
|
||
sys.exit(run(version=db_version, **qs_config)) | ||
|
||
|
||
def _get_db_version(ver_str): | ||
"""Get version string from command line option | ||
|
||
>>> assert _get_db_version('trunk') is None | ||
|
||
>>> assert _get_db_version('TRUNK') is None | ||
|
||
>>> _get_db_version('1.2.3') | ||
(1, 2, 3) | ||
|
||
>>> _get_db_version('1.1') | ||
(1, 1, 0) | ||
|
||
>>> _get_db_version('1') | ||
(1, 0, 0) | ||
""" | ||
if ver_str.lower() == 'trunk': | ||
return | ||
|
||
ver_str = ver_str.split('.') | ||
while len(ver_str) < 3: | ||
ver_str.append(0) | ||
|
||
return tuple(map(int, ver_str[:3])) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, where can we find such old query protocol specs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll surprise how much people comes with very old releases (thanks you, Ubuntu LTS!)...
As about the specs: http://docs.couchdb.org/en/1.6.1/query-server/protocol.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks you, RHELErrrr.. The doc of 1.6 do not record the evolution of the protocol. (e.g.
log
command got format changed).And the oldest specs version available on the web is 1.5.1. 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, there is just actual state of things. However, there is no (I'm sure) else alternative except the code you may find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. To be honest, i'm lack of Erlang skill. Please excuse me for simply praying that those code related to older protocol work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should. At least there were few tests about (: