Commit 9dfb9730 authored by Christos Stavrakakis's avatar Christos Stavrakakis Committed by Nikos Skalkotos
Browse files

Make pithcat work with pithosmap:// URLs

Modify pithcat to be able to parse and work with URLs of the form:
`pithosmap://hash/size' which are neeed for archipelagos.
parent a7a7b869
......@@ -233,6 +233,8 @@ get_backend_type() {
if [[ "$id" =~ ^pithos: ]]; then
echo "pithos"
elif [[ "$id" =~ ^pithosmap: ]]; then
echo "pithos"
elif [[ "$id" =~ ^(http|ftp)s?: ]]; then
if [ "$network_backend_support" = "yes" ]; then
echo "network";
......
......@@ -28,6 +28,8 @@ the URL as the user when connecting to the backend.
from optparse import OptionParser
from sys import exit, stdout, stderr
from os import environ
from binascii import hexlify, unhexlify
from collections import namedtuple
try:
from pithos.backends.modular import ModularBackend
......@@ -44,30 +46,52 @@ parser.add_option('--data', dest='data', metavar='DIR',
parser.add_option('-s', action='store_true', dest='size', default=False,
help='print file size and exit')
LocationURL = namedtuple('LocationURL', ['account', 'container', 'object'])
HashmapURL = namedtuple('HashmapURL', ['hash', 'size'])
def urlsplit(url):
"""Returns (accout, container, object) from a location string"""
assert url.startswith('pithos://'), "Invalid URL"
t = url.split('/', 4)
assert len(t) == 5, "Invalid URL"
return t[2:5]
def parse_url(url):
if url.startswith('pithos://'):
t = url.split('/', 4)
assert len(t) == 5, "Invalid URL"
return LocationURL(*t[2:5])
elif url.startswith('pithosmap://'):
t = url.split('/', 3)
assert len(t) == 4, "Invalid URL"
return HashmapURL(*t[2:4])
else:
raise Exception("Invalid URL")
def print_size(backend, url):
"""Writes object's size to stdout."""
account, container, object = urlsplit(url)
meta = backend.get_object_meta(account, account, container, object, None)
print meta['bytes']
url = parse_url(url)
if type(url) is LocationURL:
account, container, object = url
meta = backend.get_object_meta(account, account, container, object,
None)
print meta['bytes']
elif type(url) is HashmapURL:
print url.size
else:
raise Exception("Invalid URL")
def print_data(backend, url):
"""Writes object's size to stdout."""
account, container, object = urlsplit(url)
size, hashmap = backend.get_object_hashmap(account, account, container,
object)
url = parse_url(url)
if type(url) is LocationURL:
account, container, object = url
size, hashmap = backend.get_object_hashmap(account, account, container,
object)
elif type(url) is HashmapURL:
hashmap = [hexlify(x) \
for x in backend.store.map_get(unhexlify(url.hash))]
size = int(url.size)
else:
raise Exception("Invalid URL")
for hash in hashmap:
block = backend.get_block(hash)
if len(block) > size:
......
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