[Bf-blender-cvs] [657259f] fluid-mantaflow: Mantaflow: Use Path objects instead of os.path.join()

Sebastián Barschkis noreply at git.blender.org
Wed Oct 26 21:39:55 CEST 2016


Commit: 657259fbaac07a9f2ec3ae94a786b16bf30ba7a6
Author: Sebastián Barschkis
Date:   Wed Oct 26 20:37:57 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB657259fbaac07a9f2ec3ae94a786b16bf30ba7a6

Mantaflow: Use Path objects instead of os.path.join()

File paths are passed into these functions, so convert passed path to pathlib.Path object to avoid internal/external conflicts. This should be easier to maintain and visually cleaner.

Reviewers: sebbas

Reviewed By: sebbas

Differential Revision: https://developer.blender.org/D2317

===================================================================

M	intern/mantaflow/intern/strings/liquid_script.h
M	intern/mantaflow/intern/strings/shared_script.h
M	intern/mantaflow/intern/strings/smoke_script.h
M	release/scripts/addons
M	release/scripts/addons_contrib

===================================================================

diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index d5f6964..fc6fcc2 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -260,65 +260,69 @@ def save_mesh_high(path):\n\
 
 const std::string liquid_import_low = "\n\
 def load_liquid_data_low(path):\n\
-    flags.load(os.path.join(path, 'flags.uni'))\n\
+    path = Path(path)\n\
+    flags.load(path / 'flags.uni')\n\
     \n\
-    phiParts.load(os.path.join(path, 'phiParts.uni'))\n\
-    phi.load(os.path.join(path, 'phi.uni'))\n\
-    phiInit.load(os.path.join(path, 'phiInit.uni'))\n\
-    phiObs.load(os.path.join(path, 'phiObs.uni'))\n\
-    phiObsInit.load(os.path.join(path, 'phiObsInit.uni'))\n\
-    fractions.load(os.path.join(path, 'fractions.uni'))\n\
-    pressure.load(os.path.join(path, 'pressure.uni'))\n\
+    phiParts.load(path / 'phiParts.uni')\n\
+    phi.load(path / 'phi.uni')\n\
+    phiInit.load(path / 'phiInit.uni')\n\
+    phiObs.load(path / 'phiObs.uni')\n\
+    phiObsInit.load(path / 'phiObsInit.uni')\n\
+    fractions.load(path / 'fractions.uni')\n\
+    pressure.load(path / 'pressure.uni')\n\
     \n\
-    vel.load(os.path.join(path, 'vel.uni'))\n\
-    velOld.load(os.path.join(path, 'velOld.uni'))\n\
-    velParts.load(os.path.join(path, 'velParts.uni'))\n\
-    mapWeights.load(os.path.join(path, 'mapWeights.uni'))\n\
+    vel.load(path / 'vel.uni')\n\
+    velOld.load(path / 'velOld.uni')\n\
+    velParts.load(path / 'velParts.uni')\n\
+    mapWeights.load(path / 'mapWeights.uni')\n\
     \n\
-    pp.load(os.path.join(path, 'pp.uni'))\n\
-    pVel.load(os.path.join(path, 'pVel.uni'))\n\
+    pp.load(path / 'pp.uni')\n\
+    pVel.load(path / 'pVel.uni')\n\
     \n\
-    gpi.load(os.path.join(path, 'gpi.uni'))\n";
+    gpi.load(path / 'gpi.uni')\n";
 
 const std::string liquid_import_high = "\n\
 def load_liquid_data_high(path):\n\
-    xl_flags.load(os.path.join(path, 'xl_flags.uni'))\n\
+    path = Path(path)\n\
+    xl_flags.load(path / 'xl_flags.uni')\n\
     \n\
-    xl_phiParts.load(os.path.join(path, 'xl_phiParts.uni'))\n\
-    xl_phi.load(os.path.join(path, 'xl_phi.uni'))\n\
+    xl_phiParts.load(path / 'xl_phiParts.uni')\n\
+    xl_phi.load(path / 'xl_phi.uni')\n\
     \n\
-    xl_pp.load(os.path.join(path, 'xl_pp.uni'))\n";
+    xl_pp.load(path / 'xl_pp.uni')\n";
 
 const std::string liquid_export_low = "\n\
 def save_liquid_data_low(path):\n\
-    flags.save(os.path.join(path, 'flags.uni'))\n\
+    path = Path(path)\n\
+    flags.save(path / 'flags.uni')\n\
     \n\
-    phiParts.save(os.path.join(path, 'phiParts.uni'))\n\
-    phi.save(os.path.join(path, 'phi.uni'))\n\
-    phiInit.save(os.path.join(path, 'phiInit.uni'))\n\
-    phiObs.save(os.path.join(path, 'phiObs.uni'))\n\
-    phiObsInit.save(os.path.join(path, 'phiObsInit.uni'))\n\
-    fractions.save(os.path.join(path, 'fractions.uni'))\n\
-    pressure.save(os.path.join(path, 'pressure.uni'))\n\
+    phiParts.save(path / 'phiParts.uni')\n\
+    phi.save(path / 'phi.uni')\n\
+    phiInit.save(path / 'phiInit.uni')\n\
+    phiObs.save(path / 'phiObs.uni')\n\
+    phiObsInit.save(path / 'phiObsInit.uni')\n\
+    fractions.save(path / 'fractions.uni')\n\
+    pressure.save(path / 'pressure.uni')\n\
     \n\
-    vel.save(os.path.join(path, 'vel.uni'))\n\
-    velOld.save(os.path.join(path, 'velOld.uni'))\n\
-    velParts.save(os.path.join(path, 'velParts.uni'))\n\
-    mapWeights.save(os.path.join(path, 'mapWeights.uni'))\n\
+    vel.save(path / 'vel.uni')\n\
+    velOld.save(path / 'velOld.uni')\n\
+    velParts.save(path / 'velParts.uni')\n\
+    mapWeights.save(path / 'mapWeights.uni')\n\
     \n\
-    pp.save(os.path.join(path, 'pp.uni'))\n\
-    pVel.save(os.path.join(path, 'pVel.uni'))\n\
+    pp.save(path / 'pp.uni')\n\
+    pVel.save(path / 'pVel.uni')\n\
     \n\
-    gpi.save(os.path.join(path, 'gpi.uni'))\n";
+    gpi.save(path / 'gpi.uni')\n";
 
 const std::string liquid_export_high = "\n\
 def save_liquid_data_high(path):\n\
-    xl_flags.save(os.path.join(path, 'xl_flags.uni'))\n\
+    path = Path(path)\n\
+    xl_flags.save(path / 'xl_flags.uni')\n\
     \n\
-    xl_phiParts.save(os.path.join(path, 'xl_phiParts.uni'))\n\
-    xl_phi.save(os.path.join(path, 'xl_phi.uni'))\n\
+    xl_phiParts.save(path / 'xl_phiParts.uni')\n\
+    xl_phi.save(path / 'xl_phi.uni')\n\
     \n\
-    xl_pp.save(os.path.join(path, 'xl_pp.uni'))\n";
+    xl_pp.save(path / 'xl_pp.uni')\n";
 
 //////////////////////////////////////////////////////////////////////
 // DESTRUCTION
