Permalink
Browse files

Added pep8 functionality in setup.py, and updated daikon.py to have m…

…ain catch exceptions. This should close #28, and update #47
  • Loading branch information...
1 parent b171fda commit 2b9ab618a0f208fd890cd4443ab78ed75d0850af @neogenix committed Nov 11, 2011
Showing with 69 additions and 18 deletions.
  1. +1 −1 MANIFEST.in
  2. +0 −1 daikon/__init__.py
  3. +9 −5 daikon/cluster.py
  4. +11 −1 daikon/config.py
  5. +11 −9 daikon/daikon.py
  6. +1 −0 daikon/exceptions.py
  7. +2 −1 daikon/index.py
  8. +1 −0 daikon/node.py
  9. +33 −0 setup.py
View
@@ -1,5 +1,5 @@
include daikon.conf
-include README.rst
include LICENSE
include AUTHORS
include HISTORY.rst
+include README.rst
View
@@ -15,4 +15,3 @@
#
__version__ = '1.0.4'
-
View
@@ -24,15 +24,17 @@ def cluster_status(cluster, host, port, extended):
request_health = requests.get('http://' + host + ':' + port +
'/_cluster/health?level=indices')
if request_health.error is not None:
- print 'ERROR: Fetching Cluster Status : "' + cluster + '" -', request_health.error
+ print 'ERROR: Fetching Cluster Status : "' + cluster + \
+ '" -', request_health.error
sys.exit(1)
else:
request_health.raise_for_status()
request_state = requests.get('http://' + host + ':' + port +
'/_cluster/state')
if request_state.error is not None:
- print 'ERROR: Fetching Cluster Status : "' + cluster + '" -', request_state.error
+ print 'ERROR: Fetching Cluster Status : "' + cluster + \
+ '" -', request_state.error
sys.exit(1)
else:
request_state.raise_for_status()
@@ -52,8 +54,10 @@ def cluster_status(cluster, host, port, extended):
print '\t\t Cluster Name:', data_result_state[u'cluster_name']
print '\t\t Master Node:', data_result_state[u'master_node']
if extended:
- print '\t\t\t Name:', data_result_state[u'nodes'][master_node][u'name']
- print '\t\t\t Transport Address:', data_result_state[u'nodes'][master_node][u'transport_address']
+ print '\t\t\t Name:', \
+ data_result_state[u'nodes'][master_node][u'name']
+ print '\t\t\t Transport Address:', \
+ data_result_state[u'nodes'][master_node][u'transport_address']
print '\t Indices:'
for index in data_result_state[u'metadata'][u'indices']:
@@ -77,7 +81,7 @@ def cluster_status(cluster, host, port, extended):
def cluster_shutdown(cluster, host, port):
try:
- request = requests.post('http://' + host + ':' + port + '/_shutdown' )
+ request = requests.post('http://' + host + ':' + port + '/_shutdown')
if request.error is not None:
print 'ERROR: Shutting Down Cluster : "' + cluster + '" -', request.error
sys.exit(1)
View
@@ -26,7 +26,7 @@ def __init__(self, arguments):
self.arguments = arguments
def config_setup(self):
- """ setup configuration, and read config files """
+ """ Setup configuration, and read config files """
self.config_parser = ConfigParser.ConfigParser()
@@ -39,13 +39,17 @@ def config_setup(self):
return self.config_parser
def cluster(self):
+ """ Cluster configuration """
+
if hasattr(self.arguments, "cluster") and self.arguments.cluster is not None:
cluster = self.arguments.cluster
else:
cluster = 'default'
return cluster
def host(self):
+ """ Host configuration """
+
if not self.config_parser.get(self.cluster(), 'host'):
raise ConfigError('No default host defined!\n')
elif hasattr(self.arguments, 'host') and self.arguments.host:
@@ -55,6 +59,8 @@ def host(self):
return host
def port(self):
+ """ Port configuration """
+
if not self.config_parser.get(self.cluster(), 'port'):
raise ConfigError('No default port defined!\n')
elif hasattr(self.arguments, 'port') and self.arguments.port:
@@ -64,6 +70,8 @@ def port(self):
return port
def replicas(self):
+ """ Replicas configuration """
+
if not self.config_parser.get(self.cluster(), 'replicas'):
raise ConfigError('No default replicas defined!\n')
elif hasattr(self.arguments, 'replicas') and self.arguments.replicas:
@@ -73,6 +81,8 @@ def replicas(self):
return replicas
def shards(self):
+ """ Shards configuration """
+
if not self.config_parser.get(self.cluster(), 'shards'):
raise ConfigError('No default shards defined!\n')
elif hasattr(self.arguments, 'shards') and self.arguments.shards:
View
@@ -16,15 +16,15 @@
#!/usr/bin/env python
-from config import configuration
-from exceptions import ConfigError
-
import index
import cluster
import node
-
+import sys
import argparse
+from config import configuration
+from exceptions import ConfigError
+
VERSION = __import__('daikon').__version__
@@ -164,8 +164,13 @@ def main():
# end
args = parser_main.parse_args()
- config = configuration(args)
- config.config_setup()
+
+ try:
+ config = configuration(args)
+ config.config_setup()
+ except ConfigError as error:
+ print error
+ sys.exit(1)
if hasattr(args, 'subparser_index_name'):
if args.subparser_index_name == 'list':
@@ -205,7 +210,4 @@ def main():
if __name__ == '__main__':
- try:
main()
- except ConfigError as error:
- print 'ERROR: Configuration Error - %s' % error
View
@@ -14,6 +14,7 @@
# limitations under the License.
#
+
class DaikonError(Exception):
""" Base Exception Class """
View
@@ -90,7 +90,8 @@ def index_list(host, port, extended):
else:
print '\t\t Status:', data_result_health[index][u'status']
print '\t\t Number Of Shards:', data_result_state[index][u'settings'][u'index.number_of_shards']
- print '\t\t Number Of Replicas:', data_result_state[index][u'settings'][u'index.number_of_replicas']
+ print '\t\t Number Of Replicas:', data_result_state[index][u'settings'][u'index.number_of_replicas']
+
def index_open(host, port, indexname):
try:
View
@@ -18,6 +18,7 @@
import anyjson as json
import sys
+
def node_status(host, port, extended):
try:
request = requests.get('http://' + host + ':' + port +
View
@@ -14,7 +14,37 @@
# limitations under the License.
#
+import os
+import sys
+
from setuptools import setup, find_packages
+from distutils.core import Command
+from subprocess import call
+
+
+class Pep8Command(Command):
+ description = "run pep8 script"
+ user_options = []
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ try:
+ import pep8
+ pep8
+ except ImportError:
+ print 'Missing "pep8" library. You can install it using pip: ' + \
+ 'pip install pep8'
+ sys.exit(1)
+
+ cwd = os.getcwd()
+ retcode = call(('pep8 %s/daikon/ %s/test/' % (cwd, cwd)).split(' '))
+ sys.exit(retcode)
+
setup(name='daikon',
version=__import__('daikon').__version__,
@@ -45,5 +75,8 @@
entry_points={
'console_scripts':
['daikon = daikon.daikon:main']
+ },
+ cmdclass={
+ 'pep8': Pep8Command
}
)

0 comments on commit 2b9ab61

Please sign in to comment.