Revision a5f6a683 snf-image-host/pithcat
b/snf-image-host/pithcat | ||
---|---|---|
27 | 27 |
|
28 | 28 |
from optparse import OptionParser |
29 | 29 |
from sys import exit, stdout, stderr |
30 |
from os import environ |
|
30 | 31 |
|
31 | 32 |
try: |
32 | 33 |
from pithos.backends.modular import ModularBackend |
... | ... | |
46 | 47 |
|
47 | 48 |
def urlsplit(url): |
48 | 49 |
"""Returns (accout, container, object) from a location string""" |
49 |
|
|
50 |
|
|
50 | 51 |
assert url.startswith('pithos://'), "Invalid URL" |
51 | 52 |
t = url.split('/', 4) |
52 | 53 |
assert len(t) == 5, "Invalid URL" |
... | ... | |
55 | 56 |
|
56 | 57 |
def print_size(backend, url): |
57 | 58 |
"""Writes object's size to stdout.""" |
58 |
|
|
59 |
|
|
59 | 60 |
account, container, object = urlsplit(url) |
60 | 61 |
meta = backend.get_object_meta(account, account, container, object, None) |
61 | 62 |
print meta['bytes'] |
... | ... | |
63 | 64 |
|
64 | 65 |
def print_data(backend, url): |
65 | 66 |
"""Writes object's size to stdout.""" |
66 |
|
|
67 |
|
|
67 | 68 |
account, container, object = urlsplit(url) |
68 | 69 |
size, hashmap = backend.get_object_hashmap(account, account, container, |
69 | 70 |
object) |
... | ... | |
77 | 78 |
|
78 | 79 |
def main(): |
79 | 80 |
options, args = parser.parse_args() |
80 |
if len(args) != 1 or not options.db or not options.data:
|
|
81 |
if len(args) != 1: |
|
81 | 82 |
parser.print_help() |
82 | 83 |
exit(1) |
83 | 84 |
|
84 | 85 |
url = args[0] |
85 |
backend = ModularBackend(None, options.db, None, options.data) |
|
86 |
|
|
86 |
|
|
87 |
if not options.data and 'PITHCAT_INPUT_DATA' not in environ: |
|
88 |
stderr.write("Pithos data directory path is missing.\n") |
|
89 |
exit(1) |
|
90 |
|
|
91 |
data_path = environ['PITHCAT_INPUT_DATA'] if not options.data else \ |
|
92 |
options.data |
|
93 |
|
|
94 |
if not options.db and 'PITHCAT_INPUT_DB' not in environ: |
|
95 |
stderr.write("Pithos database uri is missing.\n") |
|
96 |
exit(1) |
|
97 |
|
|
98 |
db_uri = environ['PITHCAT_INPUT_DB'] if not options.db else options.db |
|
99 |
|
|
100 |
backend = ModularBackend(None, db_uri, None, data_path) |
|
101 |
|
|
87 | 102 |
if options.size: |
88 | 103 |
print_size(backend, url) |
89 | 104 |
else: |
Also available in: Unified diff