@@ -386,5 +390,3 @@ path_prefix = '$MANTA_EXPORT_PATH$'\n\
 load_liquid_data_low(path_prefix)\n\
 if using_highres:\n\
     load_liquid_data_high(path_prefix)\n";
-
-
diff --git a/intern/mantaflow/intern/strings/shared_script.h b/intern/mantaflow/intern/strings/shared_script.h
index 4c20665..208b4ba 100644
--- a/intern/mantaflow/intern/strings/shared_script.h
+++ b/intern/mantaflow/intern/strings/shared_script.h
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -35,6 +35,7 @@
 
 const std::string manta_import = "\
 from manta import *\n\
+from pathlib import Path\n\
 import os, shutil, math, sys, gc, tempfile\n";
 
 //////////////////////////////////////////////////////////////////////
@@ -140,4 +141,3 @@ end_frame = 1000\n\
 while start_frame <= end_frame:\n\
     manta_step(start_frame)\n\
     start_frame += 1\n";
-
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index e9223bb..661d638 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -4,7 +4,7 @@
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. 
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -344,67 +344,71 @@ def update_flame_high():\n\
 
 const std::string smoke_import_low = "\n\
 def load_smoke_data_low(path):\n\
-    density.load(os.path.join(path, 'density.uni'))\n\
-    flags.load(os.path.join(path, 'flags.uni'))\n\
-    vel.load(os.path.join(path, 'vel.uni'))\n\
-    forces.load(os.path.join(path, 'forces.uni'))\n\
-    inflow_grid.load(os.path.join(path, 'inflow_low.uni'))\n\
-    fuel_inflow.load(os.path.join(path, 'fuel_inflow.uni'))\n\
+    path = Path(path)\n\
+    density.load(path / 'density.uni')\n\
+    flags.load(path / 'flags.uni')\n\
+    vel.load(path / 'vel.uni')\n\
+    forces.load(path / 'forces.uni')\n\
+    inflow_grid.load(path / 'inflow_low.uni')\n\
+    fuel_inflow.load(path / 'fuel_inflow.uni')\n\
     if using_colors:\n\
-        color_r.load(os.path.join(path, 'color_r.uni'))\n\
-        color_g.load(os.path.join(path, 'color_g.uni'))\n\
-        color_b.load(os.path.join(path, 'color_b.uni'))\n\
+        color_r.load(path / 'color_r.uni')\n\
+        color_g.load(path / 'color_g.uni')\n\
+        color_b.load(path / 'color_b.uni')\n\
     if using_heat:\n\
-        heat.load(os.path.join(path, 'heat.uni'))\n\
+        heat.load(path / 'heat.uni')\n\
     if using_fire:\n\
-        flame.load(os.path.join(path, 'flame.uni'))\n\
-        fuel.load(os.path.join(path, 'fuel.uni'))\n\
-        react.load(os.path.join(path, 'react.uni'))\n";
+        flame.load(path / 'flame.uni')\n\
+        fuel.load(path / 'fuel.uni')\n\
+        react.load(path / 'react.uni')\n";
 
 const std::string smoke_import_high = "\n\
 def load_smoke_data_high(path):\n\
-    xl_density.load(os.path.join(path, 'xl_density.uni'))\n\
-    xl_flags.load(os.path.join(path, 'xl_flags.uni'))\n\
+    path = Path(path)\n\
+    xl_density.load(path / 'xl_density.uni')\n\
+    xl_flags.load(path / 'xl_flags.uni')\n\
     if using_colors:\n\
-        xl_color_r.load(os.path.join(path, 'xl_color_r.uni'))\n\
-        xl_color_g.load(os.path.join(path, 'xl_color_g.uni'))\n\
-        xl_color_b.load(os.path.join(path, 'xl_color_b.uni'))\n\
+        xl_color_r.load(path / 'xl_color_r.uni')\n\
+        xl_color_g.load(path / 'xl_color_g.uni')\n\
+        xl_color_b.load(path / 'xl_color_b.uni')\n\
     if using_fire:\n\
-        xl_flame.load(os.path.join(path, 'xl_flame.uni'))\n\
-        xl_fuel.load(os.path.join(path, 'xl_fuel.uni'))\n\
-        xl_react.load(os.path.join(path, 'xl_react.uni'))\n";
+        xl_flame.load(path / 'xl_flame.uni')\n\
+        xl_fuel.load(path / 'xl_fuel.uni')\n\
+        xl_react.load(path / 'xl_react.uni')\n";
 
 const std::string smoke_export_low = "\n\
 def save_smoke_data_low(path):\n\
-    density.save(os.path.join(path, 'density.uni'))\n\
-    flags.save(os.path.join(path, 'flags.uni'))\n\
-    vel.save(os.path.join(path, 'vel.uni'))\n\
-    forces.save(os.path.join(path, 'forces.uni'))\n\
-    inflow_grid.save(os.path.join(path, 'inflow_low.uni'))\n\
-    fuel_inflow.save(os.path.join(path, 'fuel_inflow.uni'))\n\
+    path = Path(path)\n\
+    density.save(path / 'density.uni'))\n\
+    flags.save(path / 'flags.uni')\n\
+    vel.save(path / 'vel.uni')\n\
+    forces.save(path / 'forc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list