def write_file(self, file_name, data): with open("%s" % file_name, 'w') as f: f.write(utils.format_json(data)) f.close() names = file_name.split('/') name = names[len(names) - 1] with open("%s/%s" % (self.dir_all, name), 'w') as f: f.write(utils.format_json(data)) f.close()
def show_stale_bindings(args): config.get_models( args, { "ietf_interfaces_interfaces", "interface_service_bindings_service_bindings" }) stale_ids, bindings = flows.get_stale_bindings(args) for iface_id in sorted(stale_ids): for binding in bindings[iface_id].itervalues(): # if binding.get('bound-services'): path = get_data_path('bindings', binding) print utils.format_json(bindings[iface_id]) print('http://{}:{}/restconf/config/{}'.format( args.ip, args.port, path))
def _process_response(self): resp = self._conn.getresponse() data = resp.read() if resp.status in [301, 302, 303, 307] and resp.getheader("location") != None: redirected_url = resp.getheader("location") return self.get(redirected_url) if data: decoded_data = simplejson.loads(data) logging.debug("response:" + utils.format_json(decoded_data)) if decoded_data["error"]: raise ErrorInResponseException( decoded_data, "Error occurred when remote driver (server) is processing the request:" + utils.format_json(decoded_data)) return decoded_data
def perform_ming(self, collection, command, params, duration, modify=None): if not command.startswith('find'): raise HTTPBadRequest('Not a find statement') query_params = json.loads(params, object_hook=json_util.object_hook) session = config['package'].model.DBSession cursor = [] for i, step in enumerate(command.split('.')): if step == 'find': args = query_params[i] cursor = session.find(collection, args) else: args = query_params[i] cmd = getattr(cursor, step) cursor = cmd(*args) isexplain = False if modify and modify.lower() == 'explain': cursor = cursor.ming_cursor.cursor.explain() isexplain = True return dict( action=command, params=format_json(params), result=cursor, collection=collection, duration=float(duration), isexplain=isexplain)
def to_json(self): dicts = { self.team1.team_name: self.team1.to_dict(), self.team2.team_name: self.team2.to_dict(), "contract": self.contract, } json_repr = json.dumps(dicts, indent=4) return format_json(json_repr)
def show_groups(args): odl_inventory_nodes_config = opendaylight_inventory.nodes( Model.CONFIG, args) of_nodes = odl_inventory_nodes_config.get_clist_by_key() groups = odl_inventory_nodes_config.get_groups(of_nodes) for dpn in groups: for group_key in groups[dpn]: print "Dpn: {}, ID: {}, Group: {}".format( dpn, group_key, utils.format_json(args, groups[dpn][group_key]))
def request(self, method, path, *params): if params: payload = utils.format_json(params) logging.debug("request:" + path + payload) else: payload = "" if not path.startswith("/hub") and not path.startswith("http://"): path = "/hub/session/%s/%s/" % (self._session_id, self._context) + path self._conn.request(method, path, body=payload, headers={"Accept": "application/json"}) return self._process_response()
def _process_response(self): resp = self._conn.getresponse() data = resp.read() if resp.status in [301, 302, 303, 307] and resp.getheader("location") != None: redirected_url = resp.getheader("location") return self.get(redirected_url) if resp.status == 200 and data: decoded_data = utils.load_json(data) logging.debug("response:" + utils.format_json(decoded_data)) if decoded_data["error"]: raise ErrorInResponseException( decoded_data, ("Error occurred when remote driver (server) is processing" "the request:") + utils.format_json(decoded_data), ) return decoded_data elif resp.status in [202, 204]: pass elif resp.status == 404: raise NoSuchElementException() else: raise RemoteDriverServerException("Server error in the remote driver server, status=%d" % resp.status)
def show_idpools(args): neutron_neutron = neutron.neutron(Model.CONFIG, args) ports = neutron_neutron.get_ports_by_key() iface_ids = [] for k, v in get_duplicate_ids(args).iteritems(): result = "Id:{},Keys:{}".format(k, json.dumps(v.get('id-keys'))) if v.get('pool-name'): result = "{},Pool:{}".format(result, v.get('pool-name')) if v.get('pool-name') == 'interfaces': iface_ids.extend(v.get('id-keys')) if v.get('parent-pool-name'): result = "{},ParentPool:{}".format(result, v.get('parent-pool-name')) print result print "\nNeutron Ports" print "=============" for id in iface_ids: port = ports.get(id, {}) print "Iface={}, NeutronPort={}".format(id, utils.format_json(args, port))
COURSE_COUNT = 15 print(f'Connecting to {config.db.uri}') print('Dropping the collection!') client = MongoClient(host=config.db.uri) db = client[config.db.name] db.drop_collection('courses') db.drop_collection('benchmarks') db.drop_collection('users') print('Initializing the collection!') directory = os.path.dirname(__file__) with open(os.path.join(directory, 'data.json')) as fp: courses = json.load(fp) courses = list(courses.values())[:COURSE_COUNT] courses = [utils.format_json(course) for course in courses] collection = db.benchmarks benchmarks = [ 'Benchmark 1.0', 'Benchmark 1.1', 'Benchmark 1.2', 'Benchmark 1.3', 'Benchmark 2.0' ] benchmarks = [{'name': name} for name in benchmarks] benchmarks = [utils.format_json(benchmark) for benchmark in benchmarks] collection.insert_many(benchmarks) assert collection.count() == len(benchmarks) print('Inserted {} benchmarks'.format(len(benchmarks))) print('Adding test benchmarks relationships!') benchmarks = list(map(lambda b: b['current']['name'], benchmarks)) for course, benchmark in zip(courses, benchmarks):
def show_elan_instances(args): elan_elan_instances = elan.elan_instances(Model.CONFIG, args) instances = elan_elan_instances.get_clist_by_key() for k, v in instances.items(): print "ElanInstance: {}, {}".format(k, utils.format_json(args, v))
def create(collection): result = collection.insert_one(utils.format_json(flask.request.json)) return str(result.inserted_id), http.HTTPStatus.CREATED
def to_json(self): dicts = {self.game_id: self.dicts} json_repr = prettyjson(dicts) json_repr = format_json(json_repr) return json_repr
def process_item(self, item, spider): # print item print format_json(item) return item
def to_json(self): json_repr = prettyjson(self.games) json_repr = format_json(json_repr) return json_repr
#!/usr/bin/env python2.6 # # Copyright (C) 2011 by Brian Weck # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php # # import utils from cssbot import reddit utils.usage(1, "usage: %s id") fetch_id = utils.argv(1) r = reddit.APIWrapper() r.num_retries = 0 x = r.get_comments(fetch_id) print utils.format_json(x)