def create(args, FIELDS_URL): """create a field""" data = parse_opts(args) for arg in ('name', 'field_type'): if arg not in data: raise Exception("Creating a Field requires a " + arg) rsp = json_http(FIELDS_URL, method='POST', data=data) print "Created New Field: " + data['name'] + " at: " + FIELDS_URL
def update(args, FIELDS_URL): """modify properties of a Field""" data = parse_opts(args) if 'name' not in data: raise Exception("Updating a Field requires a name") name = data['name'] del data['name'] json_http(FIELDS_URL + "/" + name, method='PUT', data=data) print "Updated Field: " + name
def update(args, DS_URL): """modify properties of a datasource""" data = parse_opts(args) i = get_id(data) if i is None: raise Exception( "Updating a DataSource requires either an id or a name") json_http(DS_URL + "/" + i, method='PUT', data=data) print "Updated DataSource #" + i
def schedule(args, DS_URL): """modify the schedule of a datasource""" data = parse_opts(args) i = get_id(data) if i is None: raise Exception( "Modifying the schedule of a DataSource requires either an id or a name" ) json_http(DS_URL + "/" + i + '/schedule', method='PUT', data=data) print "Updated Schedule of DataSource #" + i
def delete(args, DS_URL): """remove a datasource""" if 1 != len(args): raise Exception("wrong number of args for deleting a DataSource") i = get_id(parse_opts(args)) if i is None: raise Exception( "Must supply either an id or a name for a DataSource to delete it") json_http(DS_URL + '/' + i, method='DELETE') print "Deleted DataSource #" + i
def create(args, DS_URL, added_data=None): """create a datasource""" data = parse_opts(args) if 'name' not in data: raise Exception("Creating a DataSource requires a name") if 'type' not in data: raise Exception("Creating a DataSource requires a type") if 'crawler' not in data: raise Exception("Creating a DataSource requires a crawler") if added_data: data.update(added_data) rsp = json_http(DS_URL, method='POST', data=data) print "Created New DataSource: " + str( rsp['id']) + " with name: " + data['name'] + " at " + DS_URL return rsp['id']
def history(args, DS_URL): """display the indexing history of a datasource""" if 1 != len(args): raise Exception("wrong number of args for showing a DataSource") i = get_id(parse_opts(args)) if i is None: raise Exception( "Must supply either an id or a name to view the indexing history of a DataSource" ) url = DS_URL + "/" + i + '/history' data = json_http(url) print "History of DataSource #" + i + ": " + url + " => " + pretty_json( data)
def status(args, DS_URL): """display status of datasources""" if 1 < len(args): raise Exception("wrong number of args for showing DataSource status") i = get_id(parse_opts(args)) if (i is not None): url = DS_URL + '/' + i + '/status' data = json_http(url) print "Status of DataSource #" + i + ": " + url + " => " + pretty_json( data) else: url = DS_URL + "/all/status" data = json_http(url) print "Status of All DataSources: " + url + " => " + pretty_json(data)
def show(args, DS_URL): """display current datasources""" if 1 < len(args): raise Exception("wrong number of args for showing a DataSource") i = get_id(parse_opts(args)) if (i is None): print 'Data Sources: ' + DS_URL data = json_http(DS_URL) if 0 == len(data): print ' (none)' else: for ds in data: print_ds(ds, ' ') else: print_ds(json_http(DS_URL + '/' + i))
def update(args, SETTINGS_URL): """modify settings""" data = parse_opts(args) json_http(SETTINGS_URL, method='PUT', data=data) print "Updated Settings"