def addUser(samweb, username, firstname=None, lastname=None, email=None, uid=None, groups=None): userdata = {'username': username} if firstname: userdata['first_name'] = firstname if lastname: userdata['last_name'] = lastname if email: userdata['email'] = email if uid is not None: try: uid = int(uid) except ValueError: raise ArgumentError("Invalid value for uid: %s" % uid) else: userdata['uid'] = uid if groups: userdata["groups"] = groups return samweb.postURL('/users', data=json.dumps(userdata), content_type='application/json', secure=True, role='*').text.rstrip()
def modifyFileMetadata(samweb, filename, md=None, mdfile=None): """ Modify file metadata arguments: filename md: dictionary containing metadata (default None) mdfile: file object containing metadata (must be in json format) """ if md: data = json.dumps(md) else: data = mdfile.read() url = _make_file_path(filename) return samweb.putURL(url + "/metadata", data=data, content_type='application/json', secure=True, role='*').text
def declareFile(samweb, md=None, mdfile=None): """ Declare a new file arguments: md: dictionary containing metadata (default None) mdfile: file object containing metadata (must be in json format) """ if md: data = json.dumps(md) elif mdfile: data = mdfile.read() else: raise ArgumentError('Must specify metadata dictionary or file object') return samweb.postURL('/files', data=data, content_type='application/json', secure=True).text
def validateFileMetadata(samweb, md=None, mdfile=None): """ Check the metadata for validity arguments: md: dictionary containing metadata (default None) mdfile: file object containing metadata (must be in json format) """ if md: data = json.dumps(md) elif mdfile: data = mdfile.read() else: raise ArgumentError('Must specify metadata dictionary or file object') return samweb.postURL('/files/validate_metadata', data=data, content_type='application/json').text
def addUser(samweb, username, firstname=None, lastname=None, email=None, uid=None, groups=None): userdata = { 'username' : username } if firstname: userdata['first_name'] = firstname if lastname: userdata['last_name'] = lastname if email: userdata['email'] = email if uid is not None: try: uid = int(uid) except ValueError: raise ArgumentError("Invalid value for uid: %s" % uid) else: userdata['uid'] = uid if groups: userdata["groups"] = groups return samweb.postURL('/users', data=json.dumps(userdata), content_type='application/json', secure=True, role='*').text.rstrip()
def modifyUser(samweb, username, **args): return samweb.postURL('/users/name/%s' % escape_url_path(username), data=json.dumps(args), content_type='application/json', secure=True).text.rstrip()