[yt-svn] commit/yt: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon May 20 09:34:21 PDT 2013


2 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/0945c5060fb5/
Changeset:   0945c5060fb5
Branch:      yt
User:        xarthisius
Date:        2013-05-19 17:02:44
Summary:     Introduce ensure_dir_exists function for safe creation of path directory tree. Fixes #571
Affected #:  5 files

diff -r a928d1c5ff2929339a3af07e0b8eb735c3c46bcd -r 0945c5060fb5680bee4f631d263a0fe83dd52037 yt/analysis_modules/halo_finding/halo_objects.py
--- a/yt/analysis_modules/halo_finding/halo_objects.py
+++ b/yt/analysis_modules/halo_finding/halo_objects.py
@@ -2009,14 +2009,11 @@
         --------
         >>> halos.write_out("HopAnalysis.out")
         """
-        # if path denoted in filename, assure path exists
-        my_dir = os.path.dirname(filename)
-        if not os.path.exists(my_dir):
-            only_on_root(os.makedirs, my_dir)
-
+        ensure_dir_exists(filename)
         f = self.comm.write_on_root(filename)
         HaloList.write_out(self, f, ellipsoid_data)
 
+
     def write_particle_lists_txt(self, prefix):
         r"""Write out the names of the HDF5 files containing halo particle data
         to a text file.
@@ -2033,14 +2030,11 @@
         --------
         >>> halos.write_particle_lists_txt("halo-parts")
         """
-        # if path denoted in prefix, assure path exists
-        my_dir = os.path.dirname(prefix)
-        if not os.path.exists(my_dir):
-            only_on_root(os.makedirs, my_dir)
-
+        ensure_dir_exists(prefix)
         f = self.comm.write_on_root("%s.txt" % prefix)
         HaloList.write_particle_lists_txt(self, prefix, fp=f)
 
+
     @parallel_blocking_call
     def write_particle_lists(self, prefix):
         r"""Write out the particle data for halos to HDF5 files.
@@ -2061,11 +2055,7 @@
         --------
         >>> halos.write_particle_lists("halo-parts")
         """
-        # if path denoted in prefix, assure path exists
-        my_dir = os.path.dirname(prefix)
-        if not os.path.exists(my_dir):
-            only_on_root(os.makedirs, my_dir)
-
+        ensure_dir_exists(prefix)
         fn = "%s.h5" % self.comm.get_filename(prefix)
         f = h5py.File(fn, "w")
         for halo in self._groups:
@@ -2094,16 +2084,12 @@
         ellipsoid_data : bool.
             Whether to save the ellipsoidal information to the files.
             Default = False.
-        
+
         Examples
         --------
         >>> halos.dump("MyHalos")
         """
-        # if path denoted in basename, assure path exists
-        my_dir = os.path.dirname(basename)
-        if not os.path.exists(my_dir):
-            only_on_root(os.makedirs, my_dir)
-
+        ensure_dir_exists(basename)
         self.write_out("%s.out" % basename, ellipsoid_data)
         self.write_particle_lists(basename)
         self.write_particle_lists_txt(basename)

diff -r a928d1c5ff2929339a3af07e0b8eb735c3c46bcd -r 0945c5060fb5680bee4f631d263a0fe83dd52037 yt/analysis_modules/halo_finding/rockstar/rockstar.py
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar.py
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar.py
@@ -338,6 +338,8 @@
                     hires_only = (self.hires_dm_mass is not None),
                     **kwargs)
         # Make the directory to store the halo lists in.
+        if not self.outbase:
+            self.outbase = os.getcwd()
         if self.comm.rank == 0:
             if not os.path.exists(self.outbase):
                 os.makedirs(self.outbase)

diff -r a928d1c5ff2929339a3af07e0b8eb735c3c46bcd -r 0945c5060fb5680bee4f631d263a0fe83dd52037 yt/analysis_modules/halo_profiler/standard_analysis.py
--- a/yt/analysis_modules/halo_profiler/standard_analysis.py
+++ b/yt/analysis_modules/halo_profiler/standard_analysis.py
@@ -68,8 +68,10 @@
         self.prof = prof
 
     def plot_everything(self, dirname = None):
-        if dirname is None: dirname = "%s_profile_plots/" % (self.pf)
-        if not os.path.isdir(dirname): os.makedirs(dirname)
+        if not dirname:
+            dirname = "%s_profile_plots/" % (self.pf)
+        if not os.path.isdir(dirname):
+            os.makedirs(dirname)
         import matplotlib; matplotlib.use("Agg")
         import pylab
         for field in self.prof.keys():

diff -r a928d1c5ff2929339a3af07e0b8eb735c3c46bcd -r 0945c5060fb5680bee4f631d263a0fe83dd52037 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -602,3 +602,12 @@
 def get_image_suffix(name):
     suffix = os.path.splitext(name)[1]
     return suffix if suffix in ['.png', '.eps', '.ps', '.pdf'] else ''
+
+
+def ensure_dir_exists(path):
+    r"""Create all directories in path recursively in a parallel safe manner"""
+    my_dir = os.path.dirname(path)
+    if not my_dir:
+        my_dir = os.getcwd()
+    if not os.path.exists(my_dir):
+        only_on_root(os.makedirs, my_dir)

diff -r a928d1c5ff2929339a3af07e0b8eb735c3c46bcd -r 0945c5060fb5680bee4f631d263a0fe83dd52037 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1327,7 +1327,7 @@
             plt.set_log(args.field, args.takelog)
             if args.zlim:
                 plt.set_zlim(args.field,*args.zlim)
-            if not os.path.isdir(args.output): os.makedirs(args.output)
+            ensure_dir_exists(args.output)
             plt.save(os.path.join(args.output,"%s" % (pf)))
 
 class YTRenderCmd(YTCommand):


https://bitbucket.org/yt_analysis/yt/commits/ff04cead07c8/
Changeset:   ff04cead07c8
Branch:      yt
User:        xarthisius
Date:        2013-05-19 17:15:20
Summary:     [ensure_dir_exists] just return in case the dirname is an empty string instead of needlessly touching fs twice
Affected #:  1 file

diff -r 0945c5060fb5680bee4f631d263a0fe83dd52037 -r ff04cead07c8458eb61da8f49fb7e9fb7b652d10 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -608,6 +608,6 @@
     r"""Create all directories in path recursively in a parallel safe manner"""
     my_dir = os.path.dirname(path)
     if not my_dir:
-        my_dir = os.getcwd()
+        return
     if not os.path.exists(my_dir):
         only_on_root(os.makedirs, my_dir)

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list