Exemple #1
0
# Part of the PPK project

# Known bugs:
# * Termination does not propagate from broken pipe
#   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
Exemple #2
0
#!/usr/bin/env python

# Copyright (c) 2009 Dmitri Nikulin
# See LICENSE-MIT.txt for details
# Part of the PPK project

import ppk

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)))
Exemple #3
0
#!/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__':
    if len(sys.argv) != 2:
        ppk.printUsage("<count | size<k|m|g> >")

    K = 1024
    FACTORS = {'k': K, 'm': K*K, 'g': K*K*K}

    request = sys.argv[1]
    unit = request[-1]

    count = 0
    size = 0

    if unit in FACTORS:
        size = int(request[:-1]) * FACTORS[unit]
    else:
        count = int(request)

    out = ""
    total = 0
Exemple #4
0
#!/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())
Exemple #5
0
#!/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)
Exemple #6
0
#!/usr/bin/env python

# Copyright (c) 2009 Dmitri Nikulin
# See LICENSE-MIT.txt for details
# Part of the PPK project

import ppk

import os
import sys

if __name__ == '__main__':
    if len(sys.argv) != 2:
        ppk.printUsage("<directory>")

    for head, body in ppk.readRaw():
        hash = ppk.hashBodyHex(body)

        path = os.path.join(sys.argv[1], hash)

        try:
            with open(path, 'wb') as fd:
                fd.write(body)

            sys.stdout.write(head)
            sys.stdout.write(body)

            ppk.report("wrote %s (%lu bytes)" % (hash, len(body)))
        except ex:
            ppk.report("could not write %s: %s" % (hash, str(ex)))
Exemple #7
0
#!/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__':
    if len(sys.argv) != 1:
        ppk.printUsage()

    for _, body in ppk.readRaw():
        ppk.writeSizedRaw(body)