| The Gaudi Framework v29r0 (ff2e7097)

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

- Namespace List
- Namespace Members

Functions | Variables
make_patch Namespace Reference

## Functions
def | command (cmd, args, kwargs)
def | broadcast_packages ()
def | matches (filename, patterns)
def | expand_dirs (files, basepath="")
def | revision_diff_cmd (cwd)
def | diff_pkg (name, cmtdir, exclusions=[])
def | main ()

## Variables
| cmt = lambda*args,**kwargs:apply(command, ("cmt",) + args, kwargs)
| cvs = lambda*args,**kwargs:apply(command, ("cvs",) + args, kwargs)
| 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 28 of file make_patch.py.

28 def broadcast_packages():
29 """
30 Find the local packages the current one depends on (using 'cmt broadcast').
31 Returns a list of pairs ("package name","path to the cmt directory").
32 """
33 # make cmt print one line per package with python syntax
34 if not sys.platform.startswith("win"):
35 pkg_dirs = "[\n" + cmt("broadcast",
36 r'echo "(\"<package>\", \"$PWD\"),"')[0] + ']'
37 else:
38 pkg_dirs = "[\n" + cmt("broadcast",
39 r'echo ("<package>", r"%<package>root%\cmt"),')[0] + ']'
40 # Clean up a bit the output (actually needed only on Windows because of the newlines)
41 pkg_dirs = "\n".join(
42 [l.strip() for l in pkg_dirs.splitlines() if not l.startswith("#")])
43 return eval(pkg_dirs)
44
45
make_patch.cmt
cmt
Definition: make_patch.py:23
make_patch.broadcast_packages
def broadcast_packages()
Definition: make_patch.py:28

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

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

Definition at line 11 of file make_patch.py.

11 def command(cmd, *args, **kwargs):
12 """
13 Simple wrapper to execute a command and return standard output and standard error.
14 """
15 d = {"stdout": PIPE, "stderr": PIPE}
16 d.update(kwargs)
17 cmd = [cmd] + list(args)
18 logging.debug("Execute command: %r %r", " ".join(cmd), kwargs)
19 proc = apply(Popen, (cmd,), d)
20 return proc.communicate()
21
22
make_patch.command
def command(cmd, args, kwargs)
Definition: make_patch.py:11

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

    Return the patch data for a package.

Definition at line 95 of file make_patch.py.

95 def diff_pkg(name, cmtdir, exclusions=[]):
96 """
97 Return the patch data for a package.
98 """
99 rootdir = os.path.dirname(cmtdir)
100 out, err = revision_diff_cmd(cwd=rootdir)
101 # extract new files
102 new_files = [l.split(None, 1)[1]
103 for l in out.splitlines()
104 if l.startswith("? ")]
105 new_files = expand_dirs(new_files, rootdir)
106 new_files = [f
107 for f in new_files
108 if not matches(f, exclusions)]
109 # make diff segments for added files
110 for f in new_files:
111 logging.info("Added file %r", f)
112 #out += "diff -u -p -N %s\n" % os.path.basename(f)
113 # out += command("diff", "-upN", "/dev/null", f,
114 # cwd = rootdir)[0]
115 out += "Index: %s\n" % f
116 out += "===================================================================\n"
117 out += command("diff", "-upN", "/dev/null", f,
118 cwd=rootdir)[0]
119 # extract removed files
120 removed_files = [l.split()[-1]
121 for l in err.splitlines()
122 if "cannot find" in l]
123 removed_files = [f
124 for f in removed_files
125 if not matches(f, exclusions)]
126 # make diff segments for removed files (more tricky)
127 for f in removed_files:
128 logging.info("Removed file %r", f)
129 # retrieve the original content from CVS
130 orig = cvs("up", "-p", f,
131 cwd=rootdir)[0]
132 out += "diff -u -p -N %s\n" % os.path.basename(f)
133 out += "--- %s\t1 Jan 1970 00:00:00 -0000\n" % f
134 out += "+++ /dev/null\t1 Jan 1970 00:00:00 -0000\n"
135 lines = orig.splitlines()
136 out += "@@ -1,%d +0,0 @@\n" % len(lines)
137 for l in lines:
138 out += '-%s\n' % l
139 # Fix the paths to have the package names
140 rex = re.compile(r"^(Index: |\? |\+\+\+ |--- (?!/dev/null))", re.MULTILINE)
141 out = rex.sub(r"\1%s/" % name, out)
142 return out
143
144
make_patch.command
def command(cmd, args, kwargs)
Definition: make_patch.py:11
make_patch.expand_dirs
def expand_dirs(files, basepath="")
Definition: make_patch.py:58
make_patch.revision_diff_cmd
def revision_diff_cmd(cwd)
Definition: make_patch.py:79
make_patch.matches
def matches(filename, patterns)
Definition: make_patch.py:46
make_patch.diff_pkg
def diff_pkg(name, cmtdir, exclusions=[])
Definition: make_patch.py:95
make_patch.cvs
cvs
Definition: make_patch.py:24

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 58 of file make_patch.py.

