From 7e67120169aedd7a359c57d109a07418ad4b1699 2006-01-16 21:42:33 From: vivainio Date: 2006-01-16 21:42:33 Subject: [PATCH] Get "path" objects via SList LSString mechanism, through obj.p and obj.paths --- diff --git a/IPython/genutils.py b/IPython/genutils.py index 065a96f..25328ea 100644 --- a/IPython/genutils.py +++ b/IPython/genutils.py @@ -5,7 +5,7 @@ General purpose utilities. This is a grab-bag of stuff I find useful in most programs I write. Some of these things are also convenient when working at the command line. -$Id: genutils.py 1013 2006-01-13 08:33:32Z fperez $""" +$Id: genutils.py 1028 2006-01-16 21:42:33Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -36,7 +36,7 @@ import types # Other IPython utilities from IPython.Itpl import Itpl,itpl,printpl from IPython import DPyGetOpt - +from IPython.path import path if os.name == "nt": from IPython.winconsole import get_console_size @@ -900,6 +900,16 @@ class LSString(str): n = nlstr = property(get_nlstr) + def get_paths(self): + try: + return self.__paths + except AttributeError: + self.__paths = [path(p) for p in self.split('\n') if os.path.exists(p)] + return self.__paths + + p = paths = property(get_paths) + + #---------------------------------------------------------------------------- class SList(list): """List derivative with a special access attributes. @@ -935,6 +945,15 @@ class SList(list): return self.__nlstr n = nlstr = property(get_nlstr) + + def get_paths(self): + try: + return self.__paths + except AttributeError: + self.__paths = [path(p) for p in self if os.path.exists(p)] + return self.__paths + + p = paths = property(get_paths) #---------------------------------------------------------------------------- def esc_quotes(strng): diff --git a/doc/ChangeLog b/doc/ChangeLog index 9dfb5e6..cce4bb7 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -4,7 +4,11 @@ that returns file contents on exit. * IPython/path.py: Added Jason Orendorff's "path" module to - IPython tree, http://www.jorendorff.com/articles/python/path/ + IPython tree, http://www.jorendorff.com/articles/python/path/. + You can get path objects conveniently through %sc, and !!, e.g.: + sc files=ls + for p in files.paths: # or files.p + print p,p.mtime * Ipython/iplib.py:"," and ";" autoquoting-upon-autocall now work again without considering the exclusion regexp -