def generic_put(self, if_convert, file_name=None):
        if(file_name):
            self.source_file = file_name

        if self.local_size < 512*1024:
            if_resumable = False
        else:
            if_resumable = True
        
        media_body = MediaFileUpload(
            self.source_file,
            mimetype=self.mime_type,
            resumable=if_resumable)

        if self.folder_id is None:
            parents = []
        else:
            parents = [{
                "kind": "drive#fileLink",
                "id": self.folder_id}]

        body = {
            'title': self.title,
            'description': self.description,
            'mimeType': self.mime_type,
            'parents': parents}

        if(self.file_id):
            if(self.gas_new):
                request = self.service.files().insert(
                    body=body, media_body=media_body, convert=if_convert)
            else:
                request = self.service.files().update(body=body, media_body=media_body,
                                                      convert=if_convert, fileId=self.file_id)
        else:
            request = self.service.files().insert(
                body=body, media_body=media_body, convert=if_convert)

        service_response = None

        print "Uploading file: %s" % self.source_file
        print "File size: %s" % self.sizeof_fmt(self.local_size)

        if( if_resumable ):
            while service_response is None:
                status, service_response = request.next_chunk(num_retries=10)
                if status:
                    sys.stdout.write(
                        "\rCompleted: %.2f%%" %
                        (status.progress() * 100))
                    sys.stdout.flush()
                else:
                    sys.stdout.write("\rCompleted!%s\n" % (" " * 10))
                    sys.stdout.flush()

        else:
            service_response = request.execute()

        if self.permission is not None:
            pass_action = {
                "name":"insert",
                "param":self.permission}

            perm = GDPerm(service_response['id'], pass_action)
            result = perm.run()
            logger.debug(result)
       
        return service_response
dataset/ETHPy150Open tienfuc/gdcmdtools/gdcmdtools/put.py/GDPut.generic_put/original