if download_url(source + filename, dest_dir, dryrun):
return True
return False
def globfilt(pdfs, patterns):
"Unix-style pattern matching of arguments"
rtn = []
if not patterns:
return pdfs
from fnmatch import fnmatch
for pdf in pdfs:
for pattern in patterns:
if fnmatch(pdf, pattern):
rtn.append(pdf)
return rtn
import argparse
class CommandHandler(object):
"""\
A program for managing LHAPDF parton distribution function data files.
The main sub-commands that can be used are:
- list|ls: list available PDF sets, optionally categorised by status
- update: download and install a new PDF set index file
- install|get: download and install new PDF set data files
- upgrade: download and install newer replacement PDF set data files where available
"""
def __init__(self):
## Load settings from Python module
try:
import lhapdf
DATADIR = lhapdf.paths()[0]
VERSION = lhapdf.__version__
except ImportError:
DATADIR = None
VERSION = None
## Parse the command line
ap = argparse.ArgumentParser(description=self.__doc__, formatter_class=argparse.RawTextHelpFormatter)
ap.add_argument("COMMAND", metavar="COMMAND [suboptions]", help="Subcommand to run")
ap.add_argument("--listdir", default=DATADIR, dest="LISTDIR", help="Directory containing the lhapdf.index list file [default: %(default)s]")
ap.add_argument("--pdfdir", default=DATADIR, dest="PDFDIR", help="Directory for installation of PDF set data [default: %(default)s]")
ap.add_argument("--source", default=[CVMFSBASE, URLBASE], action="append", dest="SOURCES", help="Prepend a path or URL to be used as a source of data files [default: %(default)s]")
ap.add_argument("--quiet", help="Suppress normal messages", dest="VERBOSITY", action="store_const", const=logging.ERROR, default=logging.INFO)