-
Notifications
You must be signed in to change notification settings - Fork 16
/
sst.py
executable file
·67 lines (59 loc) · 2.49 KB
/
sst.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specif
# a stand alone script to read metadata of a given SSTable
from sstmd import SSTableMetadata
from sstidx import IndexInfo
from sstable import SSTableFileName,SSTableReader
import sstable2json
import argparse
import sys
import os
parser = argparse.ArgumentParser(prog="sst")
parser.add_argument("-m", "--metadata", help="display SSTable metadata", action="store_true")
parser.add_argument("-i", "--index", help="display SSTable index information", action="store_true")
parser.add_argument("-d", "--data", help="display SSTable data in json format", action="store_true")
parser.add_argument("-c", "--cql", help="display SSTable cql rows", action="store_true")
parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")
parser.add_argument("sstable", type=str, help="SSTable file")
args = parser.parse_args()
option = "metadata"
verbose = False
if args.verbose:
verbose = True
if args.sstable is None:
print "please specify sstable file"
sys.exit(1)
filename = args.sstable
sstable = SSTableFileName.parse(filename, verbose)
if args.metadata:
metadata = SSTableMetadata.parse(sstable.statfile(), sstable.sstversion)
print metadata
elif args.index:
index = IndexInfo.parse(sstable.indexfile())
print index
elif args.data:
if os.path.isfile(sstable.datafile()) != True:
print "%s not exists" % sstable.datafile()
sys.exit(1)
if os.path.isfile(sstable.datafile()) != True:
print "%s not exists" % sstable.datafile()
sys.exit(1)
compressed = True
if os.path.isfile(sstable.compfile()) != True:
compressed = False
reader = SSTableReader(sstable.indexfile(), sstable.datafile(), sstable.compfile(), compressed, args.cql, args.verbose)
sstable2json.export(reader)