Skip to content

Commit c95c0ae

Browse files
committed
First public release
0 parents  commit c95c0ae

20 files changed

+1968
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.pyc
2+
3+
.installed.cfg
4+
bin
5+
develop-eggs
6+
eggs
7+
*.egg-info
8+
9+
tmp
10+
build
11+
dist
12+
.coverage

LICENSE.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Jose Plana Mario
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
23+

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.rst
2+
include NEWS.txt

NEWS.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
News
2+
====
3+
4+
0.1
5+
---
6+
7+
*Release date: 18-Sep-2013*
8+
9+
* Initial release

README.rst

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
python-etcd documentation
2+
=========================
3+
4+
A python client for Etcd https://github.com/coreos/etcd
5+
6+
Installation
7+
------------
8+
9+
Pre-requirements
10+
~~~~~~~~~~~~~~~~
11+
12+
Install etcd
13+
14+
From source
15+
~~~~~~~~~~~
16+
17+
.. code:: bash
18+
19+
$ python setup.py install
20+
21+
Usage
22+
-----
23+
24+
Create a client object
25+
~~~~~~~~~~~~~~~~~~~~~~
26+
27+
.. code:: python
28+
29+
import etcd
30+
31+
client = etcd.Client() # this will create a client against etcd server running on localhost on port 4001
32+
client = etcd.Client(port=4002)
33+
client = etcd.Client(host='127.0.0.1', port=4003)
34+
client = etcd.Client(host='127.0.0.1', port=4003, allow_redirect=False) # wont let you run sensitive commands on non-leader machines, default is true
35+
36+
Set a key
37+
~~~~~~~~~
38+
39+
.. code:: python
40+
41+
client.set('/nodes/n1', 1)
42+
# with ttl
43+
client.set('/nodes/n2', 2, ttl=4) # sets the ttl to 4 seconds
44+
45+
Get a key
46+
~~~~~~~~~
47+
48+
.. code:: python
49+
50+
client.get('/nodes/n2')['value']
51+
52+
Delete a key
53+
~~~~~~~~~~~~
54+
55+
.. code:: python
56+
57+
client.delete('/nodes/n1')
58+
59+
Test and set
60+
~~~~~~~~~~~~
61+
62+
.. code:: python
63+
64+
client.test_and_set('/nodes/n2', 2, 4) # will set /nodes/n2 's value to 2 only if its previous value was 4
65+
66+
Watch a key
67+
~~~~~~~~~~~
68+
69+
.. code:: python
70+
71+
client.watch('/nodes/n1') # will wait till the key is changed, and return once its changed
72+
73+
List sub keys
74+
~~~~~~~~~~~~~
75+
76+
.. code:: python
77+
78+
client.get('/nodes')
79+
80+
Get machines in the cluster
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
.. code:: python
84+
85+
client.machines
86+
87+
Get leader of the cluster
88+
~~~~~~~~~~~~~~~~~~~~~~~~~
89+
90+
.. code:: python
91+
92+
client.leader
93+
94+
Development setup
95+
-----------------
96+
97+
To create a buildout,
98+
99+
.. code:: bash
100+
101+
$ python bootstrap.py
102+
$ bin/buildout
103+
104+
to test you should have etcd available in your system path:
105+
106+
.. code:: bash
107+
108+
$ bin/test
109+
110+
to generate documentation,
111+
112+
.. code:: bash
113+
114+
$ cd docs
115+
$ make
116+
117+
Release HOWTO
118+
-------------
119+
120+
To make a release
121+
122+
1) Update release date/version in NEWS.txt and setup.py
123+
2) Run 'python setup.py sdist'
124+
3) Test the generated source distribution in dist/
125+
4) Upload to PyPI: 'python setup.py sdist register upload'

