Exemple #1
0
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()
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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()
Exemple #8
0
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
Exemple #9
0
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()
Exemple #10
0
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()