Example #1
0
def findpackage(package, root=None, firstval=0):
    '''findpackage(package[,root,firstval]) --> path(s) to package'''
    if not root: root = os.curdir
    print 'searching %s...' % root
    if package[0] != os.sep: package = os.sep + package
    packdir, basedir = os.path.split(package)
    targetdir = shutils.find(basedir, root, recurse=1, type='d')
    #print "targetdir" ,targetdir
    #remove invalid candidate directories (and 'BLD_ROOT' & 'EXPORT_ROOT')
    bldroot = shutils.env('BLD_ROOT', firstval=1)
    exproot = shutils.env('EXPORT_ROOT', firstval=1)
    remlist = []
    import fnmatch
    for dir in targetdir:
        if (not fnmatch.fnmatch(dir,'*'+package)) or \
           (not fnmatch.fnmatch(os.path.basename(dir),basedir)) or \
           ((bldroot) and (bldroot in dir)) or \
           ((exproot) and (exproot in dir)):
            remlist.append(dir)  #build list of bad matches
    for dir in remlist:
        targetdir.remove(dir)
    if targetdir: print '%s found' % package
    else: print '%s not found' % package
    if not firstval:
        return targetdir
    return prunelist(targetdir, counter=os.sep, all=False)
Example #2
0
def findpackage(package,root=None,firstval=0):
    '''findpackage(package[,root,firstval]) --> path(s) to package'''
    if not root: root = os.curdir
    print 'searching %s...' % root
    if package[0] != os.sep: package = os.sep+package
    packdir,basedir = os.path.split(package)
    targetdir = shutils.find(basedir,root,recurse=1,type='d')
    #print "targetdir" ,targetdir
    #remove invalid candidate directories (and 'BLD_ROOT' & 'EXPORT_ROOT')
    bldroot = shutils.env('BLD_ROOT',firstval=1)
    exproot = shutils.env('EXPORT_ROOT',firstval=1)
    remlist = []
    import fnmatch
    for dir in targetdir:
        if (not fnmatch.fnmatch(dir,'*'+package)) or \
           (not fnmatch.fnmatch(os.path.basename(dir),basedir)) or \
           ((bldroot) and (bldroot in dir)) or \
           ((exproot) and (exproot in dir)):
            remlist.append(dir) #build list of bad matches
    for dir in remlist:
        targetdir.remove(dir)
    if targetdir: print '%s found' % package
    else: print '%s not found' % package
    if not firstval:
        return targetdir
    return prunelist(targetdir,counter=os.sep,all=False)
Example #3
0
def findLib():
    res = env(blas_lib_envvar, 1)
    if res: return res, get_usingLib("blas", res, linkas=1)[1]

    import sys, os
    if sys.platform[:6] == 'darwin':
        dirs = ['/sw/lib', '/usr/local/lib', '/usr/lib']  # None]
    elif os.name[:5] == "posix":
        dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib']  # None]
    else:
        raise InstallationNotFound, "Don't know how to search for library blas, unknown operating system."

    res, name = get_usingLib("blas", alt=1, linkas=1)
    if res: return res, name

    for directory in dirs:
        print "Searching %s..." % directory
        res, name = get_usingLib("blas", directory, linkas=1)
        if res: return res, name
        continue

    #raise EnvironmentError, "Unable to find lib directory of blas"
    print "Unable to find lib directory of blas"
    return None, None
Example #4
0
def findLib():
    res = env(lapack_lib_envvar,1)
    if res: return res,get_usingLib("lapack",res,linkas=1)[1]

    import sys, os
    if sys.platform[:6] == 'darwin':
        dirs = ['/sw/lib', '/usr/local/lib', '/usr/lib']# None]
    elif os.name[:5] == "posix":
        dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib']# None]
    else:
        raise InstallationNotFound, "Don't know how to search for library lapack, unknown operating system."
    
    res,name = get_usingLib("lapack",alt=1,linkas=1)
    if res: return res,name

    for directory in dirs:
        print "Searching %s..." % directory
        res,name = get_usingLib("lapack",directory,linkas=1)
        if res: return res,name
        continue
        
    #raise EnvironmentError, "Unable to find lib directory of lapack"
    print "Unable to find lib directory of lapack"
    return None,None
