Ticket #13963: 13963_gap_stamp.patch

File 13963_gap_stamp.patch, 5.7 KB (added by jdemeyer, 9 years ago)
  • sage/interfaces/gap.py

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1358429419 -3600
    # Node ID d2a15003052a8cf3af39ab1cf20dfe61d7e762b8
    # Parent  b80a2598a907b72873393b680d6eafeae9773c64
    Only mess with workspaces when we actually start gap
    and touch workspaces when we use them
    
    diff --git a/sage/interfaces/gap.py b/sage/interfaces/gap.py
    a b  
    177177
    178178import expect
    179179from expect import Expect, ExpectElement, FunctionElement, ExpectFunction
    180 from sage.misc.misc import SAGE_ROOT, SAGE_EXTCODE, DOT_SAGE, is_64_bit, is_in_string
     180from sage.misc.misc import SAGE_LOCAL, SAGE_EXTCODE, DOT_SAGE, is_64_bit, is_in_string
    181181from IPython.genutils import page
    182182import re
    183183import os
     
    187187
    188188GAP_DIR = os.path.join(DOT_SAGE, 'gap')
    189189
    190 WORKSPACE = os.path.join(GAP_DIR, 'workspace-%s'%abs(hash(SAGE_ROOT)))
     190WORKSPACE = os.path.join(GAP_DIR, 'workspace-%s'%abs(hash(SAGE_LOCAL)))
    191191
    192 GAP_STAMP = SAGE_EXTCODE
     192GAP_BINARY = os.path.join(SAGE_LOCAL, 'bin', 'gap')
    193193
    194194first_try = True
    195195
    196 try:
    197     os.makedirs(GAP_DIR)
    198     open(os.path.join(GAP_DIR, 'README.txt'), 'w').write("It is OK to delete all these cache files.  They will be recreated as needed.")
    199 except OSError:
    200     if not os.path.isdir(GAP_DIR):
    201         raise
    202 
    203196gap_cmd = "gap -r"
    204197if platform.processor() == 'ia64' and os.path.exists('/usr/bin/prctl'):
    205198    # suppress unaligned access to 0x..., ip=0x... warnings
     
    11501143            True
    11511144            sage: g.quit()
    11521145        """
    1153         if self.__use_workspace_cache and not os.path.exists(WORKSPACE):
    1154             gap_reset_workspace()
     1146        # Make sure GAP_DIR exists
     1147        try:
     1148            os.makedirs(GAP_DIR)
     1149            msg = "It is OK to delete all these cache files.  They will be recreated as needed.\n"
     1150            open(os.path.join(GAP_DIR, 'README.txt'), 'w').write(msg)
     1151        except OSError:
     1152            if not os.path.isdir(GAP_DIR):
     1153                raise
     1154
     1155        if self.__use_workspace_cache:
     1156            try:
     1157                # Check to see if we need to auto-regenerate the gap
     1158                # workspace, i.e., if the gap script is more recent
     1159                # than the saved workspace, which signals that gap has
     1160                # been upgraded.
     1161                if os.path.getmtime(WORKSPACE) < os.path.getmtime(GAP_BINARY):
     1162                    raise OSError("GAP workspace too old")
     1163                # Set the modification time of the workspace to the
     1164                # current time.  This ensures the workspace doesn't
     1165                # get deleted too soon by gap_reset_workspace().
     1166                os.utime(WORKSPACE, None)
     1167            except OSError, IOError:
     1168                gap_reset_workspace(verbose=False)
     1169
    11551170        global first_try
    11561171        n = self._session_number
    11571172        try:
    11581173            Expect._start(self, "Failed to start GAP.")
    1159         except Exception, msg:
     1174        except Exception:
    11601175            if self.__use_workspace_cache and first_try:
    11611176                print "A workspace appears to have been corrupted... automatically rebuilding (this is harmless)."
    11621177                first_try = False
     
    11661181                Expect._start(self, "Failed to start GAP.")
    11671182                self._session_number = n
    11681183                return
    1169             raise RuntimeError, msg
     1184            raise
    11701185       
    11711186        if self.__use_workspace_cache and self.__make_workspace:
    11721187            self.save_workspace()
     
    14361451    """
    14371452    if os.path.exists(WORKSPACE):
    14381453        os.unlink(WORKSPACE)
     1454
     1455    # Delete all gap workspaces that haven't been used in the last
     1456    # week, to avoid needless cruft.  I had an install on sage.math
     1457    # with 90 of these, since I run a lot of different versions of
     1458    # Sage, and it totalled 1.3GB of wasted space!  See trac #4936.
     1459    # We only do this after creating a new workspace, since this cruft
     1460    # issue is only a problem if workspaces get created every so
     1461    # often.  We don't want to have to do this on every startup.
     1462    now = time.time()
     1463    for F in os.listdir(GAP_DIR):
     1464        if F.startswith('workspace-'):
     1465            age = now - os.path.getatime(os.path.join(GAP_DIR, F))
     1466            if age >= 604800:    # 1 week in seconds
     1467                os.unlink(os.path.join(GAP_DIR, F))
    14391468       
     1469    # Create new workspace with filename WORKSPACE
    14401470    g = Gap(use_workspace_cache=False, max_workspace_size=None)
    14411471    for pkg in ['GAPDoc', 'ctbllib', 'sonata', 'guava', 'factint', \
    14421472                'gapdoc', 'grape', 'design', \
     
    14511481    # end for
    14521482    g.save_workspace()
    14531483    g.quit()
    1454    
    1455 
    1456 # Check to see if we need to auto-regenerate the gap workspace, i.e.,
    1457 # if the modification time of the gap link has changed (which signals
    1458 # that gap has been somehow upgraded).
    1459 if not os.path.exists(WORKSPACE) or os.path.getmtime(WORKSPACE) < os.path.getmtime(GAP_STAMP):
    1460     #print "Automatically updating the cached Gap workspace:"
    1461     #print WORKSPACE
    1462     gap_reset_workspace(verbose=False)
    1463 
    1464     # Delete all gap workspaces that haven't been used in at least 1
    1465     # week, to avoid needless cruft.  I had an install on sage.math
    1466     # with 90 of these, since I run a lot of different versions of
    1467     # Sage, and it totalled 1.3GB of wasted space!  See trac #4936.
    1468     # We only do this after creating a new workspace, since this cruft
    1469     # issue is only a problem if workspaces get created every so
    1470     # often.  We don't want to have to do this on every startup.
    1471     now = time.time()
    1472     for F in os.listdir(GAP_DIR):
    1473         if F.startswith('workspace'):
    1474             age = now - os.path.getatime(GAP_DIR + '/' + F)
    1475             if age  >= 604800:    # = 168*3600 = 2 weeks in seconds
    1476                 os.unlink(GAP_DIR + '/' + F)
    14771484
    14781485
    14791486class GapElement(GapElement_generic):