3 from StringIO import StringIO
6 from importCommon import *
7 #################################################################################################################################################################################
9 # Import all users from a given file #
12 # python importUsers.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] #
14 # shortest activation (be host = localhost, be port = 8080): #
15 # python importUsers.py [-f <input file> | --ifile=<input file> ] #
17 #################################################################################################################################################################################
19 def createNormativeElement(scheme, beHost, bePort, adminUser, fileDir, urlSuffix, ELEMENT_NAME, elementFormName):
22 log("in create normative element ", ELEMENT_NAME)
27 url = scheme + '://' + beHost + ':' + bePort + urlSuffix
31 adminHeader = 'USER_ID: ' + adminUser
32 #c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json', 'Accept: application/json', adminHeader])
33 c.setopt(pycurl.HTTPHEADER, [adminHeader])
36 path = fileDir + "/" + ELEMENT_NAME + ".zip"
39 send = [(elementFormName, (pycurl.FORM_FILE, path))]
41 c.setopt(pycurl.HTTPPOST, send)
43 #data = json.dumps(user)
44 #c.setopt(c.POSTFIELDS, data)
46 #c.setopt(c.WRITEFUNCTION, lambda x: None)
47 c.setopt(c.WRITEFUNCTION, buffer.write)
50 c.setopt(c.SSL_VERIFYPEER, 0)
52 #print("before perform")
55 #print("Before get response code")
56 httpRes = c.getinfo(c.RESPONSE_CODE)
58 debug("http response=", httpRes)
59 #print('Status: ' + str(responseCode))
60 debug("response buffer", buffer.getvalue())
63 return (ELEMENT_NAME, httpRes, buffer.getvalue())
65 except Exception as inst:
66 print("ERROR=" + str(inst))
67 return (ELEMENT_NAME, None, None)