Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-06-18 08:25:22 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-06-18 08:49:10 +0300
commit3ada1949f8633293b4a424bf20789d94cf924c43 (patch)
treec996f2c6a612922e3eeee5822864bb2fbb716dc1 /source/blender/windowmanager/intern
parentaab165b575ce312675e543f519c962cbf9939d34 (diff)
Python API: path mapping options for library writing function
When "Relative Remap" option was added, the intention was only to remap paths that were already relative. However it remapped all paths. This was reported as T62612 and fixed recently, however some Python script authors depended on the old behavior. For users, it's reasonable to use the existing operators to make paths absolute/relative. For scripts however it's useful to be able to write out individual data-blocks with the ability to make all paths relative. Now `bpy.data.libraries.write()` takes a path_remap argument which can be `NONE/RELATIVE/RELATIVE_ALL/ABSOLUTE` allowing the script author to choose how paths are handled when writing out data-blocks. Addresses T77768.
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r--source/blender/windowmanager/intern/wm_files.c24
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c2
2 files changed, 18 insertions, 8 deletions
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 1ecfbfb4b8d..b2753886f69 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -1409,7 +1409,7 @@ bool write_crash_blend(void)
BLI_strncpy(path, BKE_main_blendfile_path_from_global(), sizeof(path));
BLI_path_extension_replace(path, sizeof(path), "_crash.blend");
- if (BLO_write_file(G_MAIN, path, fileflags, NULL, NULL)) {
+ if (BLO_write_file(G_MAIN, path, fileflags, NULL)) {
printf("written: %s\n", path);
return 1;
}
@@ -1422,7 +1422,11 @@ bool write_crash_blend(void)
/**
* \see #wm_homefile_write_exec wraps #BLO_write_file in a similar way.
*/
-static bool wm_file_write(bContext *C, const char *filepath, int fileflags, ReportList *reports)
+static bool wm_file_write(bContext *C,
+ const char *filepath,
+ int fileflags,
+ eBLO_WritePathRemap remap_mode,
+ ReportList *reports)
{
Main *bmain = CTX_data_main(C);
Library *li;
@@ -1499,7 +1503,7 @@ static bool wm_file_write(bContext *C, const char *filepath, int fileflags, Repo
/* XXX temp solution to solve bug, real fix coming (ton) */
bmain->recovered = 0;
- if (BLO_write_file(CTX_data_main(C), filepath, fileflags, reports, thumb)) {
+ if (BLO_write_file_ex(CTX_data_main(C), filepath, fileflags, reports, remap_mode, thumb)) {
const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0);
if (!(fileflags & G_FILE_SAVE_COPY)) {
@@ -1632,7 +1636,7 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer *UNUSED(wt))
ED_editors_flush_edits(bmain);
/* Error reporting into console */
- BLO_write_file(bmain, filepath, fileflags, NULL, NULL);
+ BLO_write_file(bmain, filepath, fileflags, NULL);
}
/* do timer after file write, just in case file write takes a long time */
wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, U.savetime * 60.0);
@@ -1752,7 +1756,8 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
/* Force save as regular blend file. */
fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
- if (BLO_write_file(bmain, filepath, fileflags, op->reports, NULL) == 0) {
+ if (BLO_write_file_ex(
+ bmain, filepath, fileflags, op->reports, BLO_WRITE_PATH_REMAP_RELATIVE, NULL) == 0) {
printf("fail\n");
return OPERATOR_CANCELLED;
}
@@ -2668,6 +2673,12 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
char path[FILE_MAX];
const bool is_save_as = (op->type->invoke == wm_save_as_mainfile_invoke);
+ /* We could expose all options to the users however in most cases remapping
+ * existing relative paths is a good default.
+ * Users can manually make their paths relative & absolute if they wish. */
+ const eBLO_WritePathRemap remap_mode = RNA_boolean_get(op->ptr, "relative_remap") ?
+ BLO_WRITE_PATH_REMAP_RELATIVE :
+ BLO_WRITE_PATH_REMAP_NONE;
save_set_compress(op);
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -2683,13 +2694,12 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
/* set compression flag */
SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "compress"), G_FILE_COMPRESS);
- SET_FLAG_FROM_TEST(fileflags, RNA_boolean_get(op->ptr, "relative_remap"), G_FILE_RELATIVE_REMAP);
SET_FLAG_FROM_TEST(
fileflags,
(RNA_struct_property_is_set(op->ptr, "copy") && RNA_boolean_get(op->ptr, "copy")),
G_FILE_SAVE_COPY);
- const bool ok = wm_file_write(C, path, fileflags, op->reports);
+ const bool ok = wm_file_write(C, path, fileflags, remap_mode, op->reports);
if ((op->flag & OP_IS_INVOKE) == 0) {
/* OP_IS_INVOKE is set when the operator is called from the GUI.
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 001acc459c2..27aa9c532e5 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -500,7 +500,7 @@ void WM_exit_ex(bContext *C, const bool do_python)
has_edited = ED_editors_flush_edits(bmain);
- if ((has_edited && BLO_write_file(bmain, filename, fileflags, NULL, NULL)) ||
+ if ((has_edited && BLO_write_file(bmain, filename, fileflags, NULL)) ||
(undo_memfile && BLO_memfile_write_file(undo_memfile, filename))) {
printf("Saved session recovery to '%s'\n", filename);
}