Commit b607c5a3 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Improved snf-pithos-tools packages

- refactored tool scripts to python modules
- added console_scripts entry points in setup.py
- minor fix in dispatcher.py
parent 6ff6dcc8
Tools in this dir depend on being able to import pithos.
You need to adjust PYTHONPATH accordingly for this to work.
e.g.
export PYTHONPATH=$HOME/pithos
......@@ -38,9 +38,15 @@ import logging
from optparse import OptionParser
from carrot.connection import BrokerConnection
from carrot.messaging import Consumer
from carrot.messaging import Publisher
try:
from carrot.connection import BrokerConnection
from carrot.messaging import Consumer
from carrot.messaging import Publisher
except ImportError:
sys.stderr.write("Dispatcher requires 'carrot' python library to " \
"be installed\n")
sys.exit(1)
BROKER_HOST = 'localhost'
......@@ -56,7 +62,7 @@ CONSUMER_KEY = '#'
DEBUG = False
if __name__ == '__main__':
def main():
parser = OptionParser()
parser.add_option('-v', '--verbose', action='store_true', default=False,
dest='verbose', help='Enable verbose logging')
......@@ -81,14 +87,14 @@ if __name__ == '__main__':
parser.add_option('--test', action='store_true', default=False,
dest='test', help='Produce a dummy message for testing')
opts, args = parser.parse_args()
if opts.verbose:
DEBUG = True
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(name)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.DEBUG if DEBUG else logging.INFO)
logger = logging.getLogger('dispatcher')
conn = BrokerConnection(hostname=opts.host, port=opts.port,
userid=opts.user, password=opts.password,
virtual_host=opts.vhost)
......@@ -103,7 +109,7 @@ if __name__ == '__main__':
consumer = Consumer(connection=conn, queue=opts.queue,
exchange=opts.exchange, routing_key=opts.key,
exchange_type="topic")
callback = None
if opts.callback:
cb = opts.callback.rsplit('.', 1)
......@@ -111,16 +117,19 @@ if __name__ == '__main__':
__import__(cb[0])
cb_module = sys.modules[cb[0]]
callback = getattr(cb_module, cb[1])
def process_message(message_data, message):
logger.debug('%s', message_data)
if callback:
callback(message_data)
message.ack()
consumer.register_callback(process_message)
try:
consumer.wait()
except KeyboardInterrupt:
pass
if __name__ == '__main__':
main()
......@@ -323,7 +323,7 @@ class StoreFS(Operations):
return len(data)
if __name__ == '__main__':
def main():
if len(argv) != 2:
print 'usage: %s <mountpoint>' % argv[0]
exit(1)
......@@ -331,3 +331,8 @@ if __name__ == '__main__':
user = getuser()
fs = StoreFS(verbose=True)
fuse = FUSE(fs, argv[1], foreground=True)
if __name__ == '__main__':
main()
......@@ -750,6 +750,7 @@ def print_versions(data, f=stdout):
for id, t in data['versions']:
f.write('%s @ %s\n' % (str(id).rjust(30), datetime.fromtimestamp(float(t))))
def main():
try:
name = argv[1]
......@@ -769,5 +770,6 @@ def main():
status = '%s ' % f.status if f.status else ''
print '%s%s' % (status, f.data)
if __name__ == '__main__':
main()
......@@ -2114,8 +2114,14 @@ o_names = ['kate.jpg',
'photos/plants/rose.jpg',
'photos/me.jpg']
if __name__ == "__main__":
def main():
if get_user() == 'test':
unittest.main()
else:
print 'Will not run tests as any other user except \'test\' (current user: %s).' % get_user()
if __name__ == "__main__":
main()
......@@ -60,10 +60,6 @@ CLASSIFIERS = []
# Package requirements
INSTALL_REQUIRES = [
'Django>=1.2.3',
'SQLAlchemy>=0.6.3',
'MySQL-python>=1.2.2',
'psycopg2>=2.2.1'
]
EXTRAS_REQUIRES = {
......@@ -193,6 +189,11 @@ setup(
entry_points = {
'console_scripts': [
'snf-pithos-sh = pithos.tools.sh:main',
'snf-pithos-sync = pithos.tools.sync:main',
'snf-pithos-test = pithos.tools.test:main',
'snf-pithos-fs = pithos.tools.fs:main',
'snf-pithos-dispatcher = pithos.tools.dispatcher:main',
],
},
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment