| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# 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.

    00147                                  :
    00148     proc = Popen(["patch", "-p0", "--batch"], cwd = path, stdin = PIPE)
    00149     proc.communicate(patch_data)
    00150     return proc.returncode
    00151
    def check(path):

def validate_patch::build | ( |  | path | ) |

Definition at line 155 of file validate_patch.py.

    00155                :
    00156     if "LBCONFIGURATIONROOT" in os.environ:
    00157         cmd = ["make",
    00158                "-f", os.path.join(os.environ["LBCONFIGURATIONROOT"], "data", "Makefile")]
    00159         if "use-distcc" in os.environ.get("CMTEXTRATAGS",""):
    00160                cmd += ["-j", "6"]
    00161     else:
    00162         cmd = ["cmt", "-pack=GaudiRelease", "broadcast", "cmt", "make", "all_groups"]
    00163     return Popen(" ".join(cmd),
    00164                  shell = True,
    00165                  cwd = path).wait()
    def test(path):

def validate_patch::check | ( |  | path | ) |

Definition at line 152 of file validate_patch.py.

    00152                :
    00153     return Popen(" ".join(["cmt", "show", "projects"]), shell = True, cwd = path).wait()
    00154
    def build(path):

def validate_patch::check_out_gaudi | ( |  | path | ) |

Definition at line 144 of file validate_patch.py.

    00144                          :
    00145     return Popen(["svn", "co", "http://svnweb.cern.ch/guest/gaudi/Gaudi/trunk", os.path.join(path, "Gaudi")]).wait()
    00146
    def apply_patch(patch_data, path):

def validate_patch::get_patch_data | ( |  | file_id | ) |

Definition at line 107 of file validate_patch.py.

    00107                            :
    00108     file_id = int(file_id)
    00109     return urlopen("https://savannah.cern.ch/patch/download.php?file_id=%d" % file_id).read()
    00110
    class TempDir(object):

def validate_patch::get_patch_info | ( |  | patch | ) |

Definition at line 100 of file validate_patch.py.

    00100                          :
    00101     patch = int(patch)
    00102     parser = SavannahParser()
    00103     parser.feed(urlopen("https://savannah.cern.ch/patch/?%d" % patch).read())
    00104     parser.close()
    00105     return parser.patch
    00106
    def get_patch_data(file_id):

def validate_patch::get_patch_info_x | ( |  | patch | ) |

Definition at line 83 of file validate_patch.py.

    00083                            :
    00084     patch = int(patch)
    00085     server = "savannah.cern.ch"
    00086     path =  "/patch/?%d" % patch
    00087     conn = httplib.HTTPSConnection(server)
    00088     conn.request("GET", path)
    00089     r = conn.getresponse()
    00090     if r.status == 200:
    00091         pass
    00092     else:
    00093         raise RuntimeError(r.status, r.reason, "https://" + server + path)
    00094     parser = SavannahParser()
    00095     parser.feed(r.read())
    00096     parser.close()
    00097     conn.close()
    00098     return parser.patch
    00099
    def get_patch_info(patch):

def validate_patch::main | ( |  | ) |

Definition at line 193 of file validate_patch.py.

    00193           :
    00194     logging.basicConfig()
    00195     if len(sys.argv) != 2:
    00196         print """Usage:
    00197    validate_patch.py <savannah patch id>
    00198    validate_patch.py file.patch
    00199 """
    00200         return 2
    00201     patch_id = sys.argv[1]
    00202     if os.path.isfile(patch_id):
    00203         patch_data = open(patch_id, "rb").read()
    00204     else:
    00205         patch = get_patch_info(patch_id)
    00206         patch_file_id = patch.files[0][1]
    00207         patch_data = get_patch_data(patch_file_id)
    00208
    00209     td = TempDir(prefix = patch_id + "-")
    00210     if check_out_gaudi(str(td)) != 0:
    00211         print "Sorry, problems checking out Gaudi. Try again."
    00212         return 0
    00213     top_dir = os.path.join(str(td), "Gaudi")
    00214     open(os.path.join(top_dir, patch_id) ,"wb").write(patch_data)
    00215
    00216     revision = -1
    00217     for l in Popen(["svn", "info", top_dir], stdout = PIPE).communicate()[0].splitlines():
    00218         if l.startswith("Revision:"):
    00219             revision = int(l.split()[-1])
    00220             break
    00221
    00222     actions = [(lambda path: apply_patch(patch_data, path), "application of the patch"),
    00223                (check, "check of the configuration"),
    00224                (build, "build"),
    00225                (test, "test"),
    00226                ]
    00227     failure = False
    00228     for action, title in actions:
    00229         if action(top_dir) != 0:
    00230             failure = title
    00231             break
    00232
    00233     if failure:
    00234         print "*** Patch %s failed during %s (using revision r%d) ***" % (patch_id, failure, revision)
    00235         return 1
    00236
    00237     print "*** Patch %s succeeded (using revision r%d) ***" % (patch_id, revision)
    00238     return 0
    00239
    if __name__ == "__main__":

def validate_patch::test | ( |  | path | ) |

Definition at line 166 of file validate_patch.py.

    00166               :
    00167     cmd = ["cmt", "-pack=GaudiRelease", "TestProject"]
    00168     proc = Popen(" ".join(cmd),
    00169                  stdout = PIPE,
    00170                  shell = True,
    00171                  cwd = path)
    00172     output = []
    00173     while proc.poll() is None:
    00174         chunk = proc.stdout.read(256)
    00175         output.append(chunk)
    00176         sys.stdout.write(chunk)
    00177         sys.stdout.flush()
    00178     chunk = proc.stdout.read(256)
    00179     output.append(chunk)
    00180     sys.stdout.write(chunk)
    00181     sys.stdout.flush()
    00182     if proc.returncode:
    00183         # immediately return in case of failure
    00184         return proc.returncode
    00185     # look for failures in the output
    00186     output = ("".join(output)).splitlines()
    00187     for l in output:
    00188         l = l.strip()
    00189         if ": FAIL" in l or ": ERROR" in l:
    00190             return 1
    00191     return 0
    00192
    def main():

## Variable Documentation

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

Definition at line 10 of file validate_patch.py.