Ticket #10801: trac_10801-local_bin_repo.patch

File trac_10801-local_bin_repo.patch, 4.4 KB (added by was, 11 years ago)

replacing the patch by one that doesn't delete .a files.

  • new file sage-micro_release

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1314250563 25200
    # Node ID 088b0cbcc83f0210d3e00da5bb4691761aed6b55
    # Parent  6677b3d3939b28e2824b7fded3809aaa3aff27cb
    trac 10801: create a script sage-micro_release that deletes things not strictly needed for a minimal never upgraded or developed release
    
    diff --git a/sage-micro_release b/sage-micro_release
    new file mode 100755
    - +  
     1#!/usr/bin/env python
     2
     3########################################################################
     4#       Copyright (C) 2011 William Stein <wstein@gmail.com>
     5#
     6#  Distributed under the terms of the GNU General Public License (GPL)
     7#
     8#                  http://www.gnu.org/licenses/
     9########################################################################
     10
     11"""
     12AUTHORS:
     13    - William Stein -- coding
     14    - Keshav Kini -- very significant design input
     15"""
     16
     17DEBUG = False  # If True, prints everything that will happen, but does not actually do anything.
     18
     19import os, shutil, sys
     20
     21SAGE_ROOT = os.environ['SAGE_ROOT']
     22
     23def c(cmd, indent=0):
     24    print ' '*indent + cmd
     25    if DEBUG:
     26        return
     27    e = os.system(cmd)
     28    if e:
     29        print "Error executing command.  Failed with exit status %s."%e
     30        sys.exit(1)
     31
     32def strip_binaries():
     33    """
     34    Strip various binaries using the strip command to save some space.
     35    """
     36    print "Striping various binaries:"
     37    c('strip "%s"/local/bin/Singular-*'%SAGE_ROOT, 4)
     38    c('strip "%s"/local/bin/gfan'%SAGE_ROOT, 4)
     39
     40def strip_files_with_condition(path, condition, recursive=True):
     41    """
     42    Remove all files in the given path (and subdirectories if
     43    recursive is True) that satisfy the given condition.
     44    """
     45    for F in os.listdir(path):
     46        filename = os.path.join(path, F)
     47        if condition(F):
     48            c('strip "%s"'%filename)
     49        if recursive and os.path.isdir(filename):
     50            strip_files_with_condition(filename, condition, recursive=True)
     51
     52def strip_local_lib_so():
     53    print "Stripping .so files in local/lib"
     54    strip_files_with_condition('%s/local/lib/'%SAGE_ROOT, lambda F: F.endswith('.so'))
     55
     56def remove_paths_with_condition(path, ext, condition, recursive=True):
     57    """
     58    Remove all files in the given path (and subdirectories if
     59    recursive is True) that satisfy the given condition.
     60    """
     61    for F in os.listdir(path):
     62        filename = os.path.join(path, F)
     63        if condition(F):
     64            print "    removing %s"%filename
     65            if not DEBUG:
     66                if os.path.isdir(filename):
     67                    shutil.rmtree(filename)
     68                else:
     69                    os.unlink(filename)
     70        if recursive and os.path.isdir(filename):  # isdir checks that it still exists too
     71            remove_paths_with_condition(filename, ext, condition, recursive=True)
     72
     73def remove_paths_with_extension(path, ext, recursive=True):
     74    """
     75    Remove all files in the given path (and subdirectories if
     76    recursive is True) with the given extension.
     77    """
     78    if not ext.startswith('.'):
     79        ext = '.' + ext
     80    print "Removing %s files from %s%s:"%(ext, path, ' and all subdirectories' if recursive else '')
     81    remove_paths_with_condition(path, ext, lambda F: os.path.splitext(F)[1] == ext, recursive)
     82
     83def remove_paths_with_prefix(path, prefix, recursive=True):
     84    print "Removing files starting with %s from %s%s:"%(prefix, path, ' and all subdirectories' if recursive else '')
     85    remove_paths_with_condition(path, prefix, lambda F: F.startswith(prefix), recursive)
     86   
     87def remove_dot_a_files():
     88    """
     89    Remove .a files from various places, since these are only needed
     90    for building, not for running Sage.
     91    """
     92    remove_paths_with_extension('%s/local/lib/'%SAGE_ROOT, 'a')
     93
     94def remove_sage_build_dir():
     95    build_dir = '%s/devel/sage/build/'%SAGE_ROOT
     96    remove_paths_with_prefix(build_dir, 'lib.', recursive=False)
     97    remove_paths_with_prefix(build_dir, 'temp.', recursive=False)
     98
     99def main():
     100    """
     101    Do all cleanups.
     102    """
     103    strip_local_lib_so()
     104    strip_binaries()
     105
     106    # Removing .a files is potentially too intrusive, so we're turning
     107    # this off for now.  The problem is that it might break %cython
     108    # in the notebook, say.
     109    # remove_dot_a_files()
     110   
     111    remove_sage_build_dir()
     112   
     113
     114if __name__ == '__main__':
     115   main()