--- src/pylorax/ltmpl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 040f1aa..d716586 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -95,7 +95,11 @@ def rglob(pathname, root="/", fatal=False): raise IOError, "nothing matching %s in %s" % (pathname, root)
def rexists(pathname, root=""): - return True if rglob(pathname, root) else False + # Generator is always True, even with no values; + # bool(rglob(...)) won't work here. + for _path in rglob(pathname, root): + return True + return False
# TODO: operate inside an actual chroot for safety? Not that RPM bothers.. class LoraxTemplateRunner(object):
On Wed, 2012-12-19 at 12:40 +0100, Martin Gracik wrote:
src/pylorax/ltmpl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 040f1aa..d716586 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -95,7 +95,11 @@ def rglob(pathname, root="/", fatal=False): raise IOError, "nothing matching %s in %s" % (pathname, root)
def rexists(pathname, root=""):
- return True if rglob(pathname, root) else False
- # Generator is always True, even with no values;
- # bool(rglob(...)) won't work here.
- for _path in rglob(pathname, root):
return True
- return False
I think
try: rglob(pathname, root).next() return True except StopIteration: return False
would be better readable, but that's just a matter of opinion. ACK to whichever from that two you prefer. :)
--
Martin Gracik
----- Original Message -----
On Wed, 2012-12-19 at 12:40 +0100, Martin Gracik wrote:
src/pylorax/ltmpl.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index 040f1aa..d716586 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -95,7 +95,11 @@ def rglob(pathname, root="/", fatal=False): raise IOError, "nothing matching %s in %s" % (pathname, root)
def rexists(pathname, root=""):
- return True if rglob(pathname, root) else False
- # Generator is always True, even with no values;
- # bool(rglob(...)) won't work here.
- for _path in rglob(pathname, root):
return True
- return False
I think
try: rglob(pathname, root).next() return True except StopIteration: return False
would be better readable, but that's just a matter of opinion. ACK to whichever from that two you prefer. :)
I really don't agree. :) What if sometime later rglob is changed to return a list instead of an iterator? Then your solution stops working and rexists needs to be changed too.
-- Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
anaconda-patches mailing list anaconda-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
anaconda-patches@lists.fedorahosted.org