| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

Functions | Variables

# make_patch Namespace Reference

## Functions
def | command
def | broadcast_packages
def | matches
def | expand_dirs
def | revision_diff_cmd
def | diff_pkg
def | main
## Variables
tuple | cmt = lambda*args,**kwargs:apply(command, ("cmt",) + args, kwargs)
tuple | cvs = lambda*args,**kwargs:apply(command, ("cvs",) + args, kwargs)
tuple | svn = lambda*args,**kwargs:apply(command, ("svn",) + args, kwargs)

## Function Documentation

def make_patch::broadcast_packages | ( | ) |

    Find the local packages the current one depends on (using 'cmt broadcast').
    Returns a list of pairs ("package name","path to the cmt directory").

Definition at line 23 of file make_patch.py.

    00024                         :
    00025     """
    00026     Find the local packages the current one depends on (using 'cmt broadcast').
    00027     Returns a list of pairs ("package name","path to the cmt directory").
    00028     """
    00029     # make cmt print one line per package with python syntax
    00030     if not sys.platform.startswith("win"):
    00031         pkg_dirs = "[\n" + cmt("broadcast",r'echo "(\"<package>\", \"$PWD\"),"')[0] + ']'
    00032     else:
    00033         pkg_dirs = "[\n" + cmt("broadcast",r'echo ("<package>", r"%<package>root%\cmt"),')[0] + ']'
    00034     # Clean up a bit the output (actually needed only on Windows because of the newlines)
    00035     pkg_dirs = "\n".join([l.strip() for l in pkg_dirs.splitlines() if not l.startswith("#")])
    00036     return eval(pkg_dirs)

def make_patch::command | ( |  | cmd,
|  |  | args,
|  |  | kwargs
| ) |  |

    Simple wrapper to execute a command and return standard output and standard error.

Definition at line 8 of file make_patch.py.

    00009                                  :
    00010     """
    00011     Simple wrapper to execute a command and return standard output and standard error.
    00012     """
    00013     d = {"stdout": PIPE, "stderr": PIPE}
    00014     d.update(kwargs)
    00015     cmd = [cmd] + list(args)
    00016     logging.debug("Execute command: %r %r", " ".join(cmd), kwargs)
    00017     proc = apply(Popen, (cmd,), d)
    00018     return proc.communicate()

def make_patch::diff_pkg | ( |  | name,
|  |  | cmtdir,
|  |  | exclusions = `[]`
| ) |  |

    Return the patch data for a package.

Definition at line 83 of file make_patch.py.

    00084                                            :
    00085     """
    00086     Return the patch data for a package.
    00087     """
    00088     rootdir = os.path.dirname(cmtdir)
    00089     out, err = revision_diff_cmd(cwd = rootdir)
    00090     # extract new files
    00091     new_files = [ l.split(None,1)[1]
    00092                   for l in out.splitlines()
    00093                   if l.startswith("? ") ]
    00094     new_files = expand_dirs(new_files, rootdir)
    00095     new_files = [ f
    00096                   for f in new_files
    00097                   if not matches(f, exclusions) ]
    00098     # make diff segments for added files
    00099     for f in new_files:
    00100         logging.info("Added file %r", f)
    00101         #out += "diff -u -p -N %s\n" % os.path.basename(f)
    00102         #out += command("diff", "-upN", "/dev/null", f,
    00103         #               cwd = rootdir)[0]
    00104         out += "Index: %s\n" % f
    00105         out += "===================================================================\n"
    00106         out += command("diff", "-upN", "/dev/null", f,
    00107                        cwd = rootdir)[0]
    00108     # extract removed files
    00109     removed_files = [ l.split()[-1]
    00110                       for l in err.splitlines()
    00111                       if "cannot find" in l ]
    00112     removed_files = [ f
    00113                       for f in removed_files
    00114                       if not matches(f, exclusions) ]
    00115     # make diff segments for removed files (more tricky)
    00116     for f in removed_files:
    00117         logging.info("Removed file %r", f)
    00118         # retrieve the original content from CVS
    00119         orig = cvs("up", "-p", f,
    00120                    cwd = rootdir)[0]
    00121         out += "diff -u -p -N %s\n" % os.path.basename(f)
    00122         out += "--- %s\t1 Jan 1970 00:00:00 -0000\n" % f
    00123         out += "+++ /dev/null\t1 Jan 1970 00:00:00 -0000\n"
    00124         lines = orig.splitlines()
    00125         out += "@@ -1,%d +0,0 @@\n" % len(lines)
    00126         for l in lines:
    00127             out += '-%s\n' % l
    00128     # Fix the paths to have the package names
    00129     rex = re.compile(r"^(Index: |\? |\+\+\+ |--- (?!/dev/null))", re.MULTILINE)
    00130     out = rex.sub(r"\1%s/" % name, out)
    00131     return out

def make_patch::expand_dirs | ( |  | files,
|  |  | basepath = `""`
| ) |  |

    Replace the entries in files that correspond to directories with the list of
    files in those directories.

Definition at line 48 of file make_patch.py.

    00049                                      :
    00050     """
    00051     Replace the entries in files that correspond to directories with the list of
    00052     files in those directories.
    00053     """
    00054     if basepath:
    00055         lb = len(basepath)+1
    00056     else:
    00057         lb = 0
    00058     newlist = []
    00059     for f in files:
    00060         base = os.path.join(basepath, f)
    00061         if os.path.isdir(base):
    00062             for root, ds, fs in os.walk(base):
    00063                 for ff in fs:
    00064                     newlist.append(os.path.join(root,ff)[lb:])
    00065         else:
    00066             newlist.append(f)
    00067     return newlist

