Google Search Appliance Feeds Protocol Developers Guide User Manual
Page 25

Google Search Appliance: Feeds Protocol Developer’s Guide
25
The following example shows a groups feed client written in Python.
# Copyright 2013 Google Inc. All Rights Reserved.
"""A helper script that pushes a groups xml file to the feeder."""
import getopt
import mimetypes
import sys
import urllib2
def PrintMessage():
"""Print help message for command usage."""
print """Usage: %s ARGS
--groupsource:
sharepoint, ggg, ldap or others
--url:
groupsfeed url of the feedergate, e.g. http://gsabox:19900/xmlgroups
--groupsfilename:
The groups xml file you want to feed
--help: output this message""" % sys.argv[0]
def main(argv):
"""Process command line arguments and send feed to the webserver."""
try:
opts, _ = getopt.getopt(argv[1:], None,
["help", "groupsource=",
"url=", "groupsfilename="])
except getopt.GetoptError:
# print help information and exit:
PrintMessage()
sys.exit(2)
groupsource = None
url = None
groupsfilename = None
for opt, arg in opts:
if opt == "--help":
PrintMessage()
sys.exit()
if opt == "--groupsource":
groupsource = arg
if opt == "--url":
url = arg
if opt == "--groupsfilename":
groupsfilename = arg
params = []
if (url and groupsfilename and
groupsource in ("sharepoint", "ggg", "ldap", "others")):
params.append(("groupsource", groupsource))
data = ("data", groupsfilename, open(groupsfilename, "r").read())
request_url = PostMultipart(url, params, (data,))
print urllib2.urlopen(request_url).read()
else:
PrintMessage()
sys.exit(1)