[Open Office] cwsextract, rdiff
David Fraser
davidf at sjsoft.com
Tue Mar 7 13:31:20 EST 2006
Caolan McNamara wrote:
> FWIW I reckon cwsextract can be implemented with cvs rdiff,
>
> cvs rdiff works out of the box with anoncvs, and while it doesn't with
> the tunnel,
> cvs -d:username at localhost:2401/shared/data/helm/cvs/repository rdiff
> does work. Should be a speed win there for getting workspaces.
>
I wrote a little Python script that parses the lists of files from EIS,
then uses cvs diff on only the files listed as having changed in the
cws. Might be even faster but haven't used it for a while.
The idea again was to work where the cwsextract tool wouldn't because of
permissions etc
By default it will run and extract all the current cws into patch files
for fun and extra load on the servers :-)
Attached in case anyone is interested
David
-------------- next part --------------
#!/usr/bin/env python
import eis
class TestEIS:
def setup_class(cls):
cls.eis = eis.EIS()
def testcwsid(self):
assert self.eis.getcwsid("hr26") == 3367
def testcwsmodules(self):
assert sorted(self.eis.getcwsmodules("os67")) == ["officecfg", "svtools", "sw"]
def testcwsfiles(self):
os67files = sorted(self.eis.getcwsfiles("os67"))
assert ('officecfg', 'registry/data/org/openoffice/Office/Writer.xcu') in os67files
assert ('sw', 'source/ui/dbui/mmmergepage.src') in os67files
assert len(os67files) == 37
-------------- next part --------------
#!/usr/bin/env python
import urllib2
import cookielib
import os
import BeautifulSoup
import cgi
import sys
class EIS:
def __init__(self, cookiefile="eis.lwp"):
self.cookiefile = cookiefile
self.cookiejar = cookielib.LWPCookieJar()
if os.path.isfile(self.cookiefile):
self.cookiejar.load(self.cookiefile)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
urllib2.install_opener(opener)
self.login()
self.cache = {}
def login(self):
urllib2.urlopen("http://eis.services.openoffice.org/EIS2/GuestLogon").read()
self.cookiejar.save(self.cookiefile)
def cacheurl(self, url):
if url in self.cache:
return self.cache[url]
else:
try:
contents = urllib2.urlopen(url).read()
except urllib2.HTTPError, e:
if e.code == 401:
self.login()
contents = urllib2.urlopen(url).read()
else:
raise
self.cache[url] = contents
return contents
def findcws(self, mws=None, milestone=None, cws=None, cwsid=None):
"""lists all cws available, as mws, milestone, cws, cwsid"""
milestoneindex = self.cacheurl("http://eis.services.openoffice.org/EIS2/servlet/cws.CWSExplorer?Mode=Milestones")
cwslist = []
for line in milestoneindex.replace("\r", "").split("\n"):
# cws.ShowCWS?Path=SRC680%2Fm54%2Fdba15&Id=1431
startmark, endmark = '"/EIS2/cws.ShowCWS?', '"'
if line.startswith("theMenu.addChild") and startmark in line:
cwsargs = line[line.find(startmark) + len(startmark):]
cwsargs = cwsargs[:cwsargs.find(endmark)]
cwsargs = cgi.parse_qs(cwsargs)
cwspath = cwsargs["Path"][0]
thismws, thismilestone, thiscws = cwspath.split("/", 3)
thiscwsid = int(cwsargs["Id"][0])
if (mws is None or mws == thismws) and \
(milestone is None or milestone == thismilestone) and \
(cws is None or cws == thiscws) and \
(cwsid is None or cwsid == thiscwsid):
cwslist.append((thismws, thismilestone, thiscws, thiscwsid))
return cwslist
def getcwsid(self, cwsname):
for mws, milestone, somecws, somecwsid in self.findcws(cws=cwsname):
return somecwsid
raise ValueError("no id found for cws %s" % cwsname)
milestoneindex = self.cacheurl("http://eis.services.openoffice.org/EIS2/servlet/cws.CWSExplorer?Mode=Milestones")
for line in milestoneindex.replace("\r", "").split("\n"):
if line.startswith("theMenu.addChild"):
if line.find('"%s"' % cwsname) != -1:
cwsid = line[line.find("&Id=")+4:]
for i, c in enumerate(cwsid):
if not c.isdigit():
if not cwsid[:i]:
raise ValueError("invalid cwsid %s for cws %s" % (cwsid, cwsname))
return int(cwsid[:i])
return cwsid
def getcwsinfo(self, cwsname):
cwsid = self.getcwsid(cwsname)
return self.cacheurl("http://eis.services.openoffice.org/EIS2/cws.ShowCWS?Id=%d" % cwsid)
def getcwsmodules(self, cwsname):
cwsinfo = self.getcwsinfo(cwsname)
infosoup = BeautifulSoup.BeautifulSoup(cwsinfo)
titlesoup = infosoup.first("h4").findNext("h4", {}, "Modules & Files").parent
modulesoup = titlesoup.findNext("table")
modules = []
for tr in modulesoup("tr"):
module = tr.first("td").first("font").string
if module and module not in modules:
modules.append(module)
return modules
def getcwsfiles(self, cwsname):
cwsinfo = self.getcwsinfo(cwsname)
infosoup = BeautifulSoup.BeautifulSoup(cwsinfo)
titlesoup = infosoup.first("h4").findNext("h4", {}, "Modules & Files").parent
modulesoup = titlesoup.findNext("table")
files = []
for tr in modulesoup("tr"):
module = tr.first("td").first("font").string
if module:
filename = tr.first("td").findNext("td").first("font").string.strip()
if filename:
files.append((module, filename))
return files
def getcwspatch(self, srcdir, cwsname):
cwsmodules = self.getcwsmodules(cwsname)
cwsfiles = self.getcwsfiles(cwsname)
patches = []
for module, filename in cwsfiles:
moduledir = os.path.join(srcdir, module)
cwsanchor = "CWS_SRC680_%s_ANCHOR" % cwsname.upper()
cwsbranch = "cws_src680_%s" % cwsname
cvsresult = None
if "/" in filename:
dirname = filename[:filename.rfind("/")]
osdirname = os.path.join(*dirname.split("/"))
if not os.path.exists(os.path.join(srcdir, module, osdirname)):
print >> sys.stderr, "warning: directory %s does not exist" % dirname
parentdirname = os.path.dirname(osdirname)
actualbranch = "HEAD"
parenttagfile = os.path.join(srcdir, module, parentdirname, "CVS", "Tag")
if os.path.exists(parenttagfile):
actualbranch = open(parenttagfile).read()[1:].strip()
checkoutdir = os.path.basename(osdirname)
try:
cvscmd = "cd %s ; (cd %s ; cvs up -d -r %s %s) ; cvs diff -uN -r %s -r %s %s" % (moduledir, parentdirname, cwsbranch, checkoutdir, cwsanchor, cwsbranch, filename)
cvsresult = os.popen(cvscmd).read()
finally:
os.system("cd %s ; (cd %s ; cvs up -P -r %s %s) ; rm -fr %s" % (moduledir, parentdirname, actualbranch, checkoutdir, osdirname))
cvscmd = "cd %s ; cvs diff -uN -r %s -r %s %s" % (moduledir, cwsanchor, cwsbranch, filename)
if cvsresult is None:
cvsresult = os.popen(cvscmd).read()
cvsresult = cvsresult.replace("Index: %s" % filename, "Index: %s/%s" % (module, filename))
cvsresult = cvsresult.replace("--- %s" % filename, "--- %s/%s" % (module, filename))
cvsresult = cvsresult.replace("+++ %s" % filename, "+++ %s/%s" % (module, filename))
patches.append(cvsresult)
return "".join(patches)
if __name__ == "__main__":
eis = EIS()
srcdir = "/share/openoffice/ximian/linux-build-HEAD/build/"
for cws in sys.argv[1:]:
# print cws + " : " + " ".join(eis.getcwsmodules(cws))
sys.stdout.write(eis.getcwspatch(os.path.join(srcdir, "src680-m151"), cws))
if not sys.argv[1:]:
for mws, milestone, cws, cwsid in eis.findcws(mws="SRC680"):
print "extracting patch for %s %s %s" % (mws, milestone, cws)
cwspatch = eis.getcwspatch(os.path.join(srcdir, "src680-m151"), cws)
cwsfile = open(os.path.join("patches", "%s-%s-%s.diff" % (mws, milestone, cws)), "w")
cwsfile.write(cwspatch)
cwsfile.close()
More information about the Openoffice
mailing list