Changeset 12881


Ignore:
Timestamp:
08/02/12 17:45:23 (13 years ago)
Author:
glperez
Message:

Modified DownloadExternalPackage.py to output usage examples when fed no arguments.

Location:
issm/trunk-jpl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/externalpackages/gsl/install-android.sh

    r12846 r12881  
    1010
    1111    #Download from ISSM server
    12     $ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/gsl-1.15.tar.gz' 'gsl-1.15.tar.gz'
     12    $ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/gsl-1.' 'gsl-1.15.tar.gz'
    1313
    1414    #Untar
     
    2828    ./configure \
    2929        --build="i386-apple-darwin10.8.0" \
    30         --host=$host_triplet\
    31             --prefix="$ISSM_DIR/externalpackages/gsl/install/"
     30        --host=$host_triplet \
     31            --prefix="$ISSM_DIR/externalpackages/gsl/install/" \
     32        --disable-static
    3233fi
    3334
  • issm/trunk-jpl/externalpackages/libtool/install.sh

    r12846 r12881  
    66
    77#Download from ISSM server
    8 $ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/libtool' 'libtool'
     8$ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/libtool' 'libtool.tar.gz'
    99
    1010#Untar
  • issm/trunk-jpl/externalpackages/triangle/install-android.sh

    r12738 r12881  
    11#!/bin/bash
    2 source $ANDROID_DIR/android_aux.sh
    32
    4 # use matlab?
    5 matlab=0
    6 
    7 # Some cleanup
     3#Some cleanup
    84rm -rf install triangle
    95mkdir install
    106
    11 # Download from ISSM server
     7#Download from ISSM server
    128$ISSM_DIR/scripts/DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/triangle.zip' 'triangle.zip'
    139
    14 # Untar
     10#Untar
    1511cd install
    1612cp ../triangle.zip ./
    1713unzip triangle.zip
    1814
    19 # copy new makefile
    20 cp ../configs//android/configure.make ./
     15#copy new makefile
     16cp ../configs/android/configure.make ./
    2117cp ../makefile ./
    2218
    23 # Patch triangle.c
    24 if [[ $matlab == "1" ]];then
    25         patch triangle.c ../triangle.c.patch.matlab
    26 else
    27         patch triangle.c ../triangle.c.patch.python
    28 fi
     19#Patch triangle.c
     20patch triangle.c ../triangle.c.patch
    2921
    30 # Compile triangle
    31 make -j $j
     22#Compile triangle
     23make
    3224
    33 # Patch triangle.h
     25#Patch triangle.h
    3426patch triangle.h ../triangle.h.patch
  • issm/trunk-jpl/scripts/DownloadExternalPackage.py

    r12846 r12881  
    11#!/usr/bin/env python
    22# -*- coding: ISO-8859-1 -*-
     3#
     4# TODO: Improve upon extension recognition by checking for mismatches in found targets
     5# and specified local file.
     6#
    37
    48import os,sys,re
     
    2125# End class myHTMLParser
    2226
    23 pivot = sys.argv[1].rfind("/")
    24 url = (sys.argv[1])[:pivot]
    25 localFile=sys.argv[2]
     27# Separates the URL into a directory and the file or pattern based on the
     28# last appearance of '/'.
     29if len(sys.argv) > 1:
     30    pivot = sys.argv[1].rfind("/")
     31    url = (sys.argv[1])[:pivot]
     32    pivot += 1
     33    find = (sys.argv[1])[pivot:]
     34else:
     35    print "******************************************************************************************************************************"
     36    print "* Invalid input!                                                                                                             *"
     37    print "*                                                                                                                            *"
     38    print "* Try: 'DownloadExternalPackage.py url [localFile]'                                                                          *"
     39    print "*                                                                                                                            *"
     40    print "* Where 'URL' is the URL with an explicit package name or the URL followed by the truncated package name. And 'localFile' is *"
     41    print "* the file name (including extension) that you would like to save as.                                                        *"
     42    print "*                                                                                                                            *"
     43    print "* Examples:                                                                                                                  *"
     44    print "*                                                                                                                            *"
     45    print "* DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/petsc-2.3.2-p3.tar.gz' 'petsc-2.3.2-p3.tar.gz' *"
     46    print "*                                                                                                                            *"
     47    print "*     This is the old style and the safest way to download a package.                                                        *"
     48    print "*                                                                                                                            *"
     49    print "* DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/libtool' 'libtool.tar.gz'                      *"
     50    print "*                                                                                                                            *"
     51    print "*     This is the new style. For packages like 'Libtool', which we never expect to be using multiple versions, this will     *"
     52    print "*     download the most recent version and save it as the generic 'libtool.tar.gz'.                                          *"
     53    print "*                                                                                                                            *"
     54    print "* DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/gsl-1.' 'gsl-1.15.tar.gz'                      *"
     55    print "*                                                                                                                            *"
     56    print "*     This is the new style. This is a demonstration of how this script can be used to disambiguate a package name if there  *"
     57    print "*     are more than once package matching 'gsl-'.                                                                            *"
     58    print "*                                                                                                                            *"
     59    print "* DownloadExternalPackage.py 'http://issm.jpl.nasa.gov/files/externalpackages/libtool'                                       *"
     60    print "*                                                                                                                            *"
     61    print "*     This is the new style. This will download a package with 'libtool' as a prefix and save it as its canonical name.      *"
     62    print "*                                                                                                                            *"
     63    print "*                                                                                                                            *"
     64    print "******************************************************************************************************************************"
    2665
    27 pivot += 1;
    28 find = (sys.argv[1])[pivot:];
     66if len(sys.argv) > 2:
     67    localFile=sys.argv[2]
     68    print "Downloaded file will saved as: " + localFile
     69else:
     70    localFile = None
     71    print "Downloaded file will saved with the same file name."
     72
     73
    2974print "Looking for " + find
     75
     76# As an extra precaution, if no extension is given for a particular package
     77# such as '.../libtool', then ensure that files found are of appropriate
     78# file extensions.
     79#
     80# WARNING: The external packages directory includes executable binaries with
     81# '.exe' extensions. As such, '.exe' is an acceptable suffix, but this is
     82# inherently dangerous since this script can be used to download from any
     83# valid website. Furthermore, if an individual attempts a "man-in-the-middle" 
     84# attack, then the user would be capable of downloading executables from
     85# an untrusted source.
    3086pattern = find + "[\w.-]*(\.tar\.gz|tar\.gz2|tgz|zip|exe)?"
    3187parser = MyHTMLParser(pattern)
    3288
     89# Creates a 'FancyURL' which allows the script to fail gracefully by catching
     90# HTTP error codes 30X and several 40X(where 'X' is a natural number).
    3391urlObject = FancyURLopener()
    3492obj = urlObject.open(url)
    3593parser.feed(obj.read())
    3694
     95# If a file pattern was used to describe the file that should be downloaded,
     96# then there is the potential for multiple file matches. Currently, the script
     97# will detect this ambiguity and print out all the matches, while informing
     98# the user that he must refine his search.
     99#
     100# TODO: Prompt the user to select from a list his/her preferred target.
    37101if len(parser.targets) > 1:
    38102    print "Could not resolve your download due to the number of hits."
     
    42106
    43107elif len(parser.targets) == 1:
     108    print "Found: " + parser.targets[0]
    44109    url += "/" + parser.targets[0]
    45     if os.path.exists(localFile):
    46         print "File "+ localFile +" already exists and will not be downloaded..."
    47     elif parser.targets[0] == localFile:
    48         urllib.urlretrieve(url, localFile)
    49         print "Found: " + parser.targets[0]
    50     elif parser.matcher.match(localFile) != "None":
    51         urllib.urlretrieve(url,parser.targets[0]);
    52         print "Found: " + parser.targets[0]
     110
     111    if localFile is None:
     112        if os.path.exists(parser.targets[0]):
     113            print "File " + parser.targets[0] + " already exists and will not be downloaded..."
     114        else:
     115            urllib.urlretrieve(url, parser.targets[0])
     116            print "File saved as: " + parser.targets[0]
    53117    else:
    54         urllib.urlretrieve(url, parser.targets[0]);
    55         print "WARNING: the file found \'" + parser.targets[0] + "\' does not match \'" + localFile + "\'"
    56         print "Ensure the downloaded version is suitable."
     118        if os.path.exists(localFile):
     119            print "File "+ localFile +" already exists and will not be downloaded..."
     120        else:
     121            if parser.targets[0] == localFile:
     122                print "File found and destination match."
     123            elif parser.matcher.match(localFile) != "None":
     124                print "File found matches destination pattern."
     125            else:
     126                print "WARNING: the file found \'" + parser.targets[0] + "\' does not match \'" + localFile + "\'"
     127                print "Ensure the downloaded version is suitable."
     128
     129            urllib.urlretrieve(url, localFile)
     130            print "File saved as: " + localFile
    57131
    58132else:
Note: See TracChangeset for help on using the changeset viewer.