Revision a5f6a683

b/snf-image-host/create
79 79
        image_size=$($CURL -sI "$IMAGE_NAME" | grep ^Content-Length: | cut -d" " -f2)
80 80
        ;;
81 81
    pithos)
82
        cmd_args="--db $(printf "%q" "${PITHOS_DB}") \
83
                  --data $(printf "%q" "${PITHOS_DATA}") \
84
                  $(printf "%q" "${IMAGE_NAME}")"
82
        # For security reasons pass the database url to pithcat as an
83
        # environmental variable.
84
        export PITHCAT_INPUT_DB="$PITHOS_DB"
85
        export PITHCAT_INPUT_DATA="$PITHOS_DATA"
86
        cmd_args="$(printf "%q" "${IMAGE_NAME}")"
85 87
        image_cmd="./pithcat $cmd_args"
86 88
        image_size=$(./pithcat -s  $cmd_args)
87 89
        ;;
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