Skip to content
This repository was archived by the owner on Jul 22, 2019. It is now read-only.

Query Server package code review #286

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Mar 22, 2016
e38397e
[server] Introduce `BaseQueryServer` and `SimpleQueryServer`
kxepal May 13, 2016
3a71bff
[server] mv view.py to server/__main__.py
kxepal May 9, 2016
820bda5
[server] Add server test suite
kxepal May 14, 2016
55d7088
[server] Test suite for `server.stream`
kxepal May 14, 2016
dcbbd47
[server] Apply proper API calls to __main__.py
kxepal May 9, 2016
b47a059
[server] New cmd option `--log-level`
kxepal May 9, 2016
76256a1
[server] New cmd option `--allow-get-update`
kxepal May 9, 2016
ce1a300
[server] New cmd option `--enable-eggs`
kxepal May 9, 2016
e217c4f
[server] New cmd option `--egg-cache`
kxepal May 9, 2016
12893f6
[server] New cmd option `couchdb-version`
kxepal May 9, 2016
146d969
[server] `BaseQueryServer.commands` property
kxepal May 13, 2016
147364e
[server] Exception handlers for `BaseQueryServer`
kxepal May 13, 2016
369f320
[server] Property `BaseQueryServer.state`
kxepal May 13, 2016
bd98047
[server] Server cmd: `log`
kxepal May 13, 2016
a0fbacd
[server] Server API: `compile`
kxepal May 13, 2016
2f562a7
[server] Resolve dependencies of `compiler`: `maybe_export_egg`
kxepal May 15, 2016
3bad349
[server] Resolve dependencies of `compiler`
kxepal May 15, 2016
45682c5
[server] Resolve dependencies of `compiler`: `require`
kxepal May 15, 2016
906c6b1
[server] Resolve dependencies of `compiler`: `compile_func`
kxepal May 15, 2016
37798ba
[server] Server cmd: `add_lib`
kxepal May 13, 2016
4349d51
[server] Server cmd: `add_fun`
kxepal May 13, 2016
9c30606
[server] Server cmd: `reset`
kxepal May 13, 2016
c4e152b
[server] Server cmd: `add_ddoc`
kxepal May 13, 2016
d4f7a01
[server] Server API: `ddoc_cmd`
kxepal May 13, 2016
698ee0e
[server] Server cmd: `map_doc`
kxepal May 13, 2016
d00497d
[server] Server cmd: `reduce`
kxepal May 13, 2016
bb91838
[server] Server cmd: `rereduce`
kxepal May 13, 2016
a2c5841
[server] Server cmd: `show_doc`
kxepal May 13, 2016
0a457bf
[server] `render_function` required by `show_doc`
kxepal May 13, 2016
cca018d
[server] `response_with` required by `show_doc`
kxepal May 13, 2016
dbcc74d
[server] Introduce `MimeProvider`
kxepal May 13, 2016
b321342
[server] Add `util.OrderedDict` required by `mime`
iblislin May 14, 2016
1db4916
[server] Add helper functions in module `mime`
kxepal May 14, 2016
91abfb9
[server] Server cmd: `list_old`
kxepal May 14, 2016
3f47ac1
[server] Server cmd: `show`
kxepal May 14, 2016
9e9422c
[server] Server cmd: `list`
kxepal May 14, 2016
2148e00
[server] Server cmd: `update`
kxepal May 14, 2016
ef9c855
[server] Server cmd: `filter`
kxepal May 14, 2016
6cede86
[server] Server cmd: `validate_doc_update`
kxepal May 14, 2016
6f365b8
[server] Server cmd: `ddoc shows`
kxepal May 14, 2016
8e7b197
[server] Server cmd: `ddoc lists`
kxepal May 14, 2016
64c7d14
[server] Server cmd: `ddoc updates`
kxepal May 14, 2016
106e528
[server] Server cmd: `ddoc filters`
kxepal May 14, 2016
e60cf48
[server] Server cmd: `ddoc views`
kxepal May 14, 2016
27facf4
[server] Server cmd: `ddoc validate_doc_update`
kxepal May 14, 2016
60b8555
[server] Add test suite: 'cli'
kxepal May 15, 2016
e741a85
[server] unicode anywhere in stream.respond
iblislin May 20, 2016
cc4798e
[server] Fix setup.py packages options
iblislin May 20, 2016
8bd1985
[server] update docstring of __main__ script
iblislin May 20, 2016
439af0a
[server] move local import statement to the top
iblislin May 20, 2016
39131fd
[server] Fix option string of cli script
iblislin May 20, 2016
838c861
[server] Replace try-except block with assertRaises
iblislin May 20, 2016
2b84a3a
[server] Apply `None` checking for `qs.log` properly
iblislin May 21, 2016
c1b50cd
[server] fix typo in compiler.py
iblislin May 22, 2016
71db52b
[server] clean up legacy code in compiler.py
iblislin May 23, 2016
2b8d345
[server] clean up legacy test case in compiler.py
iblislin May 23, 2016
0b99d7b
[server] Reimplement compiler.maybe_b64egg
iblislin May 24, 2016
b0cc416
[server] Accept empty context in compiler.require
iblislin May 28, 2016
f0c5054
[server] code clean up in compiler.py
iblislin May 28, 2016
f373e06
[server] check side effect in test case
iblislin May 30, 2016
a2ff50d
[server] Remove obsolete var: state.line_length
iblislin Jun 6, 2016
f7aee62
[server] Exam the output of user map funcion
iblislin Jun 11, 2016
f91a237
[server] check the empty output of map_doc in test case
iblislin Jun 23, 2016
13f6c8d
[server] raise exceptions in try-else block for views.py
iblislin Oct 25, 2016
d099408
[server] mime: update DEFAULT_TYPES
iblislin Oct 26, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
821 changes: 821 additions & 0 deletions couchdb/server/__init__.py

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions couchdb/server/__main__.py
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
Copy link
Author

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?

Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks you, RHEL
Errrr.. 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. 😞

Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Collaborator

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 (:

--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()
Loading