#!/usr/bin/python ############################################################################## ### ### parse-json.py ### ### A utility to parse a cassnadra-commands file and return the commands per type ### An Example for a json file: ### { ### "create":{ ### "choice_or_other":"CREATE TYPE IF NOT EXISTS choice_or_other (results text)", ### "vendor_license_model": "CREATE TABLE IF NOT EXISTS vendor_license_model (vlm_id text PRIMARY KEY, name text, description text, icon text)", ### "license_agreement": "CREATE TABLE IF NOT EXISTS license_agreement (vlm_id text, la_id text, name text, description text, type text, contract text, req_const text, fg_ids set, PRIMARY KEY (vlm_id, la_id))", ### "feature_group": "CREATE TABLE IF NOT EXISTS feature_group (vlm_id text, fg_id text, name text, description text, ep_ids set, lkg_ids set, refd_by_las set, PRIMARY KEY (vlm_id, fg_id))", ### "license_key_group": "CREATE TABLE IF NOT EXISTS license_key_group (vlm_id text,lkg_id text,name text,description text, type text, operational_scope text, ref_fgs set,PRIMARY KEY (vlm_id, lkg_id))", ### } ### } ### ### The return for "create" will be: ### CREATE TYPE IF NOT EXISTS choice_or_other (results text) ### CREATE TABLE IF NOT EXISTS vendor_license_model (vlm_id text PRIMARY KEY, name text, description text, icon text) ### CREATE TABLE IF NOT EXISTS license_agreement (vlm_id text, la_id text, name text, description text, type text, contract text, req_const text, fg_ids set, PRIMARY KEY (vlm_id, la_id)) ### CREATE TABLE IF NOT EXISTS feature_group (vlm_id text, fg_id text, name text, description text, ep_ids set, lkg_ids set, refd_by_las set, PRIMARY KEY (vlm_id, fg_id)) ### CREATE TABLE IF NOT EXISTS license_key_group (vlm_id text,lkg_id text,name text,description text, type text, operational_scope text, ref_fgs set,PRIMARY KEY (vlm_id, lkg_id)) ### Usage: ### ### parse-json.py -t create -f cassandra-commands.json ### ### For example: ### ### ### Author: Avi Ziv ### Version 1.0 ### Date: 3 May 2016 ### ############################################################################## import sys, getopt import json as json from collections import OrderedDict def readJsonFile(file, type): with open(file, 'r') as f: data = json.load(f, object_pairs_hook=OrderedDict) return data[type] def printJsonTypeEntries(jsonData): for i in jsonData.keys(): print(jsonData[i] + ';') def usage(): print('parseJsonFile.py [-f & -t