58 def expand_dirs(files, basepath=""):
59 """
60 Replace the entries in files that correspond to directories with the list of
61 files in those directories.
62 """
63 if basepath:
64 lb = len(basepath) + 1
65 else:
66 lb = 0
67 newlist = []
68 for f in files:
69 base = os.path.join(basepath, f)
70 if os.path.isdir(base):
71 for root, ds, fs in os.walk(base):
72 for ff in fs:
73 newlist.append(os.path.join(root, ff)[lb:])
74 else:
75 newlist.append(f)
76 return newlist
77
78
make_patch.expand_dirs
def expand_dirs(files, basepath="")
Definition: make_patch.py:58

def make_patch.main | ( |  | ) |

Definition at line 145 of file make_patch.py.

145 def main():
146 from optparse import OptionParser
147 parser = OptionParser(description="Produce a patch file from a CMT project. "
148 "The patch contains the changes with respect "
149 "to the CVS repository, including new files "
150 "that are present only locally. Run the script "
151 "from the cmt directory of a package.")
152 parser.add_option("-x", "--exclude", action="append", type="string",
153 metavar="PATTERN", dest="exclusions",
154 help="Pattern to exclude new files from the patch")
155 parser.add_option("-o", "--output", action="store", type="string",
156 help="Name of the file to send the output to. Standard "
157 "output is used if not specified")
158 parser.add_option("-v", "--verbose", action="store_true",
159 help="Print some progress information on standard error")
160 parser.add_option("--debug", action="store_true",
161 help="Print debug information on standard error")
162 parser.set_defaults(exclusions=[])
163
164 opts, args = parser.parse_args()
165
166 if opts.debug:
167 logging.basicConfig(level=logging.DEBUG)
168 elif opts.verbose:
169 logging.basicConfig(level=logging.INFO)
170
171 # default exclusions
172 opts.exclusions += ["*.py[co]",
173 "*.patch",
174 "cmt/cleanup.*",
175 "cmt/setup.*",
176 "cmt/*.make",
177 "cmt/Makefile",
178 "cmt/*.nmake",
179 "cmt/*.nmakesav",
180 "cmt/NMake",
181 "cmt/install*.history",
182 "cmt/build.*.log",
183 "cmt/version.cmt",
184 "genConf",
185 "slc3_ia32_gcc323*",
186 "slc4_ia32_gcc34*",
187 "slc4_amd64_gcc34*",
188 "slc4_amd64_gcc43*",
189 "win32_vc71*",
190 "i686-slc[34567]-[ig]cc*",
191 "i686-slc[34567]-clang*",
192 "x86_64-slc[34567]-[ig]cc*",
193 "x86_64-slc[34567]-clang*",
194 ".eclipse",
195 ]
196 if "CMTCONFIG" in os.environ:
197 opts.exclusions.append(os.environ["CMTCONFIG"])
198
199 # check if we are in the cmt directory before broadcasting
200 if not (os.path.basename(os.getcwd()) == "cmt" and os.path.exists("requirements")):
201 logging.error(
202 "This script must be executed from the cmt directory of a package.")
203 return 1
204
205 pkgs = broadcast_packages()
206 num_pkgs = len(pkgs)
207 count = 0
208
209 patch = ""
210 for name, path in pkgs:
211 count += 1
212 logging.info("Processing %s from %s (%d/%d)",
213 name, os.path.dirname(path), count, num_pkgs)
214 patch += diff_pkg(name, path, opts.exclusions)
215
216 if sys.platform.startswith("win"):
217 # fix newlines chars
218 patch = patch.replace("\r", "")
219
220 if opts.output:
221 logging.info("Writing patch file %r", opts.output)
222 open(opts.output, "w").write(patch)
223 else:
224 sys.stdout.write(patch)
225 return 0
226
227
make_patch.broadcast_packages
def broadcast_packages()
Definition: make_patch.py:28
GaudiPython.GaudiAlgs.write
write
Definition: GaudiAlgs.py:1259
make_patch.diff_pkg
def diff_pkg(name, cmtdir, exclusions=[])
Definition: make_patch.py:95
make_patch.main
def main()
Definition: make_patch.py:145

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 46 of file make_patch.py.

46 def matches(filename, patterns):
47 """
48 Returns True if any of the specified glob patterns (list of strings) matched
49 the string 'filename'.
50 """
51 for p in patterns:
52 if fnmatch(filename, p):
53 logging.debug("Excluding file: %r", filename)
54 return True
55 return False
56
57
make_patch.matches
def matches(filename, patterns)
Definition: make_patch.py:46

def make_patch.revision_diff_cmd | ( |  | cwd | ) |

Definition at line 79 of file make_patch.py.

79 def revision_diff_cmd(cwd):
80 if os.path.isdir(os.path.join(cwd, "CVS")):
81 return cvs("diff", "-upN", cwd=cwd)
82 else:
83 # special treatment to show new files in a way compatible with CVS
84 out, err = svn("status", cwd=cwd)
85
86 newfiles = [l
87 for l in out.splitlines()
88 if l.startswith("? ")]
89 out, err = svn("diff", cwd=cwd)
90 if newfiles:
91 out = "\n".join(newfiles) + "\n" + out
92 return out, err
93
94
make_patch.svn
svn
Definition: make_patch.py:25
make_patch.revision_diff_cmd
def revision_diff_cmd(cwd)
Definition: make_patch.py:79
make_patch.cvs
cvs
Definition: make_patch.py:24

## Variable Documentation

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

Definition at line 23 of file make_patch.py.

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

Definition at line 24 of file make_patch.py.

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

Definition at line 25 of file make_patch.py.