From b97ee67a4b8ddddf9af8a93c3e8292e34d507467 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 5 Nov 2014 09:54:43 -0800 Subject: Working GCC package. --- lib/spack/llnl/util/filesystem.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index dc722297ec..6a04d98a18 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -22,8 +22,9 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -__all__ = ['install', 'expand_user', 'working_dir', 'touch', 'mkdirp', - 'join_path', 'ancestor', 'can_access', 'filter_file', 'change_sed_delimiter'] +__all__ = ['set_install_permissions', 'install', 'expand_user', 'working_dir', + 'touch', 'mkdirp', 'force_remove', 'join_path', 'ancestor', + 'can_access', 'filter_file', 'change_sed_delimiter'] import os import sys @@ -127,10 +128,19 @@ def change_sed_delimiter(old_delim, new_delim, *filenames): filter_file(double_quoted, '"%s"' % repl, f) +def set_install_permissions(path): + """Set appropriate permissions on the installed file.""" + if os.path.isdir(path): + os.chmod(path, 0755) + else: + os.chmod(path, 0644) + + def install(src, dest): """Manually install a file to a particular location.""" tty.info("Installing %s to %s" % (src, dest)) shutil.copy(src, dest) + set_install_permissions(dest) def expand_user(path): @@ -152,6 +162,15 @@ def mkdirp(*paths): raise OSError(errno.EEXIST, "File alredy exists", path) +def force_remove(*paths): + """Remove files without printing errors. Like rm -f, does NOT + remove directories.""" + for path in paths: + try: + os.remove(path) + except OSError, e: + pass + @contextmanager def working_dir(dirname, **kwargs): if kwargs.get('create', False): -- cgit v1.2.3-70-g09d2