Ticket #13373: 13373_remove_scripts.patch

File 13373_remove_scripts.patch, 6.4 KB (added by jdemeyer, 9 years ago)
  • deleted file sage-download_package

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1345142825 -7200
    # Node ID e51ea1fbeafe0ff111ae6605382c22fbceb1713e
    # Parent  fe35059255e7c3b265d525bbbd1f046c8bbe616e
    Remove obsolete sage-latest-online-package and sage-download_package scripts
    
    diff --git a/sage-download_package b/sage-download_package
    deleted file mode 100755
    + -  
    1 #!/usr/bin/env python
    2 #####################################################
    3 #
    4 # Download to the current directory a SAGE spkg from
    5 # the internet.
    6 #
    7 # AUTHOR: William Stein
    8 #####################################################
    9 
    10 import os, sys, urllib
    11 
    12 if len(sys.argv) < 2:
    13      print "Usage: %s <package name> <package name> ..."%sys.argv[0]
    14      sys.exit(1)
    15 
    16 # Define SAGE_ROOT and PKG_SERVER based on the environment.
    17 
    18 if not os.environ.has_key("SAGE_ROOT"):
    19      print "The environment variable SAGE_ROOT must be set."
    20      sys.exit(1)
    21 SPKG_ROOT="%s/spkg/"%os.environ["SAGE_ROOT"]
    22 
    23 if not os.environ.has_key("SAGE_SERVER"):
    24      print "The environment variable SAGE_SERVER must be set."
    25      sys.exit(1)
    26 PKG_SERVER=os.environ['SAGE_SERVER'] + '/packages'
    27 
    28 # use http_error_default from URLopener to raise an IOError on failure
    29 urllib.FancyURLopener.http_error_default = urllib.URLopener.http_error_default
    30 
    31 # This reporthook is used below to print ...'s as the file downloads.
    32 cur = 0
    33 def reporthook(block, size, total):
    34      global cur
    35      n = block*size*50/total
    36      if n > cur:
    37           cur = n
    38           sys.stdout.write('.')
    39           sys.stdout.flush()
    40 
    41 def download_file(file, repository='optional'):
    42      """
    43      Find the spkg with name given by file and download it from the internet.
    44 
    45      If 'http://' is a substring of file, then everything before http://
    46      is ignored and the file is downloaded from that url. Otherwise the
    47      file is downloaded from the server given by SAGE_SERVER.
    48      
    49      INPUT:
    50          file -- string; the name of a file
    51          repository -- string (default: 'optional') name of the repository
    52          
    53      OUTPUT:
    54          bool -- True if we succeed at download the spkg; otherwise, False.
    55 
    56      NOTE: There are no md5 checks on the downloads.  This function is
    57      one place where they could go.
    58      """
    59      # Add .spkg to the end of the filename
    60      if not file.endswith(".spkg"):
    61           file += ".spkg"
    62      # Check to see if the file is a url. The reason we use .find
    63      # is because the exact PATH gets appended to the front of file,
    64      # so one has, for example
    65      #     file = /opt/sage/http://sagemath.org/home/was/file.spkg
    66      i = file.lower().find('http://')
    67      if i != -1:
    68           # It's a URL
    69           url = file[i:]
    70           file = os.path.split(file)[-1]
    71      else:
    72          # Now grab the actual file using Python's urllib.
    73          file = os.path.split(file)[-1]
    74          # It's hopefully at the package server somewhere.
    75          url = "%s/%s/%s"%(PKG_SERVER, repository, file)
    76      already_exists = os.path.exists(file)
    77 
    78      # Now do the actual download, printing nice ...'s as the download proceeds.
    79      print url, "-->", file
    80      print "[",
    81      global cur
    82      cur = 0
    83      try:
    84          urllib.urlretrieve(url, file, reporthook)
    85      except IOError:
    86          print "]"
    87          return False
    88      except KeyboardInterrupt:
    89          print "]"
    90          print "Keyboard interrupt:",
    91          if not already_exists and os.path.exists(file):
    92               print "removing partially downloaded file"
    93               os.remove(file)
    94          else:
    95               print "exiting"
    96          sys.exit(1)
    97      print "]"
    98      return True
    99 
    100 
    101 # For each input argument, we download the corresponding spkg.
    102 # The spkg's are downloaded to the current directory.
    103 
    104 for F in sys.argv[1:]:
    105      if 'http://' in F.lower():
    106           # The spkg is given by a URL:
    107           download_file(F)
    108      else:
    109           # The spkg is a file, so get it from the remote repository.
    110           for repo in ['optional', 'standard', 'experimental', 'archive']:
    111               if download_file(F, repo):
    112                     sys.exit(0)
    113           print "*"*70
    114           print "* Unable to download %s"%os.path.split(F)[-1]
    115           print "* Please see %s for a list of valid\n* packages or check the package name."%PKG_SERVER
    116           print "*"*70
    117 
  • deleted file sage-latest-online-package

    diff --git a/sage-latest-online-package b/sage-latest-online-package
    deleted file mode 100755
    + -  
    1 #!/usr/bin/env python
    2 ############################################################################
    3 #
    4 # Searches for the latest online package in each repository in $SAGE_SERVER
    5 #
    6 # License: GPLv2+ = GPLv2 or any later version at the user's option
    7 #
    8 ############################################################################
    9 from __future__ import print_function
    10 import os, sys, urllib2, re
    11 from urllib2 import HTTPError
    12 
    13 # Define SAGE_ROOT and PKG_SERVER based on the environment.
    14 
    15 if not os.environ.has_key("SAGE_ROOT"):
    16      sys.exit("The environment variable SAGE_ROOT must be set.")
    17 SPKG_ROOT="%s/spkg/"%os.environ["SAGE_ROOT"]
    18 
    19 if not os.environ.has_key("SAGE_SERVER"):
    20      sys.exit("The environment variable SAGE_SERVER must be set.")
    21      
    22 PKG_SERVER=os.environ['SAGE_SERVER'] + '/packages'
    23 
    24 strip_version_re = re.compile(r'-.+')
    25 
    26 def strip_version(string):
    27      return strip_version_re.sub('', string)
    28 
    29 # Adapted from `sage-update`
    30 def spkg_list(repo):
    31     """
    32     INPUT:
    33    
    34         - repo -- repository to look for the package in.
    35        
    36     OUTPUT:
    37    
    38         - returns the array of packages
    39     """
    40     web_url = "%s/%s/list"%(PKG_SERVER, repo)
    41     # Download the spkg/ directory listing.
    42     try:
    43          data = urllib2.urlopen(web_url)
    44     except HTTPError:
    45          sys.exit("Could not download file from {0}.".format(web_url))
    46     return data.read().splitlines()
    47 
    48 if __name__ == '__main__':
    49      if len(sys.argv) < 2:
    50           sys.exit("Usage: {0} <package name>".format(sys.argv[0]))
    51          
    52      package_name = sys.argv[1]
    53      for repository in ['optional', 'standard', 'experimental', 'archive']:
    54           packages = spkg_list(repository)
    55           for package in packages:
    56                if package_name == strip_version(package):
    57                     print(package)
    58                     sys.exit(0)
    59      sys.exit("Could not find a version for {0}.".format(package_name))