Example #5
0
def test():
    '''test(); script to test all functions'''
    print 'testing makefilter...'
    print makefilter(['PYTHON*', 'DEVELOPER'])
    print makefilter([])

    print 'testing getVars...'
    bogusdict = {
        'PYTHIA_STUFF': '${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff',
        'MIKE_VERSION': '1.0',
        'MIKE_DIR': '${HOME}/junk',
        'DUMMY_VERSION': '6.9',
        'DUMMY_STUFF': '/a/b',
        'PYTHIA_VERSION': '0.0.1'
    }
    homedir = shutils.getHOME()
    print getVars(homedir)
    print getVars('${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff')
    print getVars('${MIKE_DIR}/stuff', bogusdict)

    print 'testing expandvars...'
    print expandvars(homedir)
    print expandvars('${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff')
    print expandvars('${MIKE_DIR}/${DV_DIR}/stuff', bogusdict)
    print expandvars('${DV_DIR}/${PYTHIA_VERSION}', secondref=bogusdict)
    print expandvars('${DV_DIR}/${PYTHIA_VERSION}', bogusdict, os.environ)

    print 'testing convert...'
    source = 'test.txt'
    f = open(source, 'w')
    f.write('this is a test file.' + os.linesep)
    f.close()
    convert(source, 'mac')
    convert(source)

    print 'testing replaceText...'
    replaceText(source, {' is ': ' was '})
    replaceText(source, {'\sfile.\s': '.'})
    f = open(source, 'r')
    print f.read()
    f.close()
    os.remove(source)

    print 'testing getLines...'
    fl = ['begin\n', 'hello\n', 'world\n', 'string\n']
    print getLines(fl, 'hello\n', 'world\n')

    print 'testing findpackage...'
    print findpackage('gsl/infect', shutils.env('DV_DIR', 1), 1)
    print findpackage('dev/pythia*', shutils.env('DV_DIR', 1))
    print findpackage('python*', '/usr/local/lib')

    print 'testing makeTarget...'
    print makeTarget('~/dev')
    print makeTarget('~/dev', forceSSH=True)
    print makeTarget('~/dev', host='arcs.caltech.edu', user=shutils.getUSER())

    print 'testing parseTarget...'
    destination = '[email protected]:~/dev'
    print parseTarget(destination, useOption=True)
    destination = '[email protected]:'
    print parseTarget(destination)
    destination = 'arcs.caltech.edu:'
    print parseTarget(destination, useOption=True)
    destination = 'test.txt'
    print parseTarget(destination, forceSSH=True)

    print 'testing prunelist...'
    testlist = [
        'zero', 'one', 'two', 'three', '4', 'five', 'six', 'seven', '8', '9/81'
    ]
    print prunelist(testlist)
    print prunelist(testlist, minimum=False)
    print prunelist(testlist, minimum=False, reverse=True, all=False)
    print prunelist(testlist, counter=os.sep, minimum=False, all=False)

    print 'testing prunedict...'
    print prunedict(bogusdict)
    print prunedict(bogusdict, minimum=False, counter=os.sep)
    print prunedict(bogusdict, minimum=False, counter=os.sep, all=False)
    return
Example #6
0
def test():
    '''test(); script to test all functions'''
    print 'testing makefilter...'
    print makefilter(['PYTHON*','DEVELOPER'])
    print makefilter([])

    print 'testing getVars...'
    bogusdict = {'PYTHIA_STUFF':'${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff',
                 'MIKE_VERSION':'1.0','MIKE_DIR':'${HOME}/junk',
                 'DUMMY_VERSION':'6.9','DUMMY_STUFF':'/a/b',
                 'PYTHIA_VERSION':'0.0.1'}
    homedir = shutils.getHOME()
    print getVars(homedir)
    print getVars('${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff')
    print getVars('${MIKE_DIR}/stuff',bogusdict)

    print 'testing expandvars...'
    print expandvars(homedir)
    print expandvars('${DV_DIR}/pythia-${PYTHIA_VERSION}/stuff')
    print expandvars('${MIKE_DIR}/${DV_DIR}/stuff',bogusdict)
    print expandvars('${DV_DIR}/${PYTHIA_VERSION}',secondref=bogusdict)
    print expandvars('${DV_DIR}/${PYTHIA_VERSION}',bogusdict,os.environ)

    print 'testing convert...'
    source = 'test.txt'
    f = open(source,'w')
    f.write('this is a test file.'+os.linesep)
    f.close()
    convert(source,'mac')
    convert(source)

    print 'testing replaceText...'
    replaceText(source,{' is ':' was '})
    replaceText(source,{'\sfile.\s':'.'})
    f = open(source,'r')
    print f.read()
    f.close()
    os.remove(source)

    print 'testing getLines...'
    fl = ['begin\n','hello\n','world\n','string\n']
    print getLines(fl,'hello\n','world\n')

    print 'testing findpackage...'
    print findpackage('gsl/infect',shutils.env('DV_DIR',1),1)
    print findpackage('dev/pythia*',shutils.env('DV_DIR',1))
    print findpackage('python*','/usr/local/lib')

    print 'testing makeTarget...'
    print makeTarget('~/dev')
    print makeTarget('~/dev',forceSSH=True)
    print makeTarget('~/dev',host='arcs.caltech.edu',user=shutils.getUSER())

    print 'testing parseTarget...'
    destination = '[email protected]:~/dev'
    print parseTarget(destination,useOption=True)
    destination = '[email protected]:'
    print parseTarget(destination)
    destination = 'arcs.caltech.edu:'
    print parseTarget(destination,useOption=True)
    destination = 'test.txt'
    print parseTarget(destination,forceSSH=True)

    print 'testing prunelist...'
    testlist = ['zero','one','two','three','4','five','six','seven','8','9/81']
    print prunelist(testlist)
    print prunelist(testlist,minimum=False)
    print prunelist(testlist,minimum=False,reverse=True,all=False)
    print prunelist(testlist,counter=os.sep,minimum=False,all=False)

    print 'testing prunedict...'
    print prunedict(bogusdict)
    print prunedict(bogusdict,minimum=False,counter=os.sep)
    print prunedict(bogusdict,minimum=False,counter=os.sep,all=False)
    return