def create(url, filename, properties):
        """Create new subject at given SCO-API by uploading local file.
        Expects an tar-archive containing FreeSurfer archive file. Allows to
        update properties of created resource.

        Parameters
        ----------
        url : string
            Url to POST image group create request
        filename : string
            Path to tar-archive on local disk
        properties : Dictionary
            Set of additional properties for subject (may be None)

        Returns
        -------
        string
            Url of created subject resource
        """
        # Ensure that the file has valid suffix
        if not has_tar_suffix(filename):
            raise ValueError('invalid file suffix: ' + filename)
        # Upload file to create subject. If response is not 201 the uploaded
        # file is not a valid FreeSurfer archive
        files = {'file': open(filename, 'rb')}
        response = requests.post(url, files=files)
        if response.status_code != 201:
            raise ValueError('invalid file: ' + filename)
        # Get image group HATEOAS references from successful response
        links = references_to_dict(response.json()['links'])
        resource_url = links[REF_SELF]
        # Update subject properties if given
        if not properties is None:
            obj_props = []
            # Catch TypeErrors if properties is not a list.
            try:
                for key in properties:
                    obj_props.append({'key':key, 'value':properties[key]})
            except TypeError as ex:
                raise ValueError('invalid property set')
            try:
                req = urllib2.Request(links[REF_UPSERT_PROPERTIES])
                req.add_header('Content-Type', 'application/json')
                response = urllib2.urlopen(
                    req,
                    json.dumps({'properties' : obj_props})
                )
            except urllib2.URLError as ex:
                raise ValueError(str(ex))
        return resource_url
def create ( url , filename , properties ) : if not has_tar_suffix ( filename ) : raise ValueError ( 'invalid file suffix: ' + filename ) files = { 'file' : open ( filename , 'rb' ) } response = requests . post ( url , files = files ) if response . status_code != 201 : raise ValueError ( 'invalid file: ' + filename ) links = references_to_dict ( response . json ( ) [ 'links' ] ) resource_url = links [ REF_SELF ] if not properties is None : obj_props = [ ] try : for key in properties : obj_props . append ( { 'key' : key , 'value' : properties [ key ] } ) except TypeError as ex : raise ValueError ( 'invalid property set' ) try : req = urllib2 . Request ( links [ REF_UPSERT_PROPERTIES ] ) req . add_header ( 'Content-Type' , 'application/json' ) response = urllib2 . urlopen ( req , json . dumps ( { 'properties' : obj_props } ) ) except urllib2 . URLError as ex : raise ValueError ( str ( ex ) ) return resource_url
Create new subject at given SCO-API by uploading local file.
        Expects an tar-archive containing FreeSurfer archive file. Allows to
        update properties of created resource.

        Parameters
        ----------
        url : string
            Url to POST image group create request
        filename : string
            Path to tar-archive on local disk
        properties : Dictionary
            Set of additional properties for subject (may be None)

        Returns
        -------
        string
            Url of created subject resource