labpack/storage/aws/s3.py
def import_records(self, bucket_name, import_path='', overwrite=True):

        '''
            a method to importing records from local files to a bucket

        :param bucket_name: string with name of bucket
        :param export_path: [optional] string with path to root directory of files
        :param overwrite: [optional] boolean to overwrite existing files matching records
        :return: True
        '''

        title = '%s.import_records' % self.__class__.__name__
        
    # validate inputs
        input_fields = {
            'bucket_name': bucket_name,
            'import_path': import_path
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)

    # validate path
        from os import path
        if not import_path:
            import_path = './'
        if not path.exists(import_path):
            raise ValueError('%s(import_path="%s") is not a valid path.' % (title, import_path))
        elif not path.isdir(import_path):
            raise ValueError('%s(import_path="%s") must be a directory.' % (title, import_path))
    
    # verify existence of bucket
        if not bucket_name in self.bucket_list:
            if not bucket_name in self.list_buckets():
                raise ValueError('S3 bucket "%s" does not exist in aws region %s.' % (bucket_name, self.iam.region_name))

    # create records from walk of local path
        self.iam.printer('Importing records from path "%s" to bucket "%s".' % (import_path, bucket_name), flush=True)
        from labpack.platforms.localhost import localhostClient
        localhost_client = localhostClient()
        import_path = path.abspath(import_path)
        for file_path in localhost_client.walk(import_path):
            relative_path = path.relpath(file_path, import_path)
            try:
                byte_data = open(file_path, 'rb').read()
                self.create_record(bucket_name, relative_path, byte_data, overwrite=overwrite)
                self.iam.printer('.', flush=True)
            except ValueError as err:
                if str(err).find('already contains') > -1:
                    self.iam.printer('.\n%s already exists. Record skipped. Continuing.' % relative_path, flush=True)
                else:
                    raise
            except:
                raise AWSConnectionError(title)

    # report completion and return true
        self.iam.printer(' done.')
        return True

            a method to importing records from local files to a bucket

        :param bucket_name: string with name of bucket
        :param export_path: [optional] string with path to root directory of files
        :param overwrite: [optional] boolean to overwrite existing files matching records
        :return: True
        
a method to importing records from local files to a bucket
a method to importing records from local files to a bucket
def import_records(self, bucket_name, import_path='', overwrite=True):
        title = '%s.import_records' % self.__class__.__name__
        input_fields = {
            'bucket_name': bucket_name,
            'import_path': import_path
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
        from os import path
        if not import_path:
            import_path = './'
        if not path.exists(import_path):
            raise ValueError('%s(import_path="%s") is not a valid path.' % (title, import_path))
        elif not path.isdir(import_path):
            raise ValueError('%s(import_path="%s") must be a directory.' % (title, import_path))
        if not bucket_name in self.bucket_list:
            if not bucket_name in self.list_buckets():
                raise ValueError('S3 bucket "%s" does not exist in aws region %s.' % (bucket_name, self.iam.region_name))
        self.iam.printer('Importing records from path "%s" to bucket "%s".' % (import_path, bucket_name), flush=True)
        from labpack.platforms.localhost import localhostClient
        localhost_client = localhostClient()
        import_path = path.abspath(import_path)
        for file_path in localhost_client.walk(import_path):
            relative_path = path.relpath(file_path, import_path)
            try:
                byte_data = open(file_path, 'rb').read()
                self.create_record(bucket_name, relative_path, byte_data, overwrite=overwrite)
                self.iam.printer('.', flush=True)
            except ValueError as err:
                if str(err).find('already contains') > -1:
                    self.iam.printer('.\n%s already exists. Record skipped. Continuing.' % relative_path, flush=True)
                else:
                    raise
            except:
                raise AWSConnectionError(title)
        self.iam.printer(' done.')
        return True
def import_records ( self , bucket_name , import_path = '' , overwrite = True ) : title = '%s.import_records' % self . __class__ . __name__ input_fields = { 'bucket_name' : bucket_name , 'import_path' : import_path } for key , value in input_fields . items ( ) : if value : object_title = '%s(%s=%s)' % ( title , key , str ( value ) ) self . fields . validate ( value , '.%s' % key , object_title ) from os import path if not import_path : import_path = './' if not path . exists ( import_path ) : raise ValueError ( '%s(import_path="%s") is not a valid path.' % ( title , import_path ) ) elif not path . isdir ( import_path ) : raise ValueError ( '%s(import_path="%s") must be a directory.' % ( title , import_path ) ) if not bucket_name in self . bucket_list : if not bucket_name in self . list_buckets ( ) : raise ValueError ( 'S3 bucket "%s" does not exist in aws region %s.' % ( bucket_name , self . iam . region_name ) ) self . iam . printer ( 'Importing records from path "%s" to bucket "%s".' % ( import_path , bucket_name ) , flush = True ) from labpack . platforms . localhost import localhostClient localhost_client = localhostClient ( ) import_path = path . abspath ( import_path ) for file_path in localhost_client . walk ( import_path ) : relative_path = path . relpath ( file_path , import_path ) try : byte_data = open ( file_path , 'rb' ) . read ( ) self . create_record ( bucket_name , relative_path , byte_data , overwrite = overwrite ) self . iam . printer ( '.' , flush = True ) except ValueError as err : if str ( err ) . find ( 'already contains' ) > - 1 : self . iam . printer ( '.\n%s already exists. Record skipped. Continuing.' % relative_path , flush = True ) else : raise except : raise AWSConnectionError ( title ) self . iam . printer ( ' done.' ) return True
a method to importing records from local files to a bucket
a method to importing records from local files to a bucket
'''
            a method to importing records from local files to a bucket

        :param bucket_name: string with name of bucket
        :param export_path: [optional] string with path to root directory of files
        :param overwrite: [optional] boolean to overwrite existing files matching records
        :return: True
        ''' # validate inputs # validate path # verify existence of bucket # create records from walk of local path # report completion and return true
None
self
bucket_name
string with name of bucket
string with name of bucket
import_path
overwrite
[optional] boolean to overwrite existing files matching records
[ optional ] boolean to overwrite existing files matching records
export_path
[optional] string with path to root directory of files
[ optional ] string with path to root directory of files