From 96cec22fca30e7c7f87dc5e32094d92f0c5df422 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Tue, 24 Jul 2012 17:11:36 -0400 Subject: [PATCH] * wpylib.file.file_utils: added file_exists_nonempty() function. --- file/file_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/file/file_utils.py b/file/file_utils.py index b80ddb4..76bceee 100644 --- a/file/file_utils.py +++ b/file/file_utils.py @@ -24,6 +24,7 @@ import bz2 import glob import gzip import os +import os.path try: import subprocess has_subprocess = True @@ -80,6 +81,11 @@ def open_input_file(fname, superize=0): # Miscellaneous functions +def file_exists_nonempty(fn): + return os.path.isfile(fn) and os.stat(fn).st_size > 0 + + + def glob_files(filespec): '''Processes a glob string, or does nothing (pass-on only) if an iterable object (e.g. list or tuple) is already given. @@ -101,8 +107,9 @@ def path_search(*specs, **opts): * pathsep="/" -- path separator * filetest=os.path.isfile -- filetest operator to be used * raise_error=False -- do we want to raise an exception if the file - is not found? + is not found after all possible searches? ''' + path_join = os.path.join # FIXME: this can be extremely expensive! xspecs = [] xlen = []