Bug 784841 - Part 14: Use 4-space indent on Python scripts in dom/imptests; rs=Ms2ger

This commit is contained in:
Gregory Szorc 2013-02-21 10:56:48 -08:00
parent 3086699a36
commit 143cbedb5b
4 changed files with 155 additions and 155 deletions

View File

@ -23,136 +23,136 @@ import writeMakefile
HEADERS_SUFFIX = "^headers^"
def parseManifestFile(dest, dir):
subdirs, mochitests, _, __, supportfiles = parseManifest.parseManifestFile("hg-%s/%s/MANIFEST" % (dest, dir))
return subdirs, mochitests, supportfiles
subdirs, mochitests, _, __, supportfiles = parseManifest.parseManifestFile("hg-%s/%s/MANIFEST" % (dest, dir))
return subdirs, mochitests, supportfiles
def getData(confFile):
"""This function parses a file of the form
URL of remote repository|Name of the destination directory
First directory of tests
...
Last directory of tests"""
repo = ""
dest = ""
directories = []
try:
fp = open(confFile, "r")
first = True
for line in fp:
if first:
idx = line.index("|")
repo = line[:idx].strip()
dest = line[idx + 1:].strip()
first = False
else:
directories.append(line.strip())
finally:
fp.close()
return repo, dest, directories
"""This function parses a file of the form
URL of remote repository|Name of the destination directory
First directory of tests
...
Last directory of tests"""
repo = ""
dest = ""
directories = []
try:
fp = open(confFile, "r")
first = True
for line in fp:
if first:
idx = line.index("|")
repo = line[:idx].strip()
dest = line[idx + 1:].strip()
first = False
else:
directories.append(line.strip())
finally:
fp.close()
return repo, dest, directories
def makePath(a, b):
if not b:
# Empty directory, i.e., the repository root.
return a
return "%s/%s" % (a, b)
if not b:
# Empty directory, i.e., the repository root.
return a
return "%s/%s" % (a, b)
def copyTest(source, dest):
"""Copy the file at source to dest, as well as any ^headers^ file associated
with it."""
shutil.copy(source, dest)
if os.path.exists(source + HEADERS_SUFFIX):
shutil.copy(source + HEADERS_SUFFIX, dest + HEADERS_SUFFIX)
"""Copy the file at source to dest, as well as any ^headers^ file associated
with it."""
shutil.copy(source, dest)
if os.path.exists(source + HEADERS_SUFFIX):
shutil.copy(source + HEADERS_SUFFIX, dest + HEADERS_SUFFIX)
def copy(thissrcdir, dest, directories):
"""Copy mochitests and support files from the external HG directory to their
place in mozilla-central.
"""
print("Copying %s..." % directories)
for d in directories:
subdirs, mochitests, supportfiles = parseManifestFile(dest, d)
sourcedir = makePath("hg-%s" % dest, d)
destdir = makePath(dest, d)
os.makedirs(destdir)
"""Copy mochitests and support files from the external HG directory to their
place in mozilla-central.
"""
print("Copying %s..." % directories)
for d in directories:
subdirs, mochitests, supportfiles = parseManifestFile(dest, d)
sourcedir = makePath("hg-%s" % dest, d)
destdir = makePath(dest, d)
os.makedirs(destdir)
for mochitest in mochitests:
copyTest("%s/%s" % (sourcedir, mochitest), "%s/test_%s" % (destdir, mochitest))
for support in supportfiles:
copyTest("%s/%s" % (sourcedir, support), "%s/%s" % (destdir, support))
for mochitest in mochitests:
copyTest("%s/%s" % (sourcedir, mochitest), "%s/test_%s" % (destdir, mochitest))
for support in supportfiles:
copyTest("%s/%s" % (sourcedir, support), "%s/%s" % (destdir, support))
if len(subdirs):
if d:
importDirs(thissrcdir, dest, ["%s/%s" % (d, subdir) for subdir in subdirs])
else:
# Empty directory, i.e., the repository root
importDirs(thissrcdir, dest, subdirs)
if len(subdirs):
if d:
importDirs(thissrcdir, dest, ["%s/%s" % (d, subdir) for subdir in subdirs])
else:
# Empty directory, i.e., the repository root
importDirs(thissrcdir, dest, subdirs)
def printMakefile(dest, directories):
"""Create a .mk file to be included into the main Makefile.in, which lists the
directories with tests.
"""
print("Creating .mk...")
path = dest + ".mk"
fp = open(path, "w")
fp.write("DIRS += \\\n")
fp.write(writeMakefile.makefileString([makePath(dest, d) for d in directories]))
fp.write("\n")
fp.close()
subprocess.check_call(["hg", "add", path])
"""Create a .mk file to be included into the main Makefile.in, which lists the
directories with tests.
"""
print("Creating .mk...")
path = dest + ".mk"
fp = open(path, "w")
fp.write("DIRS += \\\n")
fp.write(writeMakefile.makefileString([makePath(dest, d) for d in directories]))
fp.write("\n")
fp.close()
subprocess.check_call(["hg", "add", path])
def printMakefiles(thissrcdir, dest, directories):
"""Create Makefile.in files for each directory that contains tests we import.
"""
print("Creating Makefile.ins...")
for d in directories:
path = makePath(dest, d)
print("Creating Makefile.in in %s..." % path)
"""Create Makefile.in files for each directory that contains tests we import.
"""
print("Creating Makefile.ins...")
for d in directories:
path = makePath(dest, d)
print("Creating Makefile.in in %s..." % path)
subdirs, mochitests, supportfiles = parseManifestFile(dest, d)
subdirs, mochitests, supportfiles = parseManifestFile(dest, d)
files = ["test_%s" % (mochitest, ) for mochitest in mochitests]
files.extend(supportfiles)
files.extend(f for f in os.listdir(path) if f.endswith(HEADERS_SUFFIX))
files = ["test_%s" % (mochitest, ) for mochitest in mochitests]
files.extend(supportfiles)
files.extend(f for f in os.listdir(path) if f.endswith(HEADERS_SUFFIX))
result = writeMakefile.substMakefile("importTestsuite.py", subdirs, files)
result = writeMakefile.substMakefile("importTestsuite.py", subdirs, files)
fp = open(path + "/Makefile.in", "w")
fp.write(result)
fp.close()
fp = open(path + "/Makefile.in", "w")
fp.write(result)
fp.close()
def hgadd(dest, directories):
"""Inform hg of the files in |directories|."""
print("hg addremoving...")
for d in directories:
subprocess.check_call(["hg", "addremove", "%s/%s" % (dest, d)])
"""Inform hg of the files in |directories|."""
print("hg addremoving...")
for d in directories:
subprocess.check_call(["hg", "addremove", "%s/%s" % (dest, d)])
def importDirs(thissrcdir, dest, directories):
copy(thissrcdir, dest, directories)
printMakefiles(thissrcdir, dest, directories)
copy(thissrcdir, dest, directories)
printMakefiles(thissrcdir, dest, directories)
def importRepo(confFile, thissrcdir):
try:
repo, dest, directories = getData(confFile)
hgdest = "hg-%s" % (dest, )
print("Going to clone %s to %s..." % (repo, hgdest))
print("Removing %s..." % dest)
subprocess.check_call(["rm", "--recursive", "--force", dest])
print("Removing %s..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
print("Cloning %s to %s..." % (repo, hgdest))
subprocess.check_call(["hg", "clone", repo, hgdest])
print("Going to import %s..." % directories)
importDirs(thissrcdir, dest, directories)
printMakefile(dest, directories)
hgadd(dest, directories)
print("Removing %s again..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
except subprocess.CalledProcessError as e:
print(e.returncode)
finally:
print("Done")
try:
repo, dest, directories = getData(confFile)
hgdest = "hg-%s" % (dest, )
print("Going to clone %s to %s..." % (repo, hgdest))
print("Removing %s..." % dest)
subprocess.check_call(["rm", "--recursive", "--force", dest])
print("Removing %s..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
print("Cloning %s to %s..." % (repo, hgdest))
subprocess.check_call(["hg", "clone", repo, hgdest])
print("Going to import %s..." % directories)
importDirs(thissrcdir, dest, directories)
printMakefile(dest, directories)
hgadd(dest, directories)
print("Removing %s again..." % hgdest)
subprocess.check_call(["rm", "--recursive", "--force", hgdest])
except subprocess.CalledProcessError as e:
print(e.returncode)
finally:
print("Done")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Need one argument.")
else:
importRepo(sys.argv[1], "dom/imptests")
if len(sys.argv) != 2:
print("Need one argument.")
else:
importRepo(sys.argv[1], "dom/imptests")

View File

@ -19,46 +19,46 @@
# SOFTWARE.
def parseManifest(fd):
def parseReftestLine(chunks):
assert len(chunks) % 2 == 0
def parseReftestLine(chunks):
assert len(chunks) % 2 == 0
reftests = []
for i in range(2, len(chunks), 2):
if not chunks[i] in ["==", "!="]:
raise Exception("Misformatted reftest line " + line)
reftests.append([chunks[i], chunks[1], chunks[i + 1]])
return reftests
dirs = []
autotests = []
reftests = []
for i in range(2, len(chunks), 2):
if not chunks[i] in ["==", "!="]:
raise Exception("Misformatted reftest line " + line)
reftests.append([chunks[i], chunks[1], chunks[i + 1]])
return reftests
othertests = []
supportfiles = []
for fullline in fd:
line = fullline.strip()
if not line:
continue
dirs = []
autotests = []
reftests = []
othertests = []
supportfiles = []
for fullline in fd:
line = fullline.strip()
if not line:
continue
chunks = line.split(" ")
chunks = line.split(" ")
if chunks[0] == "MANIFEST":
raise Exception("MANIFEST listed on line " + line)
if chunks[0] == "MANIFEST":
raise Exception("MANIFEST listed on line " + line)
if chunks[0] == "dir" or (chunks[0] == "support" and chunks[1] == "dir"):
dirs.append(chunks[1]);
elif chunks[0] == "ref":
if len(chunks) % 2:
raise Exception("Missing chunk in line " + line)
reftests.extend(parseReftestLine(chunks))
elif chunks[0] == "support":
supportfiles.append(chunks[1])
elif chunks[0] in ["manual", "parser"]:
othertests.append(chunks[1])
else: # automated
autotests.append(chunks[0])
return dirs, autotests, reftests, othertests, supportfiles
if chunks[0] == "dir" or (chunks[0] == "support" and chunks[1] == "dir"):
dirs.append(chunks[1]);
elif chunks[0] == "ref":
if len(chunks) % 2:
raise Exception("Missing chunk in line " + line)
reftests.extend(parseReftestLine(chunks))
elif chunks[0] == "support":
supportfiles.append(chunks[1])
elif chunks[0] in ["manual", "parser"]:
othertests.append(chunks[1])
else: # automated
autotests.append(chunks[0])
return dirs, autotests, reftests, othertests, supportfiles
def parseManifestFile(path):
fp = open(path)
dirs, autotests, reftests, othertests, supportfiles = parseManifest(fp)
fp.close()
return dirs, autotests, reftests, othertests, supportfiles
fp = open(path)
dirs, autotests, reftests, othertests, supportfiles = parseManifest(fp)
fp.close()
return dirs, autotests, reftests, othertests, supportfiles

View File

@ -13,6 +13,6 @@ files = ["testharness.js", "testharness.css", "idlharness.js", "WebIDLParser.js"
subprocess.check_call(["hg", "clone", repo, dest])
for f in files:
subprocess.check_call(["cp", "%s/%s" % (dest, f), f])
subprocess.check_call(["hg", "add", f])
subprocess.check_call(["cp", "%s/%s" % (dest, f), f])
subprocess.check_call(["hg", "add", f])
subprocess.check_call(["rm", "--recursive", "--force", dest])

View File

@ -25,16 +25,16 @@ include $$(topsrcdir)/config/rules.mk
"""
def makefileString(entries):
if not len(entries):
return " $(NULL)"
return "\n".join([" %s \\" % (entry, ) for entry in entries]) + "\n $(NULL)"
if not len(entries):
return " $(NULL)"
return "\n".join([" %s \\" % (entry, ) for entry in entries]) + "\n $(NULL)"
def assignList(variable, entries):
return "%s := \\\n%s" % (variable, makefileString(entries))
return "%s := \\\n%s" % (variable, makefileString(entries))
def substMakefile(caller, subdirs, files):
return string.Template(makefileTemplate).substitute({
"caller": caller,
"dirs": assignList("DIRS", subdirs),
"files": assignList("MOCHITEST_FILES", files) if files else ""
})
return string.Template(makefileTemplate).substitute({
"caller": caller,
"dirs": assignList("DIRS", subdirs),
"files": assignList("MOCHITEST_FILES", files) if files else ""
})