def test_updater(env): targetdir = os.path.join(env.workdir, "target_updater") targetversion = env.VERSIONS[-1] for v in env.VERSIONS[:-1]: shutil.copytree(os.path.join(env.workdir, v), targetdir) manifestPath = os.path.join(env.workdir, "test-%s-%s-delta-from-%s-manifest.xml.bz2" % (targetversion, env.PLATFORM, v)) print "trying %s" % manifestPath um = Update.parse(BZ2File(manifestPath).read()) cmd = ["../build/src/updater", "--install-dir=%s" % targetdir, "--package-dir=%s" % env.workdir, "--auto-close", "--script=%s" % manifestPath] print "running: %s" % (" ".join(cmd)) res = subprocess.call(cmd) assert res == 0 for f in um.manifest: fpath = os.path.join(targetdir, f.name) assert os.path.exists(fpath) assert env.get_sha1(fpath) == f.fileHash fmap = um.get_filemap() for root, dirs, files in os.walk(targetdir): for f in files: fname = os.path.join(root, f) fname = fname.replace(targetdir + "/", "") assert fname in fmap shutil.rmtree(targetdir)
def test_patch_delta(env): # first make a copy of the version we want to patch targetdir = os.path.join(env.workdir, "target") patchdir = os.path.join(env.workdir, "patches") shutil.copytree(os.path.join(env.workdir, "v1.0"), targetdir) os.makedirs(patchdir) zf = zipfile.ZipFile(env.get_deltaZipPaths()[0]) zf.extractall(patchdir) zf.close() deltamanifest = Update.parse( BZ2File(env.get_deltaManifestPaths()[0], "r").read()) for p in deltamanifest.patches: cmd = [ "../build/external/bsdiff/bspatch-endsley", os.path.join(targetdir, p.name), os.path.join(targetdir, p.name + ".new"), os.path.join(patchdir, p.patchName) ] print cmd res = subprocess.call(cmd) assert res == 0 assert file(os.path.join( targetdir, p.name + ".new")).read() == "This file changes with versions v3.0" shutil.rmtree(targetdir) shutil.rmtree(patchdir)
def verify_directory(manifestPath, directory): u = None try: u = Update.parse(file(manifestPath).read()) except: print "Failed to parse manifest: " + manifestPath return False if not os.path.isdir(directory): print "%s is not a directory" % directory return False filemap = u.get_filemap() for root, dirs, files in os.walk(directory): for f in files: fullpath = os.path.join(root, f) fpath = fullpath.replace(directory + "/", "") if not fpath in filemap: print "Could not find file %s in manifest" % fpath return False ufe = filemap[fpath] fe = hashutils.get_file((fullpath, directory + "/")) if not fe == ufe: print "Could not match %s to the manifest: %s" % (fpath, ",".join(fe.whyneq(ufe))) return False return True
def __init__(self, manifestPath): self.manifestPath = manifestPath self.updateElement = Update.parse(bz2.BZ2File(manifestPath).read()) rootdir = os.path.dirname(self.manifestPath) basename = os.path.basename(self.manifestPath) basename = basename.replace("-manifest.xml.bz2", "-full.zip") self.zipfilePath = os.path.join(rootdir, basename) print "zipfilePath = %s" % self.zipfilePath
def test_parse_manifest(env): for manifest in env.get_manifestPaths(): u = Update.parse(BZ2File(manifest, "r").read()) assert u.platform == env.PLATFORM for f in u.manifest: filePath = os.path.join(os.path.dirname(manifest), u.targetVersion, f.name) assert os.path.exists(filePath) # compare sha sum. assert env.get_sha1(filePath) == f.fileHash
def test_check_zipfiles(env): for manifest in env.get_manifestPaths(): u = Update.parse(BZ2File(manifest, "r").read()) zfile = os.path.join(env.workdir, u.packages[0].name) assert u.packages[0].fileHash == env.get_sha1(zfile) filemap = u.get_filemap() zf = zipfile.ZipFile(zfile) for fp in zf.namelist(): assert fp in filemap fe = filemap[fp] data = zf.read(fp) s = sha1() s.update(data) assert fe.fileHash == s.hexdigest()
def test_delta_manifest_parse(env): for dm in env.get_deltaManifestPaths(): u = Update.parse(BZ2File(dm).read())