示例#1
0
文件: ppk-pack.py 项目: dnikulin/ppk
    if unit in FACTORS:
        size = int(request[:-1]) * FACTORS[unit]
    else:
        count = int(request)

    out = ""
    total = 0

    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

    for head, body in ppk.readRaw():
        out += head
        out += body
        total += 1

        if (((count > 0) and (total >= count)) or
            ((size > 0)  and (len(out) >= size))):

            release()

    release()
示例#2
0
文件: ppk-map.py 项目: dnikulin/ppk
#   Many fixes have been tried, none have worked

import ppk

import os
import sys

from subprocess import Popen, PIPE

if __name__ == '__main__':
    if len(sys.argv) < 2:
        ppk.printUsage("<program> [arguments ...]")

    args = sys.argv[1:]

    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()
示例#3
0
文件: ppk-unzip.py 项目: dnikulin/ppk
#!/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) != 1:
        ppk.printUsage()

    for _, zbody in ppk.readRaw():
        body = zlib.decompress(zbody)

        ilen = len(zbody)
        olen = len(body)
        pcent = ppk.percent(olen, ilen)

        ppk.report("%d -> %d (%d%%)" % (ilen, olen, pcent))

        ppk.writeRaw(body)