#!/usr/bin/env python3 """ Simple install script for: fastjet (maybe problem with the site blocking downloads!) hepmc2 pythia lhapdf6 YODA madgraph hackanalysis i.e. everything required to run hackanalysis with all features. To run this script you need wget v1 05/01/2024 """ # Default urls: ### Madgraph uses "hepmc2":"https://hepmc.web.cern.ch/hepmc/releases/hepmc2.06.09.tgz" from 2012 ## HepmC 2 has been updated three times since, most recently in 2020 ## https://hepmc.web.cern.ch/hepmc/ default_urls={"pythia": "https://pythia.org/download/pythia83/pythia8310.tgz","fastjet": "http://www.fastjet.fr/repo/fastjet-3.4.2.tar.gz","hepmc2":"https://hepmc.web.cern.ch/hepmc/releases/hepmc2.06.11.tgz","lhapdf6": "https://lhapdf.hepforge.org/downloads/?f=LHAPDF-6.5.4.tar.gz","pdfsets": "https://lhapdfsets.web.cern.ch/current/","YODA":"https://yoda.hepforge.org/downloads/?f=YODA-2.0.0.tar.gz","madgraph":"https://launchpad.net/mg5amcnlo/3.0/3.5.x/+download/MG5_aMC_v3.5.3.tar.gz","hackanalysis":"https://goodsell.pages.in2p3.fr/hackanalysis/Downloads/HackAnalysis_v1.2.tar.gz","zlib":"https://zlib.net/current/zlib.tar.gz"} import os from datetime import datetime import sys import shutil import json import collections import argparse #import urllib import tarfile import subprocess import logging #from rich.progress import track #from progress.bar import Bar #import requests import wget import ssl ssl._create_default_https_context = ssl._create_unverified_context reinstall=False clean_tarballs=False cwd = os.getcwd() tarballdir=os.path.join(cwd,'Downloads') if not os.path.exists(tarballdir): os.makedirs(tarballdir) def shell_command(command_to_execute,working_dir): global log try: command_line = subprocess.Popen(command_to_execute,shell=True, cwd=working_dir,stdout=subprocess.PIPE,stderr=subprocess.PIPE) out, err = command_line.communicate() except Exception as e: raise NameError(e) res = out.decode().strip() #log.debug(out.decode("utf-8").strip()) if err != b'': log.debug('Warning messages from '+command_to_execute+': '+err.decode("utf-8").strip()) return res def use_requests(temp_url,temp_filename): """ This for fastjet, which seems to have blocked the python wget """ try: import requests except Exception as e: raise NameError("Failed with requests import " + str(e)) notrack=False try: from rich.progress import track except: notrack=True log.debug('Trying to download ' +temp_url+' by a different method') try: r = requests.get(temp_url,stream=True, headers={'User-agent': 'Mozilla/5.0'}) r.raise_for_status() with open(temp_filename, 'wb') as f: total_length = int(r.headers.get('content-length')) #print("Length: " +str(total_length)) #with Bar('Downloading %s' % temp_filename,max=total_length) as bar: #for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1): if notrack: chunktotal=(total_length/1024) + 1 ichunktotal=int(chunktotal) #nn = 0 for nn,chunk in enumerate(r.iter_content(chunk_size=1024)): if chunk: f.write(chunk) f.flush() #nn=nn+1 done=nn*50//ichunktotal todo=50-done percentage=nn*100//ichunktotal string='['+('='*done)+(' '*todo)+'] Downloading '+str(percentage)+'% ' print(string,end='\r') print('['+('='*50)+'] Downloading 100%') else: for chunk in track(r.iter_content(chunk_size=1024),total=(total_length/1024) + 1,description='Downloading '+temp_filename): if chunk: f.write(chunk) f.flush() return temp_filename except Exception as e: raise NameError("Failed to download using requests, "+str(e)) #with open("img.png", 'wb') as f: # r.raw.decode_content = True # shutil.copyfileobj(r.raw, f) def get_file(temp_url,user_filename=None): global tarballdir,cwd #temp_filename=os.path.basename(temp_url).strip('?f=') if user_filename is None: temp_filename=os.path.basename(temp_url).replace('?f=','') else: temp_filename=user_filename log.info("Getting %s " % temp_filename) os.chdir(tarballdir) if os.path.exists(temp_filename) and not clean_tarballs: log.debug('Found pre-existing '+temp_filename) os.chdir(cwd) return temp_filename else: if clean_tarballs and os.path.exists(temp_filename): os.remove(temp_filename) try: filename = wget.download(temp_url,temp_filename) os.chdir(cwd) return filename except Exception as e: os.chdir(cwd) log.info("Could not download " +str(temp_url) +", " +str(e)) try: os.chdir(tarballdir) filename = use_requests(temp_url,temp_filename) os.chdir(cwd) return filename except Exception as ee: os.chdir(cwd) raise NameError(str(ee)) def extract_tar(tarball): """ extract the tarball and return the base directory """ global reinstall,tarballdir tar = tarfile.open(os.path.join(tarballdir,tarball)) #firstentry=tar.next() ## This to ignore stupid MacOS files found in MicrOMEGAs release allentries=[ x for x in tar.getnames() if not x.startswith('._')] #allentries=tar.list() baseprefix=os.path.commonprefix(allentries) if os.path.exists(baseprefix): if reinstall: shutil.rmtree(baseprefix) else: return baseprefix,True #raise NameError(baseprefix) if baseprefix == '': baseprefix = tarball.strip('.tar.gz') tar.extractall(path=baseprefix) tar.close() else: tar.extractall() tar.close() return baseprefix,False def extract_get(tempurl): try: tfile=get_file(tempurl) except Exception as e: raise NameError("Failed to download, "+str(e)) pre_existing=False try: basedir,pre_existing=extract_tar(tfile) except Exception as e: raise NameError("Error extracting file "+str(e)) return basedir,pre_existing def install_cmake(name,shortname,config_options,nickname=None): global latest_urls,reinstall if nickname is None: nickname=name tempurl=latest_urls[nickname] tfile=get_file(tempurl) pre_existing=False try: basedir,pre_existing=extract_tar(tfile) #if pre_existing: # return basedir except Exception as e: raise NameError("Error extracting "+name+": "+str(e)) ## Now to create a target directory ## Assume that the version number is like name-xxxxx if not shortname.lower() in basedir.lower(): raise NameError('Some problem with %s not in the base directory %s ' %(name,basedir)) vno=basedir[len(name):].replace('.','').replace('-','') install_dir=os.path.join(cwd,shortname+vno) builddir=os.path.join(cwd,basedir,'build') if not os.path.exists(builddir): # If reinstall then we already removed the build directory #if reinstall: # shutil.rmtree(builddir) os.makedirs(builddir) if os.path.exists(install_dir): if reinstall: shutil.rmtree(install_dir) else: return install_dir log.debug("configuring "+name+" "+vno+ ' to '+install_dir) _=shell_command('cmake .. '+config_options+' -DCMAKE_INSTALL_PREFIX='+install_dir,builddir) log.debug("Compiling "+name+" "+vno) _=shell_command("make && make install",os.path.join(cwd,builddir)) return install_dir,os.path.join(cwd,basedir) def install_configure(name,shortname,config_options,nickname=None): global latest_urls,reinstall,cwd if nickname is None: nickname = name tempurl=latest_urls[nickname] tfile=get_file(tempurl) pre_existing=False try: basedir,pre_existing=extract_tar(tfile) #if pre_existing: # return basedir except Exception as e: raise NameError("Error extracting "+name+": "+str(e)) ## Now to create a target directory ## Assume that the version number is like name-xxxxx if not name.lower() in basedir.lower(): raise NameError('Some problem with %s not in the base directory %s' %(name,basedir)) vno=basedir[len(name):].replace('.','').replace('-','') install_dir=os.path.join(cwd,shortname+vno) log.debug('version: '+vno) if os.path.exists(install_dir): if reinstall: shutil.rmtree(install_dir) else: return install_dir,os.path.join(cwd,basedir) log.info("configuring "+name+" "+vno+ ' to '+install_dir) _=shell_command('./configure '+config_options+' --prefix='+install_dir,os.path.join(cwd,basedir)) log.info("Compiling "+name+" "+vno) _=shell_command("make && make install",os.path.join(cwd,basedir)) return install_dir,os.path.join(cwd,basedir) def install_pythia(config_options): global latest_urls log.info('Installing pythia') tempurl=latest_urls["pythia"] try: basedir,pre_existing=extract_get(tempurl) except Exception as e: raise NameError("Error extracting Pythia "+str(e)) ## Compile ## pythia compiled against fastjet, lhapdf6, hepmc2, gzip #./configure --with-fastjet3=/home/tmp/goodsell/Packages/Collider/FJ340 --with-lhapdf6=/home/tmp/goodsell/Packages/Collider/LHAPDF623 --with-hepmc2=/home/tmp/goodsell/Packages/Collider/HepMC206 --with-gzip vno=basedir[len('pythia'):].replace('.','').replace('-','') log.debug("configuring pythia "+vno+ ' with '+config_options) _=shell_command('./configure '+config_options,os.path.join(cwd,basedir)) log.debug("Making pythia") _=shell_command("make",os.path.join(cwd,basedir)) os.chdir(cwd) return os.path.join(cwd,basedir) def install_madgraph(): global latest_urls,reinstall try: basedir,pre_existing=extract_get(latest_urls['madgraph']) if pre_existing and not reinstall: return basedir except Exception as e: raise NameError("Error extracting madgraph: "+str(e)) ## Now to install fastjet and pythia with open('temp.mg','w') as OF: OF.write('install pythia8\n') OF.write('install fastjet\n') log.info("Installing madgraph packages") _=shell_command(os.path.join(cwd,basedir,'bin','mg5_aMC temp.mg'),cwd) """ try: #os.system("make") print("Installing madgraph packages") #print(os.path.join(cwd,basedir,'bin','mg5_aMC temp.mg')) command_line = subprocess.Popen(os.path.join(cwd,basedir,'bin','mg5_aMC temp.mg'), shell=True, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = command_line.communicate() except Exception as e: raise NameError("Error installing madgraph packages "+str(e)) """ os.remove('temp.mg') return basedir """ Parse the arguments """ info_message='Please specify the tool(s) you want to install.\n Valid options are: All, SARAH, SPheno, MicrOmegas, HiggsBounds, HiggsSignals, VevaciousPlusPlus and BSMArt.' try: parser = argparse.ArgumentParser( description=info_message) # parser.add_argument('inputfile', # metavar='File', type=str, # help='Input file name') # parser.add_argument('directory', # metavar='directory', type=str, # help='Destination directory') parser.add_argument("--All", help="Install all tools", action="store_true") parser.add_argument("--pythia", help="Install pythia", action="store_true") parser.add_argument("--fastjet", help="Install fastjet", action="store_true") parser.add_argument("--hepmc2", help="Install hepmc2", action="store_true") parser.add_argument("--lhapdf6", help="Install lhapdf6", action="store_true") parser.add_argument("--yoda", help="Install yoda", action="store_true") parser.add_argument("--madgraph", help="Install madgraph/mg5@aMC", action="store_true") parser.add_argument("--hackanalysis", help="Install HackAnalysis", action="store_true") parser.add_argument("--zlib", help="Install zlib, if MadGraph hasn't done it already", action="store_true") parser.add_argument("--rootpath", help="Path to CERN root installation (not installed by this tool, it is too pernickety)", nargs="+",action="store",default='') # parser.add_argument("--Fortran", help="Fortran compiler name",nargs="+",action="store", # default='gfortran') # parser.add_argument("--FF", help="mpi Fortran compiler name for Diver, e.g. mpif90",nargs="+",action="store", # default='mpif90') parser.add_argument("--Reinstall", help="Reinstall packages", action="store_true") parser.add_argument("--Redownload",help="Delete local copies of tarballs before reinstallation",action="store_true") parser.add_argument("--LocalUrls", help="Don't try to update the urls from the internet", action="store_true") args = parser.parse_args() except Exception as e: print(info_message +str(e)) raise SystemExit if args.Reinstall: reinstall=True if args.Redownload: reinstall=True clean_tarballs=True #print(cwd) latest_urls=default_urls """ Set up logging """ scriptdir=os.path.join(cwd,'ScriptsAndLogs') if not os.path.exists(scriptdir): os.makedirs(scriptdir) log = logging.getLogger('ColliderToolsInstall') logfile=os.path.join(scriptdir,'ColliderToolsInstall.log') if os.path.exists(logfile): os.remove(logfile) log.setLevel(logging.DEBUG) ch = logging.StreamHandler() ch.setLevel(logging.INFO) fh = logging.FileHandler(logfile) fh.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) log.addHandler(fh) log.addHandler(ch) ### Now try to update urls from the website online_urls='http://goodsell.pages.in2p3.fr/hackanalysis/json/HEPcolliderurls.json' urls_json='HEPcolliderurls.json' os.chdir(scriptdir) if not args.LocalUrls: log.info("Updating paths ...") try: #filename=get_file(online_urls,urls_json) filename=wget.download(online_urls) if filename !=urls_json: shutil.move(filename,urls_json) except: ## doesn't matter at this point log.warn('Could not update paths') latest_urls={} if not args.LocalUrls and os.path.exists(urls_json): try: with open(urls_json) as json_data: http_paths = json.load(json_data) latest_urls=http_paths except Exception as e: #log.error('Failed to load json file '+file) log.error('Failed to load json file '+urls_json) log.error('Json exception given as ' +str(e)) latest_urls=default_urls else: latest_urls=default_urls os.chdir(cwd) #### Now for the local paths jsonFILE='HEPtoolpaths.json' if os.path.exists(jsonFILE): try: with open(jsonFILE) as json_data: paths_dict = json.load(json_data, object_pairs_hook=collections.OrderedDict) except Exception as e: #log.error('Failed to load json file '+file) log.error('Failed to load json file '+jsonFILE) log.error('Json exception given as ' +str(e)) raise SystemExit else: paths_dict = {} installed_something=False """ if args.All or args.fastjet: try: temp_path=install_fastjet() paths_dict['fastjet']=os.path.join(cwd,temp_path) installed_something=True print("Installed fastjet") except Exception as e: print('Problem installing fastjet: ' +str(e)) """ if args.All or args.madgraph: try: temp_path=install_madgraph() paths_dict['madgraph']=os.path.join(cwd,temp_path) installed_something=True log.info("Installed madgraph") except Exception as e: #print('Problem installing madgraph: ' +str(e)) log.error('Problem installing madgraph: ' +str(e)) # pre_existing=False # try: # tdir,exists=extract_get(latest_urls['madgraph']) # paths_dict['hepmc2']=os.path.join(cwd,tdir) # #if pre_existing: # # return basedir # except Exception as e: # print("Error extracting madgraph: "+str(e)) installed_zlib = False if 'madgraph' in paths_dict: madgraph_zlib_path=os.path.join(paths_dict['madgraph'],'HEPTools','zlib') if os.path.exists(madgraph_zlib_path): installed_zlib = True paths_dict['zlib']=madgraph_zlib_path if args.All or args.zlib: if not installed_zlib: try: log.info('Installing zlib') temp_path,_=install_configure("zlib","zlib","") paths_dict['zlib'] = temp_path installed_something=True installed_zlib=True log.info('Installed zlib') except Exception as e: log.error('Problem installing zlib: ' +str(e)) else: log.info('Madgraph already installed zlib, using that installation') if args.All or args.fastjet: try: temp_path,_=install_configure("fastjet","FJ"," --enable-thread-safety=yes ") paths_dict['fastjet']=temp_path installed_something=True log.info("Installed fastjet") except Exception as e: log.error('Problem installing fastjet: ' +str(e)) if args.All or args.hepmc2: """ This is to install older versions of hepmc, such as the one used in madgraph try: temp_path,_=install_configure('hepmc2','HEPMC2'," --with-momentum=GEV --with-length=MM ") paths_dict['hepmc2']=temp_path installed_something=True print("Installed hepmc2") except Exception as e: print('Problem installing hepmc2: ' +str(e)) """ try: temp_path,_=install_cmake('hepmc','HepMC'," -DHEPMC2_ENABLE_PYTHON=OFF -Dmomentum:STRING=GEV -Dlength:STRING=MM","hepmc2") paths_dict['hepmc2']=temp_path installed_something=True log.info("Installed hepmc2") except Exception as e: log.error('Problem installing hepmc2: ' +str(e)) if args.All or args.lhapdf6: try: ## Previously I disabled python on lhapdf because it relied on python2. I had problems compiling on my machine. #temp_path,_=install_configure('LHAPDF','LHAPDF',' --disable-python','lhapdf6') temp_path,_=install_configure('LHAPDF','LHAPDF','','lhapdf6') paths_dict['lhapdf6']=temp_path installed_something=True log.info("Installed lhapdf6") isok=True except Exception as e: log.error('Problem installing lhapdf6: ' +str(e)) isok=False if isok: log.info('Getting extra sets') #os.chdir(os.path.join(temp_path,'share','LHAPDF')) # try: # tdir,exists=extract_get('http://lhapdfsets.web.cern.ch/lhapdfsets/current/NNPDF23_lo_as_0130_qed.tar.gz') # except Exception as e: # print('Problem downloading set: '+str(e)) to_download=['NNPDF23_lo_as_0130_qed','NNPDF31_lo_as_0118','NNPDF31_nlo_as_0118','NNPDF31_nnlo_as_0118','MMHT2014lo68cl','MMHT2014nlo68cl','MMHT2014nnlo68cl'] for pdfset in to_download: tempurl=latest_urls['pdfsets']+pdfset+'.tar.gz' try: tarball=get_file(tempurl) except Exception as e: log.warn("Failed to download, "+str(e)) continue #os.chdir(os.path.join(temp_path,'share','LHAPDF')) tar = tarfile.open(os.path.join(tarballdir,tarball)) tar.extractall(path=os.path.join(temp_path,'share','LHAPDF')) tar.close() """ try: tdir,exists=extract_get(tempurl) except Exception as e: print('Problem downloading set: '+str(e)) """ os.chdir(cwd) ### Need to do fastjet, lhapdf, hepmc206 before pythia if args.All or args.pythia: ## Need to pick out the options ###--with-fastjet3=/home/tmp/goodsell/Packages/Collider/FJ340 --with-lhapdf6=/home/tmp/goodsell/Packages/Collider/LHAPDF623 --with-hepmc2=/home/tmp/goodsell/Packages/Collider/HepMC206 --with-gzip config_options=' --cxx-common="-std=c++11 -fPIC" --lib-suffix=.so' if installed_zlib: ## madgraph installed it, so it's absent on the system and we need to install it config_options=config_options+' --with-gzip='+paths_dict['zlib'] else: config_options=config_options+' --with-gzip' if 'lhapdf6' in paths_dict: config_options=config_options+' --with-lhapdf6='+paths_dict['lhapdf6'] if 'fastjet' in paths_dict: config_options=config_options+' --with-fastjet3='+paths_dict['fastjet'] if 'hepmc2' in paths_dict: config_options=config_options+' --with-hepmc2='+paths_dict['hepmc2'] try: temp_path=install_pythia(config_options) except Exception as e: print('Problem installing pythia: ' +str(e)) raise SystemExit paths_dict['pythia']=os.path.join(cwd,temp_path) installed_something=True print("Installed pythia") if args.All or args.yoda: try: if installed_zlib: inst_path,base_path=install_configure('YODA','YODA'," --with-zlib="+paths_dict['zlib']) else: inst_path,base_path=install_configure('YODA','YODA',"") paths_dict['YODA']=inst_path paths_dict['YODA source']=base_path installed_something=True log.info("Installed yoda") except Exception as e: log.error('Problem installing yoda: ' +str(e)) if args.rootpath != '': paths_dict['root'] = args.rootpath ## Regenerate configure scripts def get_python_libdir_from_path(trylibpath): import platform mypyver=platform.python_version_tuple() try: temppaths=os.listdir(trylibpath) except: raise mypydirshort='python'+str(mypyver[0])+str(mypyver[1]) pylibdir='' for tp in temppaths: if 'python' in tp: pylibdir = tp ### keeps the last one if pylibdir==mypydirshort: break """ if pylibdir != '': return pylibdir else: raise """ if pylibdir == '': raise dist_or_site=['site-packages','dist-packages'] try: for pdir in dist_or_site: packagedir=os.path.join(trylibpath,pylibdir,pdir) if os.path.exists(packagedir): return packagedir except: raise ### otherwise just return the base path return os.path.join(trylibpath,pylibdir) def get_python_lib_path(basedir): dirs_to_try=[os.path.join(basedir,'lib64'),os.path.join(basedir,'lib'),os.path.join(basedir,'local','lib'),os.path.join(basedir,'local','lib64')] pylibdir='' for trydir in dirs_to_try: try: pydir=get_python_libdir_from_path(trydir) #return os.path.join(trydir,pydir) return pydir break except: pass raise NameError('No python library directory?') if 'root' in paths_dict or 'lhapdf6' in paths_dict or 'YODA' in paths_dict: OFcsh = open('configure_colliders.csh','w') OFsh = open('SETUP_COLLIDERS.sh','w') if 'lhapdf6' in paths_dict: lhapdfbin=os.path.join(paths_dict['lhapdf6'],'bin') OFcsh.write('set path = ('+lhapdfbin+' $path)\n') OFsh.write('export PATH='+lhapdfbin+':$PATH\n') ## use lhapdf-config to get the library: try: out = shell_command(os.path.join(lhapdfbin,'lhapdf-config --libdir'),lhapdfbin) except: out=os.path.join(paths_dict['lhapdf6'],'lib') """ try: command_line = subprocess.Popen(os.path.join(lhapdfbin,'lhapdf-config --libdir'),shell=True, cwd=lhapdfbin,stdout=subprocess.PIPE,stderr=subprocess.PIPE) out, err = command_line.communicate() out=out.decode().strip() except Exception as e: out=os.path.join(paths_dict['lhapdf6'],'lib') """ #OFcsh.write('setenv LD_LIBRARY_PATH '+out.decode().strip()+':$LD_LIBRARY_PATH\n') #OFsh.write('export LD_LIBRARY_PATH='+out.decode().strip()+':$LD_LIBRARY_PATH\n') OFcsh.write('setenv LD_LIBRARY_PATH '+out+':$LD_LIBRARY_PATH\n') OFsh.write('export LD_LIBRARY_PATH='+out+':$LD_LIBRARY_PATH\n') ## get python library directory #temppaths=os.listdir(os.path.join(paths_dict['lhapdf6'],'lib64')) try: pylib = get_python_lib_path(paths_dict['lhapdf6']) OFcsh.write('setenv PYTHONPATH '+pylib+':$PYTHONPATH\n') OFsh.write('export PYTHONPATH='+pylib+':$PYTHONPATH\n') #OFcsh.write('setenv PYTHONPATH '+os.path.join(pylib,'site-packages')+':$PYTHONPATH\n') #OFsh.write('export PYTHONPATH='+os.path.join(pylib,'site-packages')+':$PYTHONPATH\n') except Exception as e: log.warning('No python for lhapdf6: '+str(e)) pass if 'YODA' in paths_dict: yodabin=os.path.join(paths_dict['YODA'],'bin') OFcsh.write('set path = ('+yodabin+' $path)\n') OFsh.write('export PATH='+yodabin+':$PATH\n') out=os.path.join(paths_dict['YODA'],'lib') OFcsh.write('setenv LD_LIBRARY_PATH '+out.strip()+':$LD_LIBRARY_PATH\n') OFsh.write('export LD_LIBRARY_PATH='+out.strip()+':$LD_LIBRARY_PATH\n') ## get python library directory #temppaths=os.listdir(os.path.join(paths_dict['lhapdf6'],'lib64')) try: pylib = get_python_lib_path(paths_dict['YODA']) OFcsh.write('setenv PYTHONPATH '+pylib+':$PYTHONPATH\n') OFsh.write('export PYTHONPATH='+pylib+':$PYTHONPATH\n') #OFcsh.write('setenv PYTHONPATH '+os.path.join(pylib,'site-packages')+':$PYTHONPATH\n') #OFsh.write('export PYTHONPATH='+os.path.join(pylib,'site-packages')+':$PYTHONPATH\n') except: pass if 'root' in paths_dict: OFcsh.write('source '+os.path.join(paths_dict['root'],'bin','thisroot.csh')+'\n') OFsh.write('source '+os.path.join(paths_dict['root'],'bin','thisroot.sh')+'\n') OFcsh.close() HA_pre_existing=False if args.All or args.hackanalysis: try: basedir,HA_pre_existing=extract_get(latest_urls["hackanalysis"]) paths_dict['hackanalysis']=os.path.join(cwd,basedir) except: log.error('HackAnalysis extraction failed') ## set up hackanalysis makefile, do this even if we are not installing hackanalysis if 'hackanalysis' in paths_dict: #MFpath=os.path.join(paths_dict['hackanalysis'],'Makefile') MFpath=os.path.join(paths_dict['hackanalysis'],'Template_Paths.inc') if not os.path.exists(MFpath): MFpath=os.path.join(paths_dict['hackanalysis'],'Paths.inc') if os.path.exists(MFpath): IF=open(MFpath,'r') OF=open(os.path.join(cwd,'HackAnalysis_Paths.inc'),'w') if installed_zlib: OF.write('ZLIBpath='+paths_dict['zlib']+'\n') for line in IF: if line.startswith('#'): OF.write(line) elif line.startswith('hepmcpath=') and 'hepmc2' in paths_dict: OF.write('hepmcpath='+paths_dict['hepmc2']+'\n') elif line.startswith('pythia8path=') and 'pythia' in paths_dict: OF.write('pythia8path='+paths_dict['pythia']+'\n') elif line.startswith('fastjetpath=') and 'fastjet' in paths_dict: OF.write('fastjetpath='+paths_dict['fastjet']+'\n') elif line.startswith('YODApath=') and 'YODA' in paths_dict: OF.write('YODApath='+paths_dict['YODA']+'\n') elif line.startswith('YAMLpath=') and 'YODA' in paths_dict: OF.write('YAMLpath='+os.path.join(paths_dict['YODA source'],'src','yamlcpp')+'\n') else: OF.write(line) IF.close() OF.close() if args.All or args.hackanalysis: if not HA_pre_existing or reinstall: if 'hackanalysis' in paths_dict and os.path.exists('HackAnalysis_Makefile'): hackpath =paths_dict['hackanalysis'] shutil.move('HackAnalysis_Makefile',os.path.join(hackpath,'Makefile')) log.info('Making HackAnalysis in '+hackpath) try: _=shell_command('make',hackpath) except Exception as e: log.error('HackAnalysis installation failed, '+str(e)) """ try: log.info('Making HackAnalysis in '+hackpath) command_line = subprocess.Popen('make', shell=True, cwd=hackpath, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = command_line.communicate() except Exception as e: log.error('HackAnalysis installation failed, '+str(e)) """ if installed_something: with open(jsonFILE, 'w') as fp: json.dump(paths_dict, fp, indent=4) log.info('Installation complete!')