from snakebite.client import Client client = Client('localhost', 54310) for p in client.mkdir(['/foo/bar', '/input'], create_parent=True): print p
from snakebite.client import Client from constants import NAMENODE_PORT client = Client('localhost', NAMENODE_PORT) for p in client.mkdir(['/foo/bar', '/input'], create_parent=True): print p
#!/usr/bin/env python from snakebite.client import Client client = Client('localhost', 9000) # specifying create_parent=True is the equivalent of mkdir -p for p in client.mkdir(['/foo/bar', '/another'], create_parent=True): print p
# To design a program which creates a directory in user directory # Execute the code as a hadoop user # sudo su hadoop # python make_dir.py from snakebite.client import Client client = Client('localhost', 8020) for p in client.mkdir(['/user/hadoop/test']): print(p)
from snakebite.client import Client client = Client('localhost', 8020) #port is the RPC port of the namenode. for i in client.ls(['/user/cloudera/behrouz']): #takes a list of paths!! print i #get this parameters from /etc/hadoop/conf/core-site.xml under the fs.defaults #many of the methods in snake bite return generators #creating a directory: #create two directories behrouz, behrouz1/b1 on HDFS: print '*' * 40 for p in client.mkdir(['/behrouz', 'behrouz1/b1'], create_parent=True): print p print '*' * 40 #deleting files and directories: deletes any subdirectories and files a directory contains #recursively deleting the directories! for p in client.delete(['/behrouz', 'behrouz1/b1'], recurse=True): print p print '*' * 40 # retrieving data from hdfs: #copying files from HDFS to Local file system: for f in client.copyToLocal(['/user/cloudera/wordCount.out'], '/home/cloudera/'): print f print '*' * 40 ####### #reading contents of a file for l in client.text(['/user/cloudera/testfile.txt']): print l #the text method automatically decompress and display gzip and bzip2 files.
client = Client('manager.novalocal', 8020) # Посмотрим, что у нас есть в рабочей директории for x in client.ls(['/student9_7']): print(x) ''' {'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1605967318187L, 'block_replication': 3, 'modification_time': 1605967318265L, 'length': 1705L, 'blocksize': 134217728L, 'owner': u'student9_7', 'path': '/student9_7/cur_readme'} {'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1605953216696L, 'block_replication': 3, 'modification_time': 1605953220706L, 'length': 7104L, 'blocksize': 134217728L, 'owner': u'student9_7', 'path': '/student9_7/googlobots.txt'} {'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1605966686950L, 'block_replication': 3, 'modification_time': 1605966688013L, 'length': 1705L, 'blocksize': 134217728L, 'owner': u'student9_7', 'path': '/student9_7/readme'} {'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1605964109596L, 'block_replication': 2, 'modification_time': 1605946691680L, 'length': 19L, 'blocksize': 134217728L, 'owner': u'student9_7', 'path': '/student9_7/test'} {'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1605964267111L, 'block_replication': 3, 'modification_time': 1605964267975L, 'length': 19L, 'blocksize': 134217728L, 'owner': u'student9_7', 'path': '/student9_7/test2'} {'group': u'supergroup', 'permission': 493, 'file_type': 'd', 'access_time': 0L, 'block_replication': 0, 'modification_time': 1605950057832L, 'length': 0L, 'blocksize': 0L, 'owner': u'student9_7', 'path': '/student9_7/testdir'} ''' # Создадим пару директорий for p in client.mkdir(['/student9_7/py_dir_01', '/student9_7/py_dir_02'], create_parent=True): print(p) ''' {'path': '/student9_7/py_dir_01', 'result': True} {'path': '/student9_7/py_dir_02', 'result': True} ''' # Удалим директорию `py_dir_01` for p in client.delete(['/student9_7/py_dir_01'], recurse=True): print(p) ''' {'path': '/student9_7/py_dir_01', 'result': True} ''' # Посмотрим что содержится в файле `test` for t in client.text(['/student9_7/test']):