19from urllib.request
import Request, urlopen
28argcomplete - Bash tab completion for argparse
29Documentation https://kislyuk.github.io/argcomplete/
31pip install argcomplete
32sudo activate-global-python-argcomplete
33Only Works On Local not in O2
34Activate libraries in below and activate #argcomplete.autocomplete(parser) line
42 "User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36"
45parser = argparse.ArgumentParser(description =
"Arguments to pass")
47 "--version", help =
"Online: Your Production tag for O2Physics example: for nightly-20220619, just enter as 20220619", action =
"store",
51 "--debug", help =
"Online and Local: execute with debug options", action =
"store",
52 choices = [
"NOTSET",
"DEBUG",
"INFO",
"WARNING",
"ERROR",
"CRITICAL"], default =
"DEBUG", type = str.upper,
56 help =
"Local: Use Local Paths for getting DQ Libraries instead of online github download. If you are working LXPLUS, It will not working so don't configure with option",
57 action =
"store_true",
61 help =
"Local: Configure your alice software folder name in your local home path (prefix: home/<user>). Default is home/<user>/alice. Example different configuration is --localpath alice-software --local --> home/<user>/alice-software",
62 action =
"store", type = str
65argcomplete.autocomplete(parser)
66extrargs = parser.parse_args()
68MY_PATH = os.path.abspath(os.getcwd())
69HOME_PATH = os.environ[
"HOME"]
71ALICE_SOFTWARE_PATH = os.environ[
"HOME"] +
"/alice"
73localPathCutsLibrary = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/CutsLibrary.h"
74localPathMCSignalsLibrary = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/MCSignalLibrary.h"
75localPathEventMixing = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/MixingLibrary.h"
77URL_CUTS_LIBRARY = (
"https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/CutsLibrary.h?raw=true")
78URL_MCSIGNALS_LIBRARY = (
"https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/MCSignalLibrary.h?raw=true")
79URL_MIXING_LIBRARY = (
"https://github.com/AliceO2Group/O2Physics/blob/master/PWGDQ/Core/MixingLibrary.h?raw=true")
83if extrargs.version
is not None:
84 prefix_version =
"nightly-"
85 extrargs.version = prefix_version + extrargs.version
88 DEBUG_SELECTION = extrargs.debug
89 numeric_level = getattr(logging, DEBUG_SELECTION.upper(),
None)
90 if not isinstance(numeric_level, int):
91 raise ValueError(
"Invalid log level: %s" % DEBUG_SELECTION)
92 logging.basicConfig(format =
"[%(levelname)s] %(message)s", level = DEBUG_SELECTION)
94if extrargs.version
and extrargs.local
is False:
95 logging.info(
"DQ libs will downloaded from github. Your Version For Downloading DQ Libs From Github : %s", extrargs.version,)
97 URL_CUTS_LIBRARY = (
"https://github.com/AliceO2Group/O2Physics/blob/" + extrargs.version +
"/PWGDQ/Core/CutsLibrary.h?raw=true")
98 URL_MCSIGNALS_LIBRARY = (
99 "https://github.com/AliceO2Group/O2Physics/blob/" + extrargs.version +
"/PWGDQ/Core/MCSignalLibrary.h?raw=true"
101 URL_MIXING_LIBRARY = (
"https://github.com/AliceO2Group/O2Physics/blob/" + extrargs.version +
"/PWGDQ/Core/MixingLibrary.h?raw=true")
103if extrargs.local
and extrargs.version:
105 "Your provided configuration for getting DQ libs in locally. You don't need to configure your github nightly version. It's for Online Downloading"
107 logging.warning(
"%s nightly version will not used in interface. Local working on going", extrargs.version)
109if extrargs.localPath
and extrargs.local:
110 ALICE_SOFTWARE_PATH = os.environ[
"HOME"] +
"/" + extrargs.localPath
111 logging.info(
"Alice software Local Path is Changed. New Local Path is %s", ALICE_SOFTWARE_PATH)
112 if os.path.isdir(ALICE_SOFTWARE_PATH)
is True:
113 logging.info(
"Alice software found at %s local Path change is true", ALICE_SOFTWARE_PATH)
115 logging.error(
"Alice software not found in path!!! Fatal Error. Check your Alice software path configuration")
118if extrargs.localPath
and extrargs.local
is False:
120 "Misconfiguration. You forget to add --local option interface for working localy. You need add this parameter to workflow"
122 logging.info(
"Example usage: python3 DownloadLibs.py --local --localPath alice")
126 if extrargs.localPath
is None:
127 logging.info(
"Default Path will used for Alice Software. Default Path : %s", ALICE_SOFTWARE_PATH)
128 if os.path.isdir(ALICE_SOFTWARE_PATH)
is True:
129 logging.info(
"Default Path: %s is Valid", ALICE_SOFTWARE_PATH)
130 elif os.path.isdir(ALICE_SOFTWARE_PATH)
is False:
131 logging.error(
"Default Path: %s is invalid!! Fatal Error. Check your Alice software path configuration", ALICE_SOFTWARE_PATH,)
134 logging.info(
"DQ libs will be getting from local folders. You alice software path : %s", ALICE_SOFTWARE_PATH,)
136 localPathCutsLibrary = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/CutsLibrary.h"
137 localPathMCSignalsLibrary = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/MCSignalLibrary.h"
138 localPathEventMixing = ALICE_SOFTWARE_PATH +
"/O2Physics/PWGDQ/Core/MixingLibrary.h"
140 logging.info(
"Local CutsLibrary.h Path: %s ", localPathCutsLibrary)
141 logging.info(
"Local MCSignalsLibrary.h Path: %s ", localPathMCSignalsLibrary)
142 logging.info(
"Local MixingLibrary.h Path: %s ", localPathEventMixing)
144 with open(
"tempCutsLibrary.h",
"wb")
as f:
145 shutil.copyfile(localPathCutsLibrary, MY_PATH +
"/tempCutsLibrary.h")
146 if os.path.isfile(
"tempCutsLibrary.h")
is True:
147 logging.info(
"tempCutsLibrary.h created at %s", MY_PATH)
149 logging.error(
"tempCutsLibrary.h not created at %s Fatal Error", MY_PATH)
151 except FileNotFoundError:
152 logging.error(
"%s not found in your provided alice-software path!!! Check your alice software path", localPathCutsLibrary,)
156 with open(
"tempMCSignalsLibrary.h",
"wb")
as f:
157 shutil.copyfile(localPathMCSignalsLibrary, MY_PATH +
"/tempMCSignalsLibrary.h")
158 if os.path.isfile(
"tempMCSignalsLibrary.h")
is True:
159 logging.info(
"tempMCSignalsLibrary.h created at %s", MY_PATH)
161 logging.error(
"tempMCSignalsLibrary.h not created at %s Fatal Error", MY_PATH)
163 except FileNotFoundError:
164 logging.error(
"%s not found in your provided alice-software path!!! Check your alice software path", localPathMCSignalsLibrary,)
168 with open(
"tempMixingLibrary.h",
"wb")
as f:
169 shutil.copyfile(localPathEventMixing, MY_PATH +
"/tempMixingLibrary.h")
170 if os.path.isfile(
"tempMixingLibrary.h")
is True:
171 logging.info(
"tempMixingLibrary.h created at %s", MY_PATH)
173 logging.error(
"tempMixingLibrary.h not created at %s Fatal Error", MY_PATH)
175 except FileNotFoundError:
176 logging.error(
"%s not found in your provided alice-software path!!! Check your alice software path", localPathEventMixing,)
179 logging.info(
"DQ Libraries pulled from local alice software successfully!")
182if extrargs.local
is False:
184 (os.path.isfile(
"tempCutsLibrary.h")
is False)
or (os.path.isfile(
"tempMCSignalsLibrary.h")
is False)
or
185 (os.path.isfile(
"tempMixingLibrary.h"))
is False
187 logging.info(
"Some Libs are Missing. All DQ libs will download")
188 logging.info(
"Github CutsLibrary.h Path: %s ", URL_CUTS_LIBRARY)
189 logging.info(
"Github MCSignalsLibrary.h Path: %s ", URL_MCSIGNALS_LIBRARY)
190 logging.info(
"Github MixingLibrary.h Path: %s ", URL_MIXING_LIBRARY)
194 context = ssl._create_unverified_context()
195 request = urllib.request.urlopen(URL_CUTS_LIBRARY, context = context)
196 request = urllib.request.urlopen(URL_MCSIGNALS_LIBRARY, context = context)
197 request = urllib.request.urlopen(URL_MIXING_LIBRARY, context = context)
198 except urllib.error.HTTPError
as error:
202 context = ssl._create_unverified_context()
203 request = urllib.request.urlopen(URL_CUTS_LIBRARY, context = context)
206 requestCutsLibrary = Request(URL_CUTS_LIBRARY, headers = headers)
207 requestMCSignalsLibrary = Request(URL_MCSIGNALS_LIBRARY, headers = headers)
208 requestMixingLibrary = Request(URL_MIXING_LIBRARY, headers = headers)
211 htmlCutsLibrary = urlopen(requestCutsLibrary, context = context).read()
212 htmlMCSignalsLibrary = urlopen(requestMCSignalsLibrary, context = context).read()
213 htmlMixingLibrary = urlopen(requestMixingLibrary, context = context).read()
215 with open(
"tempCutsLibrary.h",
"wb")
as f:
216 f.write(htmlCutsLibrary)
217 logging.info(
"tempCutsLibrary.h downloaded successfully from github")
218 with open(
"tempMCSignalsLibrary.h",
"wb")
as f:
219 f.write(htmlMCSignalsLibrary)
220 logging.info(
"tempMCSignalsLibrary.h downloaded successfully from github")
221 with open(
"tempMixingLibrary.h",
"wb")
as f:
222 f.write(htmlMixingLibrary)
223 logging.info(
"tempMixingLibrary.h downloaded successfully from github")
226 logging.info(
"DQ Libraries have been downloaded before. If you want to update, delete they manually and run this script again.")
229 logging.info(
"DQ Libraries downloaded from github successfully!")