diff options
author | Vilém Duha <vilda.novak@gmail.com> | 2019-08-11 00:37:57 +0300 |
---|---|---|
committer | Vilém Duha <vilda.novak@gmail.com> | 2019-08-12 16:58:36 +0300 |
commit | 30660b7d903a3fcd326c7238dced696e5029e500 (patch) | |
tree | d07b651936459552871de8d668f0808c0115df7e /blenderkit/upload.py | |
parent | 2b787dcb98e042ad0dda4dc315ced54d383f76ec (diff) |
BlenderKit: upload reworked.
Don't save .blend file , some users didn't like this.
Re-upload enables only thumbnail updates.
Mark for validation operator removed(was removed from UI several versions ago)
ModelUploadOperator renamed to UploadOperator, since it's used for all asset types anyway.
Skip .blend preparation in case of thumbnail reupload only
Diffstat (limited to 'blenderkit/upload.py')
-rw-r--r-- | blenderkit/upload.py | 135 |
1 files changed, 54 insertions, 81 deletions
diff --git a/blenderkit/upload.py b/blenderkit/upload.py index 9d338803..e8183684 100644 --- a/blenderkit/upload.py +++ b/blenderkit/upload.py @@ -537,7 +537,7 @@ def auto_fix(asset_type=''): asset.name = props.name -def start_upload(self, context, asset_type, as_new, metadata_only): +def start_upload(self, context, asset_type, reupload, upload_set): '''start upload process, by processing data''' props = utils.get_upload_props() storage_quota_ok = check_storage_quota(props) @@ -569,7 +569,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only): self.report({'ERROR_INVALID_INPUT'}, props.report) return {'CANCELLED'} - if as_new: + if not reupload: props.asset_base_id = '' props.id = '' export_data, upload_data, eval_path_computing, eval_path_state, eval_path, props = get_upload_data(self, context, @@ -595,11 +595,12 @@ def start_upload(self, context, asset_type, as_new, metadata_only): 'export_data': export_data, 'upload_data': upload_data, 'debug_value': bpy.app.debug_value, + 'upload_set': upload_set, } datafile = os.path.join(tempdir, BLENDERKIT_EXPORT_DATA_FILE) # check if thumbnail exists: - if not metadata_only: + if 'THUMBNAIL' in upload_set: if not os.path.exists(export_data["thumbnail_path"]): props.upload_state = 'Thumbnail not found' props.uploading = False @@ -616,7 +617,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only): if props.asset_base_id == '': try: r = requests.post(url, json=json_metadata, headers=headers, verify=True) # files = files, - props.upload_state = 'uploaded metadata' + ui.add_report('uploaded metadata') utils.p(r.text) except requests.exceptions.RequestException as e: print(e) @@ -627,10 +628,10 @@ def start_upload(self, context, asset_type, as_new, metadata_only): else: url += props.id + '/' try: - if not metadata_only: + if upload_set != ['METADATA']: json_metadata["verificationStatus"] = "uploading" r = requests.put(url, json=json_metadata, headers=headers, verify=True) # files = files, - props.upload_state = 'uploaded metadata' + ui.add_report('uploaded metadata') # parse the request # print('uploaded metadata') # print(r.text) @@ -641,7 +642,7 @@ def start_upload(self, context, asset_type, as_new, metadata_only): return {'CANCELLED'} # props.upload_state = 'step 1' - if metadata_only: + if upload_set == ['METADATA']: props.uploading = False return {'FINISHED'} @@ -658,7 +659,9 @@ def start_upload(self, context, asset_type, as_new, metadata_only): upload_data['assetBaseId'] = props.asset_base_id upload_data['id'] = props.id - bpy.ops.wm.save_mainfile() + # bpy.ops.wm.save_mainfile() + # bpy.ops.wm.save_as_mainfile(filepath=filepath, compress=False, copy=True) + props.uploading = True # save a copy of actual scene but don't interfere with the users models bpy.ops.wm.save_as_mainfile(filepath=source_filepath, compress=False, copy=True) @@ -697,7 +700,7 @@ asset_types = ( ) -class ModelUploadOperator(Operator): +class UploadOperator(Operator): """Tooltip""" bl_idname = "object.blenderkit_upload" bl_description = "Upload or re-upload asset + thumbnail + metadata" @@ -712,16 +715,27 @@ class ModelUploadOperator(Operator): default="MODEL", ) - as_new: BoolProperty( - name="upload as new", - description="deletes asset id and uploads as new file", + reupload: BoolProperty( + name="reupload", + description="reupload but also draw so that it asks what to reupload", + default=False, + options={'SKIP_SAVE'} + ) + + metadata: BoolProperty( + name="metadata", + default=True, + options={'SKIP_SAVE'} + ) + + thumbnail: BoolProperty( + name="thumbnail", default=False, options={'SKIP_SAVE'} ) - metadata_only: BoolProperty( - name="upload metadata", - description="update only metadata", + main_file: BoolProperty( + name="main file", default=False, options={'SKIP_SAVE'} ) @@ -736,13 +750,24 @@ class ModelUploadOperator(Operator): # in case of name change, we have to reupload everything, since the name is stored in blender file, # and is used for linking to scene - metadata_only = self.metadata_only if props.name_changed: + # TODO: this needs to be replaced with new double naming scheme (metadata vs blend data) # print('has to reupload whole data, name has changed.') - self.metadata_only = False + self.main_file = True props.name_changed = False - result = start_upload(self, context, self.asset_type, self.as_new, self.metadata_only) + upload_set = [] + if not self.reupload: + upload_set = ['METADATA', 'THUMBNAIL', 'MAINFILE'] + else: + if self.metadata: + upload_set.append('METADATA') + if self.thumbnail: + upload_set.append('THUMBNAIL') + if self.main_file: + upload_set.append('MAINFILE') + + result = start_upload(self, context, self.asset_type, self.reupload, upload_set) return result @@ -750,84 +775,32 @@ class ModelUploadOperator(Operator): props = utils.get_upload_props() layout = self.layout - if self.as_new: + if self.reupload: + # layout.prop(self, 'metadata') + layout.prop(self, 'main_file') + layout.prop(self, 'thumbnail') + + if props.asset_base_id != '' and not self.reupload: layout.label(text="Really upload as new? ") layout.label(text="Do this only when you create a new asset from an old one.") layout.label(text="For updates of thumbnail or model use reupload.") if props.is_private == 'PUBLIC': - ui_panels.label_multiline(layout, text='Since version 1.0.24: ' - 'PUBLIC ASSETS ARE VALIDATED AUTOMATICALLY ' - ' after upload. ' - 'Click Ok to proceed.') + ui_panels.label_multiline(layout, text='public assets are validated several hours' + ' or days after upload. ', width = 300) def invoke(self, context, event): props = utils.get_upload_props() - if self.as_new or props.is_private == 'PUBLIC': + if props.is_private == 'PUBLIC': return context.window_manager.invoke_props_dialog(self) else: return self.execute(context) -class ModelMarkForValidation(Operator): - """Tooltip""" - bl_idname = "object.blenderkit_mark_for_validation" - bl_description = "After this, model can be validated by our validators and \n then be part of the public database" - - bl_label = "Mark for validation" - - # type of upload - model, material, textures, e.t.c. - asset_type: EnumProperty( - name="type", - items=asset_types, - description="Type of upload", - default="MODEL", - ) - - @classmethod - def poll(cls, context): - props = utils.get_upload_props() - return bpy.context.active_object is not None and props.asset_base_id != '' - - def execute(self, context): - result = mark_for_validation(self, context, self.asset_type) - - return result - - -# TODO this is for upldating by creators, if they edit metadata on server or want to upload from older file version. -# class GetMetadataFromServer(Operator): -# """Tooltip""" -# bl_idname = "object.blenderkit_get_from_server" -# bl_description ="After this, model can be validated by our validators and \n then be part of the public database" -# -# bl_label = "Mark for validation" -# -# # type of upload - model, material, textures, e.t.c. -# asset_type : EnumProperty( -# name="type", -# items=asset_types, -# description="Type of upload", -# default="MODEL", -# ) -# -# @classmethod -# def poll(cls, context): -# props = utils.get_upload_props() -# return bpy.context.active_object is not None and props.asset_base_id != '' -# -# def execute(self, context): -# result = mark_for_validation(self, context, self.asset_type) -# -# return result - - def register_upload(): - bpy.utils.register_class(ModelUploadOperator) - bpy.utils.register_class(ModelMarkForValidation) + bpy.utils.register_class(UploadOperator) def unregister_upload(): - bpy.utils.unregister_class(ModelUploadOperator) - bpy.utils.unregister_class(ModelMarkForValidation) + bpy.utils.unregister_class(UploadOperator) |