bootstrap.py

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) 2006 Zope Foundation and Contributors.
4+
# All Rights Reserved.
5+
#
6+
# This software is subject to the provisions of the Zope Public License,
7+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11+
# FOR A PARTICULAR PURPOSE.
12+
#
13+
##############################################################################
14+
"""Bootstrap a buildout-based project
15+
16+
Simply run this script in a directory containing a buildout.cfg.
17+
The script accepts buildout command-line options, so you can
18+
use the -c option to specify an alternate configuration file.
19+
"""
20+
21+
import os
22+
import shutil
23+
import sys
24+
import tempfile
25+
26+
from optparse import OptionParser
27+
28+
tmpeggs = tempfile.mkdtemp()
29+
30+
usage = '''\
31+
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
32+
33+
Bootstraps a buildout-based project.
34+
35+
Simply run this script in a directory containing a buildout.cfg, using the
36+
Python that you want bin/buildout to use.
37+
38+
Note that by using --find-links to point to local resources, you can keep
39+
this script from going over the network.
40+
'''
41+
42+
parser = OptionParser(usage=usage)
43+
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
44+
45+
parser.add_option("-t", "--accept-buildout-test-releases",
46+
dest='accept_buildout_test_releases',
47+
action="store_true", default=False,
48+
help=("Normally, if you do not specify a --version, the "
49+
"bootstrap script and buildout gets the newest "
50+
"*final* versions of zc.buildout and its recipes and "
51+
"extensions for you. If you use this flag, "
52+
"bootstrap and buildout will get the newest releases "
53+
"even if they are alphas or betas."))
54+
parser.add_option("-c", "--config-file",
55+
help=("Specify the path to the buildout configuration "
56+
"file to be used."))
57+
parser.add_option("-f", "--find-links",
58+
help=("Specify a URL to search for buildout releases"))
59+
60+
61+
options, args = parser.parse_args()
62+
63+
######################################################################
64+
# load/install setuptools
65+
66+
to_reload = False
67+
try:
68+
import pkg_resources
69+
import setuptools
70+
except ImportError:
71+
ez = {}
72+
73+
try:
74+
from urllib.request import urlopen
75+
except ImportError:
76+
from urllib2 import urlopen
77+
78+
# XXX use a more permanent ez_setup.py URL when available.
79+
exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
80+
).read(), ez)
81+
setup_args = dict(to_dir=tmpeggs, download_delay=0)
82+
ez['use_setuptools'](**setup_args)
83+
84+
if to_reload:
85+
reload(pkg_resources)
86+
import pkg_resources
87+
# This does not (always?) update the default working set. We will
88+
# do it.
89+
for path in sys.path:
90+
if path not in pkg_resources.working_set.entries:
91+
pkg_resources.working_set.add_entry(path)
92+
93+
######################################################################
94+
# Install buildout
95+
96+
ws = pkg_resources.working_set
97+
98+
cmd = [sys.executable, '-c',
99+
'from setuptools.command.easy_install import main; main()',
100+
'-mZqNxd', tmpeggs]
101+
102+
find_links = os.environ.get(
103+
'bootstrap-testing-find-links',
104+
options.find_links or
105+
('http://downloads.buildout.org/'
106+
if options.accept_buildout_test_releases else None)
107+
)
108+
if find_links:
109+
cmd.extend(['-f', find_links])
110+
111+
setuptools_path = ws.find(
112+
pkg_resources.Requirement.parse('setuptools')).location
113+
114+
requirement = 'zc.buildout'
115+
version = options.version
116+
if version is None and not options.accept_buildout_test_releases:
117+
# Figure out the most recent final version of zc.buildout.
118+
import setuptools.package_index
119+
_final_parts = '*final-', '*final'
120+
121+
def _final_version(parsed_version):
122+
for part in parsed_version:
123+
if (part[:1] == '*') and (part not in _final_parts):
124+
return False
125+
return True
126+
index = setuptools.package_index.PackageIndex(
127+
search_path=[setuptools_path])
128+
if find_links:
129+
index.add_find_links((find_links,))
130+
req = pkg_resources.Requirement.parse(requirement)
131+
if index.obtain(req) is not None:
132+
best = []
133+
bestv = None
134+
for dist in index[req.project_name]:
135+
distv = dist.parsed_version
136+
if _final_version(distv):
137+
if bestv is None or distv > bestv:
138+
best = [dist]
139+
bestv = distv
140+
elif distv == bestv:
141+
best.append(dist)
142+
if best:
143+
best.sort()
144+
version = best[-1].version
145+
if version:
146+
requirement = '=='.join((requirement, version))
147+
cmd.append(requirement)
148+
149+
import subprocess
150+
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
151+
raise Exception(
152+
"Failed to execute command:\n%s",
153+
repr(cmd)[1:-1])
154+
155+
######################################################################
156+
# Import and run buildout
157+
158+
ws.add_entry(tmpeggs)
159+
ws.require(requirement)
160+
import zc.buildout.buildout
161+
162+
if not [a for a in args if '=' not in a]:
163+
args.append('bootstrap')
164+
165+
# if -c was provided, we push it back into args for buildout' main function
166+
if options.config_file is not None:
167+
args[0:0] = ['-c', options.config_file]
168+
169+
zc.buildout.buildout.main(args)
170+
shutil.rmtree(tmpeggs)

buildout.cfg

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[buildout]
2+
parts = python
3+
sphinxbuilder
4+
test
5+
develop = .
6+
eggs =
7+
urllib3==1.7
8+
9+
[python]
10+
recipe = zc.recipe.egg
11+
interpreter = python
12+
eggs = ${buildout:eggs}
13+
14+
[test]
15+
recipe = pbp.recipe.noserunner
16+
eggs = ${python:eggs}
17+
mock
18+
19+
[sphinxbuilder]
20+
recipe = collective.recipe.sphinxbuilder
21+
source = ${buildout:directory}/docs-source
22+
build = ${buildout:directory}/docs

docs-source/api.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
API Documentation
2+
=========================
3+
.. automodule:: etcd
4+
:members:
5+
.. autoclass:: Client
6+
:special-members:
7+
:members:
8+
:exclude-members: __weakref__

0 commit comments

Comments
 (0)