From 78a3faaaed8903a1c7ea30dc3d0a70a2c2a94dbf Mon Sep 17 00:00:00 2001 From: Matt Wise Date: Wed, 2 Jan 2013 21:20:46 +0000 Subject: [PATCH] Rename ndServiceRegistry to nd_service_registry to conform with Google Python Guidelines. --- README.rst | 18 +++++----- .../__init__.py | 33 +++++++++---------- .../exceptions.py | 2 +- .../funcs.py | 4 +-- .../registration.py | 8 ++--- .../shims.py | 4 +-- .../version.py | 2 +- .../watcher.py | 6 ++-- setup.py | 10 +++--- 9 files changed, 43 insertions(+), 44 deletions(-) rename {ndServiceRegistry => nd_service_registry}/__init__.py (97%) rename {ndServiceRegistry => nd_service_registry}/exceptions.py (96%) rename {ndServiceRegistry => nd_service_registry}/funcs.py (98%) rename {ndServiceRegistry => nd_service_registry}/registration.py (97%) rename {ndServiceRegistry => nd_service_registry}/shims.py (94%) rename {ndServiceRegistry => nd_service_registry}/version.py (92%) rename {ndServiceRegistry => nd_service_registry}/watcher.py (98%) diff --git a/README.rst b/README.rst index 301e760..82ce09a 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ -================= -ndServiceRegistry -================= +=================== +nd_service_registry +=================== -*`ndServiceRegistry`* is a Python module that provides a simple way to leverage +*`nd_service_registry`* is a Python module that provides a simple way to leverage *`Apache Zookeeper`* as a dynamic configuration and service registry. The goal of the package is to provide a single foundational class that can be @@ -28,7 +28,7 @@ To install, run :: or :: - pip install ndServiceRegistry + pip install nd_service_registry Instantiating a KazooServiceRegistry module ------------------------------------------- @@ -43,10 +43,10 @@ Create a logger object:: To create your initial connection object:: - >>> from ndServiceRegistry import KazooServiceRegistry + >>> from nd_service_registry import KazooServiceRegistry >>> nd = KazooServiceRegistry() -The KazooServiceRegistry object is a child of ndServiceRegistry that conforms +The KazooServiceRegistry object is a child of nd_service_registry that conforms to our ServiceRegistry specs, whlie leveraging Kazoo as the backend. The object handles all of your connection states - there is no need to start/stop or monitor the connection state at all. @@ -83,7 +83,7 @@ can though, we instead just *return False* as a way of indicating that we were unable to perform your command now ... but that we will take care of it later. Whenever we do this, we throw a WARNING log message as well. -ndServiceRegistry.exceptions.NoConnection +nd_service_registry.exceptions.NoConnection Thrown if you attempt any operation that requires immediate access to the backend Zookeeper service. Either a *set()* operation, or a *get()* operation on a path for the first time. @@ -94,7 +94,7 @@ ndServiceRegistry.exceptions.NoConnection if Zookeeper is down. This allows the service to fail temporarily in the background but your app is still able to get the 'last known' results.) -ndServiceRegistry.exceptions.ReadOnly +nd_service_registry.exceptions.ReadOnly If *readonly=True*, any operation that would result in a 'write' will throw this exception. Most notably, a *set()* operation will fail with this exception if *readonly=True*. diff --git a/ndServiceRegistry/__init__.py b/nd_service_registry/__init__.py similarity index 97% rename from ndServiceRegistry/__init__.py rename to nd_service_registry/__init__.py index 76b2449..df75412 100644 --- a/ndServiceRegistry/__init__.py +++ b/nd_service_registry/__init__.py @@ -14,12 +14,12 @@ """Simple service registration class for managing lists of servers. -The ndServiceRegistry model at Nextdoor is geared around simplicity and +The nd_service_registry model at Nextdoor is geared around simplicity and reliability. This model provides a few core features that allow you to register and unregister nodes that provide certain services, and to monitor particular service paths for lists of nodes. -Although the service structure is up to you, the ndServiceRegistry model is +Although the service structure is up to you, the nd_service_registry model is largely designed around this model: /production @@ -37,7 +37,7 @@ Example usage to provide the above service list: - >>> from ndServiceRegistry import KazooServiceRegistry + >>> from nd_service_registry import KazooServiceRegistry >>> nd = KazooServiceRegistry() >>> nd.set_node('/production/ssh/server1:22') >>> nd.set_node('/production/ssh/server2:22') @@ -61,7 +61,7 @@ aversion=0, ephemeralOwner=0, dataLength=0, numChildren=3, pzxid=45)} -When you call get(), the ndServiceRegistry module goes out and creates a +When you call get(), the nd_service_registry module goes out and creates a Watcher object for the path you provided. This object caches all of the state data for the supplied path in a local dict. This dict is updated any time the Zookeeper service sees a change to that path. @@ -90,7 +90,7 @@ __author__ = 'matt@nextdoor.com (Matt Wise)' -# For ndServiceRegistry Class +# For nd_service_registry Class import os import logging import exceptions @@ -98,15 +98,15 @@ from functools import wraps # Our own classes -from ndServiceRegistry.registration import EphemeralNode -from ndServiceRegistry.watcher import Watcher -from ndServiceRegistry.watcher import DummyWatcher -from ndServiceRegistry import funcs -from ndServiceRegistry import exceptions +from nd_service_registry.registration import EphemeralNode +from nd_service_registry.watcher import Watcher +from nd_service_registry.watcher import DummyWatcher +from nd_service_registry import funcs +from nd_service_registry import exceptions # For KazooServiceRegistry Class import kazoo.security -from ndServiceRegistry.shims import ZookeeperClient +from nd_service_registry.shims import ZookeeperClient from kazoo.client import KazooState # Use Gevent as our threader (DOES NOT WORK RIGHT NOW) @@ -125,7 +125,7 @@ SERVER = 'localhost:2181' -class ndServiceRegistry(object): +class nd_service_registry(object): """Main Service Registry object. The ServiceRegistry object is a framework object, not meant to be @@ -302,11 +302,11 @@ def _convert_dummywatchers_to_watchers(self): self._watchers[path] = w -class KazooServiceRegistry(ndServiceRegistry): +class KazooServiceRegistry(nd_service_registry): _instance = None _initialized = False - LOGGER = 'ndServiceRegistry.KazooServiceRegistry' + LOGGER = 'nd_service_registry.KazooServiceRegistry' def __new__(self, **kwargs): """Only creates a new object if one does not already exist.""" @@ -673,7 +673,7 @@ def get(self, path, callback=None): changes. Returns: - ndServiceRegistry.Watcher.get() dict object + nd_service_registry.Watcher.get() dict object """ # Return the object from our cache, if it's there @@ -707,7 +707,6 @@ def get(self, path, callback=None): 'try again later: %s' % (path, e)) return False - @_health_check def _get_watcher(self, path, callback=None): """Creates a Watcher object for the supplid path. @@ -725,7 +724,7 @@ def _get_watcher(self, path, callback=None): changes. Returns: - ndServiceRegistry.Watcher object + nd_service_registry.Watcher object """ # Ok, so the cache is missing the key. Lets look for it in Zookeeper diff --git a/ndServiceRegistry/exceptions.py b/nd_service_registry/exceptions.py similarity index 96% rename from ndServiceRegistry/exceptions.py rename to nd_service_registry/exceptions.py index dd8757b..8ef4ee2 100644 --- a/ndServiceRegistry/exceptions.py +++ b/nd_service_registry/exceptions.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Exceptions for ndServiceRegistry +"""Exceptions for nd_service_registry Copyright 2012 Nextdoor Inc.""" diff --git a/ndServiceRegistry/funcs.py b/nd_service_registry/funcs.py similarity index 98% rename from ndServiceRegistry/funcs.py rename to nd_service_registry/funcs.py index 7f35379..d51dce5 100644 --- a/ndServiceRegistry/funcs.py +++ b/nd_service_registry/funcs.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Commonly used functions for ndServiceRegistry +"""Commonly used functions for nd_service_registry Copyright 2012 Nextdoor Inc.""" @@ -27,7 +27,7 @@ from functools import wraps # logger name -LOGGER = 'ndServiceRegistry.funcs' +LOGGER = 'nd_service_registry.funcs' def encode(data=None): diff --git a/ndServiceRegistry/registration.py b/nd_service_registry/registration.py similarity index 97% rename from ndServiceRegistry/registration.py rename to nd_service_registry/registration.py index 90e07ba..df96cc5 100644 --- a/ndServiceRegistry/registration.py +++ b/nd_service_registry/registration.py @@ -56,8 +56,8 @@ import time import sys -from ndServiceRegistry import funcs -from ndServiceRegistry.watcher import Watcher +from nd_service_registry import funcs +from nd_service_registry.watcher import Watcher # For KazooServiceRegistry Class import kazoo.exceptions @@ -71,7 +71,7 @@ class Registration(object): """An object that registers a znode with ZooKeeper.""" - LOGGING = 'ndServiceRegistry.Registration' + LOGGING = 'nd_service_registry.Registration' def __init__(self, zk, path, data=None, state=True): # Create our logger @@ -242,7 +242,7 @@ class EphemeralNode(Registration): The node registered with Zookeeper is ephemeral, so if we lose our connection to the service, we have to re-register the data.""" - LOGGING = 'ndServiceRegistry.Registration.EphemeralNode' + LOGGING = 'nd_service_registry.Registration.EphemeralNode' def __init__(self, zk, path, data, state=True): """Sets the ZooKeeper registration up to be ephemeral. diff --git a/ndServiceRegistry/shims.py b/nd_service_registry/shims.py similarity index 94% rename from ndServiceRegistry/shims.py rename to nd_service_registry/shims.py index c54047d..63a32fa 100644 --- a/ndServiceRegistry/shims.py +++ b/nd_service_registry/shims.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""ndServiceRegistry Zookeeper Client Library +"""nd_service_registry Zookeeper Client Library Copyright 2012 Nextdoor Inc.""" @@ -20,7 +20,7 @@ import logging from kazoo.client import KazooClient -from ndServiceRegistry.funcs import rate_limiter +from nd_service_registry.funcs import rate_limiter # Our default variables from version import __version__ as VERSION diff --git a/ndServiceRegistry/version.py b/nd_service_registry/version.py similarity index 92% rename from ndServiceRegistry/version.py rename to nd_service_registry/version.py index 6cf9465..1dc5dff 100644 --- a/ndServiceRegistry/version.py +++ b/nd_service_registry/version.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.1.1' # http://semver.org/ +__version__ = '0.2.0' # http://semver.org/ diff --git a/ndServiceRegistry/watcher.py b/nd_service_registry/watcher.py similarity index 98% rename from ndServiceRegistry/watcher.py rename to nd_service_registry/watcher.py index ad845bf..4e9fa1e 100644 --- a/ndServiceRegistry/watcher.py +++ b/nd_service_registry/watcher.py @@ -24,7 +24,7 @@ import sys from os.path import split -from ndServiceRegistry import funcs +from nd_service_registry import funcs # For KazooServiceRegistry Class import kazoo.exceptions @@ -59,7 +59,7 @@ class Watcher(object): } """ - LOGGING = 'ndServiceRegistry.Watcher' + LOGGING = 'nd_service_registry.Watcher' def __init__(self, zk, path, callback=None, watch_children=True): # Create our logger @@ -194,7 +194,7 @@ class DummyWatcher(Watcher): want to be able to return valid data. """ - LOGGING = 'ndServiceRegistry.DummyWatcher' + LOGGING = 'nd_service_registry.DummyWatcher' def __init__(self, path, data, callback=None): # Create our logger diff --git a/setup.py b/setup.py index c79d8cc..9079566 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ from distutils.command.sdist import sdist from setuptools import setup -PACKAGE = 'ndServiceRegistry' +PACKAGE = 'nd_service_registry' __version__ = None execfile(os.path.join(PACKAGE, 'version.py')) # set __version__ @@ -46,19 +46,19 @@ def maybe_rm(path): if os.path.exists(path): shutil.rmtree(path) if self.all: - maybe_rm('ndServiceRegistry.egg-info') + maybe_rm('nd_service_registry.egg-info') maybe_rm('dist') setup( - name='ndServiceRegistry', + name='nd_service_registry', version=__version__, description='Nextdoor ServiceRegistry module for interacting with Apache Zookeeper.', long_description=open('README.rst').read(), author='Matt Wise', author_email='matt@nextdoor.com', - url='https://github.com/Nextdoor/ndServiceRegistry', - download_url='http://pypi.python.org/pypi/ndServiceRegistry#downloads', + url='https://github.com/Nextdoor/ndserviceregistry', + download_url='http://pypi.python.org/pypi/nd_service_registry#downloads', license='Apache License, Version 2.0', keywords='zookeeper apache zk', packages=[PACKAGE],