예제 #1
0
    def save(self, uri, uncompressed=False):
        '''
        Saves this recording to a URI as a compressed .tar.gz file.
        Returns the URI of what was saved, or None if there was a problem.

        Optional argument 'uncompressed' may be used to force the save
        to occur as a directory full of uncompressed files, but this only
        works for URIs that point to the local filesystem.

        For example:

        # Save to a local directory, use automatic filename
        rec.save('/home/username/recordings/')

        # Save it to a local file, with a specific name
        rec.save('/home/username/recordings/my_recording.tar.gz')

        # Same, but with an explicit file:// prefix
        rec.save('file:///home/username/recordings/my_recording.tar.gz')

        # Save it to the nems_db running on potoroo, use automatic filename
        rec.save('http://potoroo/recordings/')

        # Save it to the nems_db running on potoroo, specific filename
        rec.save('http://potoroo/recordings/my_recording.tar.gz')

        # Save it to AWS (TODO, Not Implemented, Needs credentials)
        rec.save('s3://nems.amazonaws.com/somebucket/')
        '''
        guessed_filename = self.name + '.tar.gz'
        # Set the URI metadata since we are writing to a URI now
        if not self.uri:
            self.uri = uri
        if local_uri(uri):
            uri = local_uri(uri)
            print(uri)
            if targz_uri(uri):
                return self.save_targz(uri)
            elif uncompressed:
                return self.save_dir(uri)
            else:
                #print(uri + '/' + guessed_filename)
                return self.save_targz(uri + '/' + guessed_filename)
        elif http_uri(uri):
            uri = http_uri(uri)
            if targz_uri(uri):
                return self.save_url(uri)
            elif uri[-1] == '/':
                return self.save_url(uri + guessed_filename)
            else:
                return self.save_url(uri + '/' + guessed_filename)
        elif uri[0:6] == 's3://':
            raise NotImplementedError
        else:
            raise ValueError('Invalid URI: {}'.format(uri))
예제 #2
0
    def load(uri):
        '''
        Loads from a local .tar.gz file, a local directory, from s3,
        or from an HTTP URL containing a .tar.gz file. Examples:

        # Load all signals in the gus016c-a2 directory
        rec = Recording.load('/home/myuser/gus016c-a2')
        rec = Recording.load('file:///home/myuser/gus016c-a2')

        # Load the local tar gz directory.
        rec = Recording.load('file:///home/myuser/gus016c-a2.tar.gz')

        # Load a tar.gz file served from a flat filesystem
        rec = Recording.load('http://potoroo/recordings/gus016c-a2.tar.gz')

        # Load a tar.gz file created by the nems-baphy interafce
        rec = Recording.load('http://potoroo/baphy/271/gus016c-a2')

        # Load from S3:
        rec = Recording.load('s3://nems.lbhb... TODO')
        '''
        if local_uri(uri):
            if targz_uri(uri):
                rec = Recording.load_targz(local_uri(uri))
            else:
                rec = Recording.load_dir(local_uri(uri))
        elif http_uri(uri):
            rec = Recording.load_url(http_uri(uri))
        elif uri[0:6] == 's3://':
            raise NotImplementedError
        else:
            raise ValueError('Invalid URI: {}'.format(uri))
        rec.uri = uri
        return rec