~ubuntu-branches/debian/sid/glusterfs/sid

« back to all changes in this revision

Viewing changes to geo-replication/syncdaemon/libgfchangelog.py

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2014-04-22 10:00:41 UTC
  • mfrom: (1.3.25)
  • Revision ID: package-import@ubuntu.com-20140422100041-6mur2ttyvb8zzpfq
Tags: 3.5.0-1
* New upstream release.
  - Rewrite patch 01-spelling-error.
  - Adjust lintian overrides.
  - Install new files.
  - The offical tarball is not properly generated, hack it around.
  - Add symlink from fusermount-glusterfs manpage to mount.glusterfs.
  - Move gsync-sync-gfid from /usr/share to /usr/lib.
  - Add benchmarking directory.
* Remove old versioned build dependencies and build depend on libglib2.0-dev.
* Add lintian override for possible-gpl-code-linked-with-openssl. It is the
  same false positive like with the gluster-server package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from ctypes import *
 
3
from ctypes.util import find_library
 
4
 
 
5
class Changes(object):
 
6
    libgfc = CDLL(find_library("gfchangelog"), use_errno=True)
 
7
 
 
8
    @classmethod
 
9
    def geterrno(cls):
 
10
        return get_errno()
 
11
 
 
12
    @classmethod
 
13
    def raise_oserr(cls):
 
14
        errn = cls.geterrno()
 
15
        raise OSError(errn, os.strerror(errn))
 
16
 
 
17
    @classmethod
 
18
    def _get_api(cls, call):
 
19
        return getattr(cls.libgfc, call)
 
20
 
 
21
    @classmethod
 
22
    def cl_register(cls, brick, path, log_file, log_level, retries = 0):
 
23
        ret = cls._get_api('gf_changelog_register')(brick, path,
 
24
                                                    log_file, log_level, retries)
 
25
        if ret == -1:
 
26
            cls.raise_oserr()
 
27
 
 
28
    @classmethod
 
29
    def cl_scan(cls):
 
30
        ret = cls._get_api('gf_changelog_scan')()
 
31
        if ret == -1:
 
32
            cls.raise_oserr()
 
33
 
 
34
    @classmethod
 
35
    def cl_startfresh(cls):
 
36
        ret = cls._get_api('gf_changelog_start_fresh')()
 
37
        if ret == -1:
 
38
            cls.raise_oserr()
 
39
 
 
40
    @classmethod
 
41
    def cl_getchanges(cls):
 
42
        """ remove hardcoding for path name length """
 
43
        def clsort(f):
 
44
            return f.split('.')[-1]
 
45
        changes = []
 
46
        buf = create_string_buffer('\0', 4096)
 
47
        call = cls._get_api('gf_changelog_next_change')
 
48
 
 
49
        while True:
 
50
            ret = call(buf, 4096)
 
51
            if ret in (0, -1):
 
52
                break;
 
53
            changes.append(buf.raw[:ret-1])
 
54
        if ret == -1:
 
55
            cls.raise_oserr()
 
56
        # cleanup tracker
 
57
        cls.cl_startfresh()
 
58
        return sorted(changes, key=clsort)
 
59
 
 
60
    @classmethod
 
61
    def cl_done(cls, clfile):
 
62
        ret = cls._get_api('gf_changelog_done')(clfile)
 
63
        if ret == -1:
 
64
            cls.raise_oserr()