Пример #1
0
def write_manifest(backend, name, entry_generator):
    """
    @param backend A storage backend (dedicated to manifests)

    @type  name A string.
    @param name Name of manifest; must not contain dots.
    
    @param entry_generator Backup entry generator producting all
                           entries, in order, for inclusion in the
                           manifest.
    """
    assert "." not in name, "manifest names cannot contain dots"

    mf_lines = ["shastity", "version 1", "end"]

    for (path, metadata, hashes) in entry_generator:
        md = metadata.to_string()

        pth = spencode.spencode(path)

        rest = " ".join(["%s,%s" % (algo, hex) for (algo, hex) in hashes])

        mf_lines.append("%s | %s | %s" % (md, pth, rest))

    backend.put(name, "\n".join(mf_lines))
Пример #2
0
def write_manifest(backend, name, entry_generator):
    """
    @param backend A storage backend (dedicated to manifests)

    @type  name A string.
    @param name Name of manifest; must not contain dots.
    
    @param entry_generator Backup entry generator producting all
                           entries, in order, for inclusion in the
                           manifest.
    """
    assert '.' not in name, 'manifest names cannot contain dots'

    mf_lines = ['shastity', 'version 1', 'end']

    for (path, metadata, hashes) in entry_generator:
        md = metadata.to_string()

        pth = spencode.spencode(path)

        rest = ' '.join(['%s,%s' % (algo, hex) for (algo, hex) in hashes])

        mf_lines.append('%s | %s | %s' % (md, pth, rest))

    backend.put(name, '\n'.join(mf_lines))
Пример #3
0
    def to_string(self):
        '''Produce a string encoding of this meta data.

        The format of the string is:

          MODESTR uid gid size atime mtime ctime

        Where MODESTR is the result of mode_to_str() (ls -l
        style). Times are seconds since epoch.'''

        assert self.uid is not None
        assert self.gid is not None
        assert self.size is not None
        assert self.atime is not None
        assert self.mtime is not None
        assert self.ctime is not None

        if self.is_symlink:
            assert self.symlink_value is not None  # may be empty though - that's valid for a symlink
            possible_symlink = ' %s' % (spencode.spencode(
                self.symlink_value), )
        else:
            possible_symlink = ''

        return (
            '%(modestring)s %(uid)d %(gid)d %(size)d %(atime)d %(mtime)d %(ctime)d%(possible_symlink)s'
            '' % dict(modestring=mode_to_str(
                dict(is_directory=self.is_directory,
                     is_character_device=self.is_character_device,
                     is_block_device=self.is_block_device,
                     is_regular=self.is_regular,
                     is_fifo=self.is_fifo,
                     is_symlink=self.is_symlink,
                     is_setuid=self.is_setuid,
                     is_setgid=self.is_setgid,
                     is_sticky=self.is_sticky,
                     user_read=self.user_read,
                     user_write=self.user_write,
                     user_execute=self.user_execute,
                     group_read=self.group_read,
                     group_write=self.group_write,
                     group_execute=self.group_execute,
                     other_read=self.other_read,
                     other_write=self.other_write,
                     other_execute=self.other_execute)),
                      uid=self.uid,
                      gid=self.gid,
                      size=self.size,
                      atime=self.atime,
                      mtime=self.mtime,
                      ctime=self.ctime,
                      possible_symlink=possible_symlink))
Пример #4
0
    def conv(self, s):
        encoded = sp.spencode(s)

        self.assertTrue(len(encoded) >= 2)
        self.assertTrue(encoded[0] == "'")
        self.assertTrue(encoded[len(encoded) - 1] == "'")

        for c in encoded[1 : len(encoded) - 1]:
            if (not c in sp._safechars) and (c != "%"):
                raise AssertionError("unsafe non-%% character (%s) found in: %s " "encoded from %s" % (c, encoded, s))

        decoded = sp.spdecode(encoded)

        self.assertEqual(decoded, s)
Пример #5
0
    def to_string(self):
        '''Produce a string encoding of this meta data.

        The format of the string is:

          MODESTR uid gid size atime mtime ctime

        Where MODESTR is the result of mode_to_str() (ls -l
        style). Times are seconds since epoch.'''

        assert self.uid is not None
        assert self.gid is not None
        assert self.size is not None
        assert self.atime is not None
        assert self.mtime is not None
        assert self.ctime is not None

        if self.is_symlink:
            assert self.symlink_value is not None # may be empty though - that's valid for a symlink
            possible_symlink = ' %s' % (spencode.spencode(self.symlink_value),)
        else:
            possible_symlink = ''

        return ('%(modestring)s %(uid)d %(gid)d %(size)d %(atime)d %(mtime)d %(ctime)d%(possible_symlink)s'
                '' % dict(modestring=mode_to_str(dict(is_directory=self.is_directory,
                                                      is_character_device=self.is_character_device,
                                                      is_block_device=self.is_block_device,
                                                      is_regular=self.is_regular,
                                                      is_fifo=self.is_fifo,
                                                      is_symlink=self.is_symlink,
                                                      is_setuid=self.is_setuid,
                                                      is_setgid=self.is_setgid,
                                                      is_sticky=self.is_sticky,
                                                      user_read=self.user_read,
                                                      user_write=self.user_write,
                                                      user_execute=self.user_execute,
                                                      group_read=self.group_read,
                                                      group_write=self.group_write,
                                                      group_execute=self.group_execute,
                                                      other_read=self.other_read,
                                                      other_write=self.other_write,
                                                      other_execute=self.other_execute)),
                          uid=self.uid,
                          gid=self.gid,
                          size=self.size,
                          atime=self.atime,
                          mtime=self.mtime,
                          ctime=self.ctime,
                          possible_symlink=possible_symlink))
Пример #6
0
    def conv(self, s):
        encoded = sp.spencode(s)

        self.assertTrue(len(encoded) >= 2)
        self.assertTrue(encoded[0] == "'")
        self.assertTrue(encoded[len(encoded) - 1] == "'")

        for c in encoded[1:len(encoded) - 1]:
            if (not c in sp._safechars) and (c != '%'):
                raise AssertionError(
                    'unsafe non-%% character (%s) found in: %s '
                    'encoded from %s' % (c, encoded, s))

        decoded = sp.spdecode(encoded)

        self.assertEqual(decoded, s)