def make_patch::main | ( | ) |

Definition at line 132 of file make_patch.py.

    00133           :
    00134     from optparse import OptionParser
    00135     parser = OptionParser(description = "Produce a patch file from a CMT project. "
    00136                                         "The patch contains the changes with respect "
    00137                                         "to the CVS repository, including new files "
    00138                                         "that are present only locally. Run the script "
    00139                                         "from the cmt directory of a package." )
    00140     parser.add_option("-x", "--exclude", action="append", type="string",
    00141                       metavar="PATTERN", dest="exclusions",
    00142                       help="Pattern to exclude new files from the patch")
    00143     parser.add_option("-o", "--output", action="store", type="string",
    00144                       help="Name of the file to send the output to. Standard "
    00145                            "output is used if not specified")
    00146     parser.add_option("-v", "--verbose", action="store_true",
    00147                       help="Print some progress information on standard error")
    00148     parser.add_option("--debug", action="store_true",
    00149                       help="Print debug information on standard error")
    00150     parser.set_defaults(exclusions = [])
    00151
    00152     opts, args = parser.parse_args()
    00153
    00154     if opts.debug:
    00155         logging.basicConfig(level = logging.DEBUG)
    00156     elif opts.verbose:
    00157         logging.basicConfig(level = logging.INFO)
    00158
    00159     # default exclusions
    00160     opts.exclusions += [ "*.py[co]",
    00161                          "*.patch",
    00162                          "cmt/cleanup.*",
    00163                          "cmt/setup.*",
    00164                          "cmt/*.make",
    00165                          "cmt/Makefile",
    00166                          "cmt/*.nmake",
    00167                          "cmt/*.nmakesav",
    00168                          "cmt/NMake",
    00169                          "cmt/install*.history",
    00170                          "cmt/build.*.log",
    00171                          "cmt/version.cmt",
    00172                          "genConf",
    00173                          "slc3_ia32_gcc323*",
    00174                          "slc4_ia32_gcc34*",
    00175                          "slc4_amd64_gcc34*",
    00176                          "slc4_amd64_gcc43*",
    00177                          "win32_vc71*",
    00178                          "i686-slc3-gcc323*",
    00179                          "i686-slc4-gcc34*",
    00180                          "i686-slc4-gcc41*",
    00181                          "x86_64-slc4-gcc34*",
    00182                          "x86_64-slc4-gcc41*",
    00183                          "i686-slc5-gcc43*",
    00184                          "x86_64-slc5-gcc43*",
    00185                          "x86_64-slc5-icc*",
    00186                          ]
    00187     if "CMTCONFIG" in os.environ:
    00188         opts.exclusions.append(os.environ["CMTCONFIG"])
    00189
    00190     # check if we are in the cmt directory before broadcasting
    00191     if not (os.path.basename(os.getcwd()) == "cmt" and os.path.exists("requirements")):
    00192         logging.error("This script must be executed from the cmt directory of a package.")
    00193         return 1
    00194
    00195     pkgs = broadcast_packages()
    00196     num_pkgs = len(pkgs)
    00197     count = 0
    00198
    00199     patch = ""
    00200     for name, path in pkgs:
    00201         count += 1
    00202         logging.info("Processing %s from %s (%d/%d)",
    00203                      name, os.path.dirname(path), count, num_pkgs)
    00204         patch += diff_pkg(name, path, opts.exclusions)
    00205
    00206     if sys.platform.startswith("win"):
    00207         # fix newlines chars
    00208         patch = patch.replace("\r","")
    00209
    00210     if opts.output:
    00211         logging.info("Writing patch file %r", opts.output)
    00212         open(opts.output,"w").write(patch)
    00213     else:
    00214         sys.stdout.write(patch)
    00215     return 0

def make_patch::matches | ( |  | filename,
|  |  | patterns
| ) |  |

    Returns True if any of the specified glob patterns (list of strings) matched
    the string 'filename'.

Definition at line 37 of file make_patch.py.

    00038                                :
    00039     """
    00040     Returns True if any of the specified glob patterns (list of strings) matched
    00041     the string 'filename'.
    00042     """
    00043     for p in patterns:
    00044         if fnmatch(filename, p):
    00045             logging.debug("Excluding file: %r", filename)
    00046             return True
    00047     return False

def make_patch::revision_diff_cmd | ( |  | cwd ) |

Definition at line 68 of file make_patch.py.

    00069                           :
    00070     if os.path.isdir(os.path.join(cwd, "CVS")):
    00071         return cvs("diff", "-upN", cwd = cwd)
    00072     else:
    00073         # special treatment to show new files in a way compatible with CVS
    00074         out, err = svn("status", cwd = cwd)
    00075
    00076         newfiles = [ l
    00077                      for l in out.splitlines()
    00078                      if l.startswith("? ") ]
    00079         out, err = svn("diff", cwd = cwd)
    00080         if newfiles:
    00081             out = "\n".join(newfiles) + "\n" + out
    00082         return out, err

## Variable Documentation

tuple make_patch::cmt = lambda*args,**kwargs:apply(command, ("cmt",) + args, kwargs)

Definition at line 19 of file make_patch.py.

tuple make_patch::cvs = lambda*args,**kwargs:apply(command, ("cvs",) + args, kwargs)

Definition at line 20 of file make_patch.py.

tuple make_patch::svn = lambda*args,**kwargs:apply(command, ("svn",) + args, kwargs)

Definition at line 21 of file make_patch.py.

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