Ejemplo n.º 1
0
 def sendPacketBody(self, body):
     try:
         if self.enableWrite:
             head = HEAD_STRUCT.pack(len(body))
             self.transport.write(head)
             self.transport.write(body)
     except Exception, er:
         ppk.report("sendPacketBody: %s" % str(er))
Ejemplo n.º 2
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
Ejemplo n.º 3
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))
Ejemplo n.º 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
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)
Ejemplo n.º 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 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)))
Ejemplo n.º 6
0
 def sendPacket(self, headbody):
     try:
         if self.enableWrite:
             self.transport.write(headbody)
     except Exception, er:
         ppk.report("sendPacket: %s" % str(er))