Python MogileFS Client
Python
Switch branches/tags
Nothing to show
Clone or download
Phạm Tuấn Anh
Latest commit ee4013f Dec 20, 2017

README.md

MogileFS client library for Python

Installation

$ pip install pymogile

Examples

Connect to MogileFS

>>> from pymogile import Client, MogileFSError
>>> datastore = Client(domain='test', trackers=['127.0.0.1:7001'])

New file

>>> fp = datastore.new_file('foobar.txt')
>>> fp.write('foo')
>>> fp.close()

Get paths

>>> datastore.get_paths('foobar.txt')
['http://127.0.0.1:7500/dev4/0/000/251/0000251237.fid', 'http://127.0.0.1:7500/dev6/0/000/251/0000251237.fid']
>>> print datastore.get_paths('404.txt')
[]

Get file data

>>> datastore.get_file_data('404.txt')
>>> datastore.get_file_data('foobar.txt')
'foo'

File info

>>> datastore.file_info('foobar.txt')
{'class': 'default',
 'devcount': '2',
 'domain': 'test',
 'fid': '0000251237',
 'key': 'foobar.txt',
 'length': 3}
>>> datastore.file_info('foobar.txt', devices=True)
{'class': 'default',
 'devcount': '2',
 'devids': ['4', '6'],
 'domain': 'test',
 'fid': '0000251237',
 'key': 'foobar.txt',
 'length': 3}

Rename file

>>> datastore.rename('404.txt', 'test.txt')
False
>>> datastore.rename('foobar.txt', 'foo.txt')
True
>>> datastore.get_file_data('foobar.txt')
>>> datastore.get_file_data('test.txt')
>>> datastore.get_file_data('foo.txt')
'foo'

Remove file

>>> datastore.delete('foobar.txt')
False
>>> datastore.delete('foo.txt')
True
>>> datastore.get_file_data('foo.txt')