"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/geo-replication/syncdaemon/libgfchangelog.py" (16 Sep 2020, 3318 Bytes) of package /linux/misc/glusterfs-8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "libgfchangelog.py" see the Fossies "Dox" file reference documentation.

    1 #
    2 # Copyright (c) 2011-2014 Red Hat, Inc. <http://www.redhat.com>
    3 # This file is part of GlusterFS.
    4 
    5 # This file is licensed to you under your choice of the GNU Lesser
    6 # General Public License, version 3 or any later version (LGPLv3 or
    7 # later), or the GNU General Public License, version 2 (GPLv2), in all
    8 # cases as published by the Free Software Foundation.
    9 #
   10 
   11 import os
   12 from ctypes import CDLL, RTLD_GLOBAL, get_errno, byref, c_ulong
   13 from ctypes.util import find_library
   14 from syncdutils import ChangelogException, ChangelogHistoryNotAvailable
   15 from py2py3 import (gr_cl_history_changelog, gr_cl_done,
   16                     gr_create_string_buffer, gr_cl_register,
   17                     gr_cl_history_done, bytearray_to_str)
   18 
   19 
   20 libgfc = CDLL(
   21     find_library("gfchangelog"),
   22     mode=RTLD_GLOBAL,
   23     use_errno=True
   24 )
   25 
   26 
   27 def _raise_changelog_err():
   28     errn = get_errno()
   29     raise ChangelogException(errn, os.strerror(errn))
   30 
   31 
   32 def _init():
   33     if libgfc.gf_changelog_init(None) == -1:
   34         _raise_changelog_err()
   35 
   36 
   37 def register(brick, path, log_file, log_level, retries=0):
   38     _init()
   39 
   40     ret = gr_cl_register(libgfc, brick, path, log_file, log_level, retries)
   41 
   42     if ret == -1:
   43         _raise_changelog_err()
   44 
   45 
   46 def scan():
   47     ret = libgfc.gf_changelog_scan()
   48     if ret == -1:
   49         _raise_changelog_err()
   50 
   51 
   52 def startfresh():
   53     ret = libgfc.gf_changelog_start_fresh()
   54     if ret == -1:
   55         _raise_changelog_err()
   56 
   57 
   58 def getchanges():
   59     def clsort(cfile):
   60         return cfile.split('.')[-1]
   61 
   62     changes = []
   63     buf = gr_create_string_buffer(4096)
   64     call = libgfc.gf_changelog_next_change
   65 
   66     while True:
   67         ret = call(buf, 4096)
   68         if ret in (0, -1):
   69             break
   70 
   71         # py2 and py3 compatibility
   72         result = bytearray_to_str(buf.raw[:ret - 1])
   73         changes.append(result)
   74 
   75     if ret == -1:
   76         _raise_changelog_err()
   77 
   78     # cleanup tracker
   79     startfresh()
   80 
   81     return sorted(changes, key=clsort)
   82 
   83 
   84 def done(clfile):
   85     ret = gr_cl_done(libgfc, clfile)
   86     if ret == -1:
   87         _raise_changelog_err()
   88 
   89 
   90 def history_scan():
   91     ret = libgfc.gf_history_changelog_scan()
   92     if ret == -1:
   93         _raise_changelog_err()
   94 
   95     return ret
   96 
   97 
   98 def history_changelog(changelog_path, start, end, num_parallel):
   99     actual_end = c_ulong()
  100     ret = gr_cl_history_changelog(libgfc, changelog_path, start, end,
  101                                   num_parallel, byref(actual_end))
  102     if ret == -1:
  103         _raise_changelog_err()
  104 
  105     if ret == -2:
  106         raise ChangelogHistoryNotAvailable()
  107 
  108     return (ret, actual_end.value)
  109 
  110 
  111 def history_startfresh():
  112     ret = libgfc.gf_history_changelog_start_fresh()
  113     if ret == -1:
  114         _raise_changelog_err()
  115 
  116 
  117 def history_getchanges():
  118     def clsort(cfile):
  119         return cfile.split('.')[-1]
  120 
  121     changes = []
  122     buf = gr_create_string_buffer(4096)
  123     call = libgfc.gf_history_changelog_next_change
  124 
  125     while True:
  126         ret = call(buf, 4096)
  127         if ret in (0, -1):
  128             break
  129 
  130         # py2 and py3 compatibility
  131         result = bytearray_to_str(buf.raw[:ret - 1])
  132         changes.append(result)
  133 
  134     if ret == -1:
  135         _raise_changelog_err()
  136 
  137     return sorted(changes, key=clsort)
  138 
  139 
  140 def history_done(clfile):
  141     ret = gr_cl_history_done(libgfc, clfile)
  142     if ret == -1:
  143         _raise_changelog_err()