コード例 #1
0
ファイル: metadata.py プロジェクト: chargen/shastity
    def from_string(cls, s):
        '''Given a string in the format produced by to_string(), parse
        it and return the resulting instance.'''
        comps = s.split()

        assert len(comps) > 1

        d = str_to_mode(comps[0])  # grab most flags

        expt_len = 8 if d['is_symlink'] else 7
        assert len(comps) == expt_len, (
            'incorrectly formatted meta data string - should be 7 or 8 '
            'space separated tokens, depending on whether it is a symlink')

        d['uid'] = int(comps[1])
        d['gid'] = int(comps[2])
        d['size'] = int(comps[3])
        d['atime'] = int(comps[4])
        d['mtime'] = int(comps[5])
        d['ctime'] = int(comps[6])

        if d['is_symlink']:
            d['symlink_value'] = spencode.spdecode(comps[7])

        return FileMetaData(d)
コード例 #2
0
ファイル: manifest.py プロジェクト: chargen/shastity
def read_manifest(backend, name):
    """
    @return A backup entry generator producing all entries, in order,
            contained in the manifest.
    """
    assert '.' not in name, 'manifest names cannot contain dots'

    mf_lines = [line.strip() for line in backend.get(name).split('\n')]

    version = None
    lineno = 1

    if len(mf_lines) == 0:
        raise ManifestError(lineno, '', "Manifest empty")

    if mf_lines[0] != 'shastity':
        raise ManifestError(lineno, mf_lines[0], "First line not 'shastity'")

    lineno += 1

    for head in mf_lines[lineno - 1:]:
        lineno += 1

        if head == 'end':
            break

        # version
        m = re.match(r'version (\d+)', head)
        if m:
            version = int(m.group(1))

        # unknown
        else:
            raise ManifestError(lineno, head,
                                "Invalid header line: %s" % (head))

    if len(mf_lines) == 0:
        raise ManifestError(lineno, '', "Header error or no data.")

    if version is None:
        raise ManifestError(lineno, '',
                            "Required manifest header 'version' missing")

    for line in mf_lines[lineno - 1:]:
        lineno += 1
        (md, path, rest) = [s.strip() for s in line.split('|')]

        md = metadata.FileMetaData.from_string(md)
        path = spencode.spdecode(path)

        if rest:
            rest = [(algo, hex)
                    for (algo,
                         hex) in [pair.split(',') for pair in rest.split()]]
        else:
            rest = []

        yield (path, md, rest)
コード例 #3
0
ファイル: manifest.py プロジェクト: ThomasHabets/shastity
def read_manifest(backend, name):
    """
    @return A backup entry generator producing all entries, in order,
            contained in the manifest.
    """
    assert "." not in name, "manifest names cannot contain dots"

    mf_lines = [line.strip() for line in backend.get(name).split("\n")]

    version = None
    lineno = 1

    if len(mf_lines) == 0:
        raise ManifestError(lineno, "", "Manifest empty")

    if mf_lines[0] != "shastity":
        raise ManifestError(lineno, mf_lines[0], "First line not 'shastity'")

    lineno += 1

    for head in mf_lines[lineno - 1 :]:
        lineno += 1

        if head == "end":
            break

        # version
        m = re.match(r"version (\d+)", head)
        if m:
            version = int(m.group(1))

        # unknown
        else:
            raise ManifestError(lineno, head, "Invalid header line: %s" % (head))

    if len(mf_lines) == 0:
        raise ManifestError(lineno, "", "Header error or no data.")

    if version is None:
        raise ManifestError(lineno, "", "Required manifest header 'version' missing")

    for line in mf_lines[lineno - 1 :]:
        lineno += 1
        (md, path, rest) = [s.strip() for s in line.split("|")]

        md = metadata.FileMetaData.from_string(md)
        path = spencode.spdecode(path)

        if rest:
            rest = [(algo, hex) for (algo, hex) in [pair.split(",") for pair in rest.split()]]
        else:
            rest = []

        yield (path, md, rest)
コード例 #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
ファイル: test_spencode.py プロジェクト: chargen/shastity
    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)
コード例 #6
0
ファイル: manifest.py プロジェクト: GunioRobot/shastity
def read_manifest(backend, name):
    """
    @return A backup entry generator producing all entries, in order,
            contained in the manifest.
    """
    assert '.' not in name, 'manifest names cannot contain dots'
    
    mf_lines = [ line.strip() for line in backend.get(name).split('\n') ]

    for line in mf_lines:
        (md, path, rest) = [ s.strip() for s in line.split('|') ]

        md = metadata.FileMetaData.from_string(md)
        path = spencode.spdecode(path)
        
        if rest:
            rest = [ (algo, hex) for (algo, hex) in [ pair.split(',') for pair in rest.split() ] ]
        else:
            rest = []

        yield (path, md, rest)
コード例 #7
0
ファイル: metadata.py プロジェクト: GunioRobot/shastity
    def from_string(cls, s):
        '''Given a string in the format produced by to_string(), parse
        it and return the resulting instance.'''
        comps = s.split()
        
        assert len(comps) > 1

        d = str_to_mode(comps[0]) # grab most flags
        
        expt_len = 8 if d['is_symlink'] else 7
        assert len(comps) == expt_len, ('incorrectly formatted meta data string - should be 7 or 8 '
                                        'space separated tokens, depending on whether it is a symlink')

        d['uid'] = int(comps[1])
        d['gid'] = int(comps[2])
        d['size'] = int(comps[3])
        d['atime'] = int(comps[4])
        d['mtime'] = int(comps[5])
        d['ctime'] = int(comps[6])

        if d['is_symlink']:
            d['symlink_value'] = spencode.spdecode(comps[7])

        return FileMetaData(d)