def release(): global out global total if total > 0: ppk.report("packed %d objects into %d bytes" % (total, len(out))) ppk.writeRaw(out) out = "" total = 0
import os import sys if __name__ == '__main__': if len(sys.argv) < 2: ppk.printUsage("<directory> [hashes ...]") sys.stdin.close() root = sys.argv[1] for hash in sys.argv[2:]: path = os.path.join(root, hash) body = "" try: with open(path, 'rb') as fd: body = fd.read() nhash = ppk.hashBodyHex(body) if hash == nhash: ppk.report("read %s (%lu bytes)" % (hash, len(body))) ppk.writeRaw(body) else: ppk.report("read %s but hashed as %s (%lu bytes)" % (hash, nhash, len(body))) except IOError, er: ppk.report(str(er))
for _, ibody in ppk.readRaw(): pipe = Popen(args, stdin = PIPE, stdout = PIPE, shell = False) try: with pipe.stdin as opipe: with pipe.stdout as ipipe: pid = os.fork() if pid == 0: # spawnee (read pipe, write stdout) try: # Don't pipe.wait() on exit pipe = None opipe.close() obody = ipipe.read() ipipe.close() ppk.writeRaw(obody) finally: sys.exit(0) else: # spawner (read stdin, write pipe) try: ipipe.close() opipe.write(ibody) opipe.close() finally: os.waitpid(pid, 0) finally: if pipe is not None: pipe.wait()
#!/usr/bin/env python # Copyright (c) 2009 Dmitri Nikulin # See LICENSE-MIT.txt for details # Part of the PPK project import ppk import sys if __name__ == '__main__': sys.stdin.close() if len(sys.argv) < 2: ppk.printUsage("<file0> [... fileN]") for path in sys.argv[1:]: with open(path, 'rt') as fd: for line in fd: ppk.writeRaw(line.rstrip())
#!/usr/bin/env python # Copyright (c) 2009 Dmitri Nikulin # See LICENSE-MIT.txt for details # Part of the PPK project import ppk import sys import zlib if __name__ == '__main__': if len(sys.argv) > 2: ppk.printUsage("[level = 9]") level = 9 if len(sys.argv) > 1: level = int(sys.argv[1]) for _, body in ppk.readRaw(): zbody = zlib.compress(body, level) ilen = len(body) olen = len(zbody) pcent = ppk.percent(olen, ilen) ppk.report("%d -> %d (%d%%)" % (ilen, olen, pcent)) ppk.writeRaw(zbody)