11 from __future__
import print_function
12 from future
import standard_library
13 standard_library.install_aliases()
15 from urllib.parse
import urlparse
16 from FetchMTTTool
import *
17 from distutils.spawn
import find_executable
37 FetchMTTTool.__init__(self)
43 self.
options[
'module'] = (
None,
"Modules (or lmod modules) to be loaded for accessing this package")
44 self.
options[
'url'] = (
None,
"URL to access the repository")
45 self.
options[
'username'] = (
None,
"Username required for accessing the repository")
46 self.
options[
'password'] = (
None,
"Password required for that user to access the repository")
47 self.
options[
'pwfile'] = (
None,
"File where password can be found")
48 self.
options[
'branch'] = (
None,
"Branch (if not master) to be downloaded")
49 self.
options[
'pr'] = (
None,
"Pull request to be downloaded")
50 self.
options[
'subdir'] = (
None,
"Subdirectory of interest in repository")
56 IPlugin.activate(self)
60 IPlugin.deactivate(self)
67 lines = testDef.printOptions(self.
options)
73 testDef.logger.verbose_print(
"Git Execute")
76 testDef.parseOptions(log, self.
options, keyvals, cmds)
79 if cmds[
'url']
is not None:
83 log[
'stderr'] =
"No repository URL was provided"
85 testDef.logger.verbose_print(
"Working repo " + url)
86 username = cmds[
'username']
90 if cmds[
'password']
is not None:
91 password = cmds[
'password']
94 if cmds[
'pwfile']
is not None:
95 if os.path.exists(cmds[
'pwfile']):
96 f = open(cmds[
'pwfile'],
'r')
97 password = f.readline().strip()
101 log[
'stderr'] =
"Password file " + cmds[
'pwfile'] +
" does not exist"
108 if cmds[
'pwfile']
is not None:
109 if os.path.exists(cmds[
'pwfile']):
110 f = open(cmds[
'pwfile'],
'r')
111 password = f.readline().strip()
115 log[
'stderr'] =
"Password file " + cmds[
'pwfile'] +
" does not exist"
121 if password
is not None:
124 log[
'stderr'] =
"Password without username"
127 (leader,tail) = url.split(
"//", 1)
129 url = leader +
"//" + username +
":" + password +
"@" + tail
130 elif username
is not None:
132 (leader,tail) = url.split(
"//", 1)
134 url = leader +
"//" + username +
"@" + tail
135 testDef.logger.verbose_print(
"Working final repo " + url)
138 repo = os.path.basename(urlparse(url).path)
141 if self.
done[repo]
is not None:
142 log[
'status'] = self.
done[repo][0]
143 log[
'location'] = self.
done[repo][1]
151 if cmds[
'modules']
is not None:
152 status,stdout,stderr = testDef.modcmd.loadModules(cmds[
'modules'], testDef)
154 log[
'status'] = status
155 log[
'stderr'] = stderr
161 if not find_executable(
"git"):
163 log[
'stderr'] =
"Executable git not found"
166 status,stdout,stderr = testDef.modcmd.unloadModules(cmds[
'modules'], testDef)
168 log[
'status'] = status
169 log[
'stderr'] = stderr
175 if cmds[
'branch']
is not None:
176 branch = cmds[
'branch']
182 if cmds[
'pr']
is not None:
187 for rep
in self.
done:
190 log[
'status'] = rep[1]
192 log[
'stderr'] =
"Prior attempt to clone or update repo {0} failed".format(repo)
195 status,stdout,stderr = testDef.modcmd.unloadModules(cmds[
'modules'], testDef)
197 log[
'status'] = status
198 log[
'stderr'] = stderr
204 dst = os.path.join(testDef.options[
'scratchdir'], log[
'section'].replace(
":",
"_"))
206 if not os.path.exists(dst): os.mkdir(dst)
209 log[
'stderr'] =
"Unable to create " + dst
215 if os.path.exists(repo):
216 if not os.path.isdir(repo):
218 log[
'stderr'] =
"Cannot update or clone repository {0} as a file of that name already exists".format(repo)
220 self.done.append((repo, 1))
223 status,stdout,stderr = testDef.modcmd.unloadModules(keyvals[
'modules'], testDef)
225 log[
'status'] = status
226 log[
'stderr'] = stderr
239 status, stdout, stderr, _ = testDef.execmd.execute(cmds, [
"git",
"pull"], testDef)
242 if branch
is not None:
243 status, stdout, stderr, _ = testDef.execmd.execute(cmds, [
"git",
"clone",
"-b", branch, url], testDef)
245 status, stdout, stderr, _ = testDef.execmd.execute(cmds, [
"git",
"clone", url], testDef)
249 log[
'status'] = status
250 log[
'stdout'] = stdout
251 log[
'stderr'] = stderr
254 log[
'location'] = os.getcwd()
257 cmdlog =
'Fetch CMD: ' +
' '.join(cmds)
258 testDef.logger.verbose_print(cmdlog)
260 if cmds[
'subdir']
is not None:
261 log[
'location'] = os.path.join(log[
'location'], cmds[
'subdir'])
265 self.
done[repo] = (status, log[
'location'])
268 status,stdout,stderr = testDef.modcmd.unloadModules(cmds[
'modules'], testDef)
270 log[
'status'] = status
271 log[
'stderr'] = stderr