コード例 #1
0
ファイル: test_init.py プロジェクト: chutz/snakeoil
 def test_get_handler(self):
     self.assertRaises(KeyError, chksum.get_handler, "x")
     self.assertEqual(self._inited_count, 1)
     chksum.chksum_types["x"] = 1
     self.assertRaises(KeyError, chksum.get_handler, "y")
     chksum.chksum_types["y"] = 2
     self.assertEqual(1, chksum.get_handler("x"))
     self.assertEqual(2, chksum.get_handler("y"))
     self.assertEqual(self._inited_count, 1)
コード例 #2
0
 def test_get_handler(self):
     self.assertRaises(KeyError, chksum.get_handler, "x")
     self.assertEqual(self._inited_count, 1)
     chksum.chksum_types["x"] = 1
     self.assertRaises(KeyError, chksum.get_handler, "y")
     chksum.chksum_types["y"] = 2
     self.assertEqual(1, chksum.get_handler("x"))
     self.assertEqual(2, chksum.get_handler("y"))
     self.assertEqual(self._inited_count, 1)
コード例 #3
0
 def get_chf(self):
     try:
         self.chf = chksum.get_handler(self.chf_type)
     except KeyError:
         raise SkipTest(
             'no handler for %s, do you need to install PyCrypto or mhash?'
             % (self.chf_type, ))
コード例 #4
0
ファイル: digest.py プロジェクト: floppym/pkgcore
def _write_manifest(handle, chf, filename, chksums):
    """Convenient, internal method for writing manifests"""
    size = chksums.pop("size")
    handle.write("%s %s %i" % (chf.upper(), filename, size))
    for chf in sorted(chksums):
        handle.write(" %s %s" % (chf.upper(), get_handler(chf).long2str(chksums[chf])))
    handle.write('\n')
コード例 #5
0
    def _write(self):
        md5_handler = get_handler('md5')
        outfile = None
        try:
            outfile = self._get_fd(True)

            for obj in sorted(self):

                if obj.is_reg:
                    s = " ".join(("obj", obj.location,
                        md5_handler.long2str(obj.chksums["md5"]),
                        str(int(obj.mtime))))

                elif obj.is_sym:
                    s = " ".join(("sym", obj.location, "->",
                                   obj.target, str(int(obj.mtime))))

                elif obj.is_dir:
                    s = "dir " + obj.location

                elif obj.is_dev:
                    s = "dev " + obj.location

                elif obj.is_fifo:
                    s = "fif " + obj.location

                else:
                    raise Exception(f"unknown type {type(obj)}: {obj}")
                outfile.write(s + "\n")
            outfile.close()

        finally:
            # if atomic, it forces the update to be wiped.
            del outfile
コード例 #6
0
ファイル: digest.py プロジェクト: filmor/pkgcore
def _write_manifest(handle, chf, filename, chksums):
    """Convenient, internal method for writing manifests"""
    size = chksums.pop("size")
    handle.write("%s %s %i" % (chf.upper(), filename, size))
    for chf in sorted(chksums):
        handle.write(" %s %s" % (chf.upper(), get_handler(chf).long2str(chksums[chf])))
    handle.write('\n')
コード例 #7
0
ファイル: test_defaults.py プロジェクト: chutz/snakeoil
 def get_chf(self):
     try:
         self.chf = chksum.get_handler(self.chf_type)
     except KeyError:
         raise SkipTest(
             'no handler for %s, do you need to install PyCrypto or mhash?'
             % (self.chf_type,))
コード例 #8
0
 def _get_chf_serializer(chf):
     if chf == 'eclassdir':
         return lambda data: os.path.dirname(data.path)
     if chf == 'mtime':
         return lambda data: '%.0f' % math.floor(data.mtime)
     # Skip the leading 0x...
     getter = operator.attrgetter(chf)
     return lambda data: get_handler(chf).long2str(getter(data))
コード例 #9
0
ファイル: __init__.py プロジェクト: den4ix/pkgcore
 def _get_chf_serializer(chf):
     if chf == 'eclassdir':
         return lambda data: os.path.dirname(data.path)
     if chf == 'mtime':
         return lambda data: '%.0f' % math.floor(data.mtime)
     # Skip the leading 0x...
     getter = operator.attrgetter(chf)
     return lambda data: get_handler(chf).long2str(getter(data))
コード例 #10
0
ファイル: deltadb.py プロジェクト: rafaelmartins/distpatch
 def _parse_checksum_line(self, line):
     pieces = line.split()
     chksums = OrderedDict()
     uchksums = OrderedDict()
     for key, value in izip(pieces[::2], pieces[1::2]):
         key = key.lower()[:]
         mykey = key[0] == 'u' and key[1:] or key
         myvalue = get_handler(mykey).str2long(value.strip())
         if key[0] == 'u':
             uchksums[mykey] = myvalue
         else:
             chksums[mykey] = myvalue
     return chksums, uchksums
コード例 #11
0
ファイル: test_chksum.py プロジェクト: pombredanne/snakeoil
 def test_get_handler(self):
     with pytest.raises(chksum.MissingChksumHandler):
         chksum.get_handler("x")
     assert self._inited_count == 1
     chksum.chksum_types["x"] = 1
     with pytest.raises(chksum.MissingChksumHandler):
         chksum.get_handler("y")
     chksum.chksum_types["y"] = 2
     assert chksum.get_handler("x") == 1
     assert chksum.get_handler("y") == 2
     assert self._inited_count == 1
コード例 #12
0
ファイル: __init__.py プロジェクト: filmor/pkgcore
 def _default_serializer(chf, data):
     # Skip the leading 0x...
     getter = operator.attrgetter(chf)
     return get_handler(chf).long2str(getter(data))
コード例 #13
0
ファイル: chksums.py プロジェクト: rafaelmartins/distpatch
 def __init__(self, algorithm, value):
     self.algorithm = algorithm
     self.value = value
     self._handler = get_handler(algorithm)
コード例 #14
0
 def get_chf(self):
     try:
         self.chf = chksum.get_handler(self.chf_type)
     except chksum.MissingChksumHandler:
         self.chf = None