| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Namespace List
- Namespace Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions | Variables
validate_patch Namespace Reference

## Classes
class | PatchData
class | SavannahParser
| parse the More...
class | TempDir

## Functions
def | get_patch_info_x
def | get_patch_info
def | get_patch_data
def | check_out_gaudi
def | apply_patch
def | check
def | build
def | test
def | main

## Variables
string | __author__ "Marco Clemencic <marco.clemencic@cern.ch>"

## Function Documentation

def validate_patch.apply_patch | ( |  | patch_data,
|  |  | path
| ) |  |

Definition at line 147 of file validate_patch.py.

147
148 def apply_patch(patch_data, path):
149 proc = Popen(["patch", "-p0", "--batch"], cwd = path, stdin = PIPE)
150 proc.communicate(patch_data)
151 return proc.returncode

def validate_patch.build | ( |  | path | ) |

Definition at line 155 of file validate_patch.py.

155
156 def build(path):
157 if "LBCONFIGURATIONROOT" in os.environ:
158 cmd = ["make",
159 "-f", os.path.join(os.environ["LBCONFIGURATIONROOT"], "data", "Makefile")]
160 if "use-distcc" in os.environ.get("CMTEXTRATAGS",""):
161 cmd += ["-j", "6"]
162 else:
163 cmd = ["cmt", "-pack=GaudiRelease", "broadcast", "cmt", "make", "all_groups"]
164 return Popen(" ".join(cmd),
165 shell = True,
cwd = path).wait()

def validate_patch.check | ( |  | path | ) |

Definition at line 152 of file validate_patch.py.

152
153 def check(path):
154 return Popen(" ".join(["cmt", "show", "projects"]), shell = True, cwd = path).wait()

def validate_patch.check_out_gaudi | ( |  | path | ) |

Definition at line 144 of file validate_patch.py.

144
145 def check_out_gaudi(path):
146 return Popen(["svn", "co", "http://svnweb.cern.ch/guest/gaudi/Gaudi/trunk", os.path.join(path, "Gaudi")]).wait()

def validate_patch.get_patch_data | ( |  | file_id | ) |

Definition at line 107 of file validate_patch.py.

107
108 def get_patch_data(file_id):
109 file_id = int(file_id)
110 return urlopen("https://savannah.cern.ch/patch/download.php?file_id=%d" % file_id).read()

def validate_patch.get_patch_info | ( |  | patch | ) |

Definition at line 100 of file validate_patch.py.

100
101 def get_patch_info(patch):
102 patch = int(patch)
103 parser = SavannahParser()
104 parser.feed(urlopen("https://savannah.cern.ch/patch/?%d" % patch).read())
105 parser.close()
106 return parser.patch

def validate_patch.get_patch_info_x | ( |  | patch | ) |

Definition at line 83 of file validate_patch.py.

83
84 def get_patch_info_x(patch):
85 patch = int(patch)
86 server = "savannah.cern.ch"
87 path = "/patch/?%d" % patch
88 conn = httplib.HTTPSConnection(server)
89 conn.request("GET", path)
90 r = conn.getresponse()
91 if r.status == 200:
92 pass
93 else:
94 raise RuntimeError(r.status, r.reason, "https://" + server + path)
95 parser = SavannahParser()
96 parser.feed(r.read())
97 parser.close()
98 conn.close()
99 return parser.patch

def validate_patch.main | ( |  | ) |

Definition at line 193 of file validate_patch.py.

193
194 def main():
195 logging.basicConfig()
196 if len(sys.argv) != 2:
197 print """Usage:
198 validate_patch.py <savannah patch id>
199 validate_patch.py file.patch
200 """
201 return 2
202 patch_id = sys.argv[1]
203 if os.path.isfile(patch_id):
204 patch_data = open(patch_id, "rb").read()
205 else:
206 patch = get_patch_info(patch_id)
207 patch_file_id = patch.files[0][1]
208 patch_data = get_patch_data(patch_file_id)
209
210 td = TempDir(prefix = patch_id + "-")
211 if check_out_gaudi(str(td)) != 0:
212 print "Sorry, problems checking out Gaudi. Try again."
213 return 0
214 top_dir = os.path.join(str(td), "Gaudi")
215 open(os.path.join(top_dir, patch_id) ,"wb").write(patch_data)
216
217 revision = -1
218 for l in Popen(["svn", "info", top_dir], stdout = PIPE).communicate()[0].splitlines():
219 if l.startswith("Revision:"):
220 revision = int(l.split()[-1])
221 break
222
223 actions = [(lambda path: apply_patch(patch_data, path), "application of the patch"),
224 (check, "check of the configuration"),
225 (build, "build"),
226 (test, "test"),
227 ]
228 failure = False
229 for action, title in actions:
230 if action(top_dir) != 0:
231 failure = title
232 break
233
234 if failure:
235 print "*** Patch %s failed during %s (using revision r%d) ***" % (patch_id, failure, revision)
236 return 1
237
238 print "*** Patch %s succeeded (using revision r%d) ***" % (patch_id, revision)
239 return 0

def validate_patch.test | ( |  | path | ) |

Definition at line 166 of file validate_patch.py.

166
167 def test(path):
168 cmd = ["cmt", "-pack=GaudiRelease", "TestProject"]
169 proc = Popen(" ".join(cmd),
170 stdout = PIPE,
171 shell = True,
172 cwd = path)
173 output = []
174 while proc.poll() is None:
175 chunk = proc.stdout.read(256)
176 output.append(chunk)
177 sys.stdout.write(chunk)
178 sys.stdout.flush()
179 chunk = proc.stdout.read(256)
180 output.append(chunk)
181 sys.stdout.write(chunk)
182 sys.stdout.flush()
183 if proc.returncode:
184 # immediately return in case of failure
185 return proc.returncode
186 # look for failures in the output
187 output = ("".join(output)).splitlines()
188 for l in output:
189 l = l.strip()
190 if ": FAIL" in l or ": ERROR" in l:
191 return 1
192 return 0

## Variable Documentation

string validate_patch.__author__ "Marco Clemencic <marco.clemencic@cern.ch>"

Definition at line 10 of file validate_patch.py.