daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jun 7th, 2017 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python2.5
  2.  
  3. import sys
  4. import getopt
  5. from getpass import getpass
  6. from ZSI import ServiceProxy
  7.  
  8. import csv
  9. import xml.dom.minidom
  10.  
  11. ###################################################
  12. # set default values
  13.  
  14. port=8080
  15. host="drop2.lms.gatech.edu"
  16. proto="http"
  17. file="populate.csv"
  18.  
  19. ####################################################
  20. # Handle command line options
  21.  
  22. def usage(rcode=1):
  23.   print "usage: ", sys.argv[0], " [--file,-f=<file> --host=<hostname> --port=,-p<port> --help,-h --ssl,-s]"
  24.   sys.exit(rcode)
  25. try:
  26.   optlist, args = getopt.getopt(sys.argv[1:], "f:sh:p:", ['help', 'port=', 'host=', 'ssl', 'file='])
  27. except getopt.GetoptError:
  28.   usage()
  29. for opt, arg in optlist:
  30.   if opt in ["-h", "--help"]:
  31.     usage(0)
  32.   elif opt in ["--host"]:
  33.     host=arg
  34.     continue
  35.   elif opt in ["-p", "--port"]:
  36.     port=int(arg)
  37.     continue
  38.   elif opt in ["-s", "--ssl"]:
  39.     proto='https'
  40.     continue
  41.   elif opt in ["-f", "--file"]:
  42.     file=arg
  43.     continue
  44.  
  45. ############################################
  46. # Log into the web service
  47.  
  48. login_wsdl = proto + '://' + host + ':' + str(port) + '/sakai-axis/SakaiLogin.jws?wsdl'
  49. login = ServiceProxy.ServiceProxy(login_wsdl)
  50.  
  51. user=raw_input("username: ")
  52. password=getpass("password: ")
  53. session=login.login(id=user, pw=password)['loginReturn']
  54.  
  55. ############################################
  56. # XML Helper Methods
  57.  
  58. def getText(nodelist):
  59.   rc = ""
  60.   for node in nodelist:
  61.     if node.nodeType == node.TEXT_NODE:
  62.       rc = rc + node.data
  63.   return rc
  64.  
  65. ############################################
  66. # Scripted actions below
  67.  
  68. script = ServiceProxy.ServiceProxy(script_wsdl)
  69.  
  70. reader = csv.reader(open(file, "rb"))
  71.  
  72. def addpage(siteid, title):
  73.   print "Adding page to \"" + siteid + "\" called \"" + title + "\": ",
  74.   result=script.addNewPageToSite(sessionid=session, siteid=siteid, pagetitle=title, pagelayout=0)["addNewPageToSiteReturn"]
  75.   print result
  76.  
  77. def addtool(siteid, pagetitle, toolid):
  78.   print "Adding \"" + toolid + "\" to \"" + siteid + ": ",
  79.   result=script.addNewToolToPage(sessionid=session, siteid=siteid, pagetitle=pagetitle, tooltitle=pagetitle, toolid=toolid, layouthints="")["addNewToolToPageReturn"]
  80.   print result
  81.  
  82. def addsite(siteid, title, joinable, joinerrole, published, publicview, type):
  83.   print "Adding site \"" + siteid + "\": ",
  84.   result=script.addNewSite(sessionid=session, siteid=siteid, title=title, description="", shortdesc="", iconurl="", infourl="", joinable=joinable, joinerrole=joinerrole, published=published, publicview=publicview, skin="", type=type)["addNewSiteReturn"]
  85.   print result
  86.  
  87. def adduser(eid, firstname, lastname, email, type, password):
  88.   print "Adding user \"" + eid + "\": ",
  89.   result=script.addNewUser(sessionid=session, eid=eid, id=eid, firstname=firstname, lastname=lastname, email=email, type=type, password=password)["addNewUserReturn"]
  90.   print result
  91.  
  92. def addutos(siteid, eid, roleid):
  93.   print "Adding user \"" + eid + "\" to site \"" + siteid + "\": ",
  94.   result=script.addMemberToSiteWithRole(sessionid=session, siteid=siteid, eid=eid, roleid=roleid)["addMemberToSiteWithRoleReturn"]
  95.   print result
  96.  
  97. for row in reader:
  98.   #print "Processing line", str(reader.line_num) + ": ",
  99.   action = row[0]
  100.   if (action == "addUserToSite"):
  101.     siteid = row[1]
  102.     eid = row[2]
  103.     roleid = row[3]
  104.     addutos(siteid, eid, roleid)
  105.   elif (action == "addSite"):
  106.     siteid = row[1]
  107.     title = row[2]
  108.     joinable = row[3]
  109.     joinerrole = row[4]
  110.     published = row[5]
  111.     publicview = row[6]
  112.     type = row[7]
  113.     addsite(siteid, title, joinable, joinerrole, published, publicview, type)
  114.     addpage(siteid, "Site Info")
  115.     addtool(siteid, "Site Info", "sakai.siteinfo")
  116.   elif (action == "addTool"):
  117.     siteid = row[1]
  118.     pagetitle = row[2]
  119.     toolid = row[3]
  120.     addpage(siteid, pagetitle)
  121.     addtool(siteid, pagetitle, toolid)
  122.   elif (action == "addUser"):
  123.     eid = row[1]
  124.     firstname = row[2]
  125.     lastname = row[3]
  126.     email = row[4]
  127.     type = row[5]
  128.     password = row[6]
  129.     adduser(eid, firstname, lastname, email, type, password)
  130.   elif (action == "comment"):
  131.     continue
  132.   else:
  133.     print "I don't know how to \"" + action + "\" skipping."
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top