Miki Tebeka avatar Miki Tebeka committed f21464f

Python 2.6 support

Comments (0)

Files changed (4)

+from sys import version_info
+
 try:
     from setuptools import setup
 except ImportError:
     from distutils.core import setup
 
+install_requires = ['requests']
+if version_info[:2] < (2, 7):
+    install_requires.append('argparse')
+
 setup(
     name='whoops',
     version='0.1.0',
 
 from whoops import WebHDFS
 
-conn = WebHDFS('192.168.1.143', user='hdfs')
+conn = WebHDFS('cdh4', user='hdfs')
 remote = '/tmp/z138'
 new = '/tmp/8z'
 print('put')

whoops/__init__.py

     return wrapper
 
 
-octperm = '{:03o}'.format
-intparam = '{:d}'.format
+octperm = '{0:03o}'.format
+intparam = '{0:d}'.format
 boolparam = {True: 'true', False: 'false'}.get
 
 
     # Below here are some utility functions
     def _put(self, op, method, local, path, query):
         if not isfile(local):
-            raise WebHDFSError('put error: {} not found'.format(local))
+            raise WebHDFSError('put error: {0} not found'.format(local))
 
         resp = self._op(method, path, op, query)
         url = self._get_redirect(resp)
         # the url. Otherwise we'd just follow the redirects
         url = urlparse(resp.headers['Location'])
         host, port = url.netloc.split(':')
-        url = url._replace(netloc='{}:{}'.format(self.host, port))
+        url = url._replace(netloc='{0}:{1}'.format(self.host, port))
         return url.geturl()
 
     def _check_resp(self, resp):
         return resp
 
     def _op(self, method, path, op, query=None):
-        url = '{}{}?op={}'.format(self.base_url, path, op)
+        url = '{0}{1}?op={2}'.format(self.base_url, path, op)
 
         if self.user:
-            url += '&user.name={}'.format(self.user)
+            url += '&user.name={0}'.format(self.user)
 
         if query:
-            url += '&{}'.format(urlencode(query))
+            url += '&{0}'.format(urlencode(query))
 
         resp = requests.request(method, url, allow_redirects=False)
         return self._check_resp(resp)
 
     def _gen_base(self, host, port):
-        return 'http://{}:{}/webhdfs/v1'.format(host, port)
+        return 'http://{0}:{1}/webhdfs/v1'.format(host, port)

whoops/__main__.py

 def stat(args):
     info = fs.stat(args.path)
     msize = max(len(key) for key in info)
-    fmt = '{{:{}}}: {{}}'.format(msize)
+    fmt = '{{0:{}}}: {{1}}'.format(msize)
     for key, value in info.items():
         print(fmt.format(key, value))
 
     try:
         out = open(args.dest, mode)
     except IOError as err:
-        raise WebHDFSError('cannot open {} - {}'.format(args.dest, err))
+        raise WebHDFSError('cannot open {0} - {1}'.format(args.dest, err))
 
     try:
         data = fs.read(args.src, args.offset, args.length, args.buffersize)
 
 def put(args):
     if not isfile(args.src):
-        raise WebHDFSError('{} is not a file'.format(args.src))
+        raise WebHDFSError('{0} is not a file'.format(args.src))
 
     fs.put(args.src, args.dest, args.overwrite, args.blocksize,
            args.replication, args.mode, args.buffersize)
 
 def append(args):
     if not isfile(args.src):
-        raise WebHDFSError('{} is not a file'.format(args.src))
+        raise WebHDFSError('{0} is not a file'.format(args.src))
 
     fs.append(args.src, args.dest, args.buffersize)
 
                         default=None)
     parser.add_argument('--user', help='webhdfs user', default=None)
     parser.add_argument('--version', action='version',
-                        version='whoops {}'.format(__version__))
+                        version='whoops {0}'.format(__version__))
 
     subs = parser.add_subparsers()
 
     try:
         args.func(args)
     except WebHDFSError as err:
-        raise SystemExit('error: {}'.format(err))
+        raise SystemExit('error: {0}'.format(err))
     except ConnectionError as err:
         raise SystemExit(
-            'error: cannot connect - {}'.format(err.args[0].reason))
+            'error: cannot connect - {0}'.format(err.args[0].reason))
 
 
 if __name__ == '__main__':
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.