Commits

Miki Tebeka committed 708e6d3

listdir

Comments (0)

Files changed (4)

+About
+=====
+Python client for Hadoop WebHDFS_
+
+.. _WebHDFS: http://hadoop.apache.org/docs/r1.1.1/webhdfs.html

build/lib/webhdfs/__init__.py

Empty file added.
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+setup(
+    name='webhdfs',
+    version='0.1.0',
+    description='WebHDFS client',
+    long_description=open('README.rst').read(),
+    author='Miki Tebeka',
+    author_email='miki.tebeka@gmail.com',
+    license='MIT',
+    url='https://bitbucket.org/tebeka/webhdfs',
+    packages=['webhdfs'],
+    entry_points={
+        'console_scripts': [
+            'webhdfs = webhdfs.__main__:main',
+        ]
+    },
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: MIT License',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 3',
+        'Topic :: Software Development :: Libraries',
+        'Topic :: Software Development :: Libraries :: Python Modules',
+    ],
+    install_requires=['requests'],
+)

webhdfs/__init__.py

+import requests
+
+DEFAULT_HOST = 'localhost'
+DEFAULT_PORT = '50070'
+
+class WebHDFSError(Exception):
+    pass
+
+class WebHDFS(object):
+    def __init__(self, host=DEFAULT_HOST, port=DEFAULT_PORT):
+        self.host, self.port = host, port
+
+    def listdir(self, path):
+        url = 'http://{}:{}/webhdfs/v1{}?op=LISTSTATUS'.format(
+            self.host, self.port, path)
+
+        resp = requests.get(url)
+        if not resp.ok:
+            raise WebHDFSError
+
+        return resp.json()['FileStatuses']['FileStatus']
+
+
+