Commits

Miki Tebeka committed f45dcbe

packing

Comments (0)

Files changed (8)

+syntax: glob
+
+README.html
+build
+dist
+hive.egg-info/
+2013-01-10 version 0.1.0
+    * Initial release
+include README.rst ChangeLog *.sh
+What?
+=====
+Packing hive thrift client in more Pythonic way.
+
+Why?
+====
+Hive thrift libraries taken from CDH4 distribution and then mucked around to make
+the imports work.
+
+How?
+====
+In code
+-------
+::
+    
+    import hive
+    client = hive.connect(host, port)
+    client.execute('SHOW TABLES')
+    rows = client.fetchAll()
+
+Command line
+------------
+Poor mans hive client
+
+::
+
+    python -m hive [script]
+
+Who?
+====
+https://bitbucket.org/tebeka/hive

README.txt

-Packing hive thrift client in more Pythonic way
+__version__ = '0.1.0'
+
 DEFAULT_HOST = 'localhost'
 DEFAULT_PORT = 10000
 
 #!/usr/bin/env python
 
-from . import connect
+from . import connect, DEFAULT_HOST, DEFAULT_PORT, __version__
 from .hive_service import ThriftHive
 import re
 from os import environ
+from os.path import expanduser, isfile
 
-HOST = environ.get('HIVE_HOST', 'localhost')
-PORT = int(environ.get('HIVE_PORT', '10000'))
+HOST = environ.get('HIVE_HOST', DEFAULT_HOST)
+PORT = int(environ.get('HIVE_PORT', DEFAULT_PORT))
+
+HISTFILE = expanduser('~/.hive-history')
 
 
 def fix_hql(hql):
     # 'SHOW TABLES;' -> 'SHOW TABLES'
     return re.sub('\s*;+\s*$', '', hql, re.M|re.S)
 
+
 def repl(client):
     import readline
-    readline.parse_and_bind("tab: complete")
+    if isfile(HISTFILE):
+        readline.read_history_file(HISTFILE)
+
     while True:
         try:
             hql = raw_input('[hive] ').strip()
         except (KeyboardInterrupt, EOFError):
+            readline.write_history_file(HISTFILE)
             return
 
         hql = fix_hql(hql)
         except ThriftHive.HiveServerException as e:
             print('ERROR: {}'.format(e))
 
+
 def script(client, filename):
     with open(filename) as fo:
         hql = fo.read()
     parser.add_argument('--host', default=HOST)
     parser.add_argument('--port', default=PORT, type=int)
     parser.add_argument('script', help='script file', nargs='?')
+    parser.add_argument('--version', action='version', version=__version__)
     args = parser.parse_args(argv[1:])
 
     client = connect(args.host, args.port)
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+setup(
+    name='hive',
+    version='0.1.0',
+    description='Hive thrift client',
+    long_description=open('README.rst').read(),
+    author='Miki Tebeka',
+    author_email='miki.tebeka@gmail.com',
+    license='MIT',
+    url='https://bitbucket.org/tebeka/hive',
+    py_modules=['hive'],
+    install_requires=['thrift'],
+)