| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

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.

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

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

Definition at line 155 of file validate_patch.py.

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

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

Definition at line 152 of file validate_patch.py.

    00153                :
    00154     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.

    00145                          :
    00146     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.

    00108                            :
    00109     file_id = int(file_id)
    00110     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.

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

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

Definition at line 83 of file validate_patch.py.

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

def validate_patch::main | ( | ) |

Definition at line 193 of file validate_patch.py.

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

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

Definition at line 166 of file validate_patch.py.

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

## Variable Documentation

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

Definition at line 10 of file validate_patch.py.

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines