"Fossies" - the Fresh Open Source Software Archive

Member "glusterfs-8.2/tools/glusterfind/src/libgfchangelog.py" (16 Sep 2020, 2775 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 # -*- coding: utf-8 -*-
    2 
    3 # Copyright (c) 2015 Red Hat, Inc. <http://www.redhat.com/>
    4 # This file is part of GlusterFS.
    5 #
    6 # This file is licensed to you under your choice of the GNU Lesser
    7 # General Public License, version 3 or any later version (LGPLv3 or
    8 # later), or the GNU General Public License, version 2 (GPLv2), in all
    9 # cases as published by the Free Software Foundation.
   10 
   11 import os
   12 from ctypes import CDLL, RTLD_GLOBAL, get_errno, create_string_buffer, c_ulong, byref
   13 from ctypes.util import find_library
   14 from gfind_py2py3 import bytearray_to_str, gf_create_string_buffer
   15 from gfind_py2py3 import gfind_history_changelog, gfind_changelog_register
   16 from gfind_py2py3 import gfind_history_changelog_done
   17 
   18 
   19 class ChangelogException(OSError):
   20     pass
   21 
   22 libgfc = CDLL(find_library("gfchangelog"), mode=RTLD_GLOBAL, use_errno=True)
   23 
   24 
   25 def raise_oserr(prefix=None):
   26     errn = get_errno()
   27     prefix_or_empty = prefix + ": " if prefix else ""
   28     raise ChangelogException(errn, prefix_or_empty + os.strerror(errn))
   29 
   30 
   31 def cl_init():
   32     ret = libgfc.gf_changelog_init(None)
   33     if ret == -1:
   34         raise_oserr(prefix="gf_changelog_init")
   35 
   36 
   37 def cl_register(brick, path, log_file, log_level, retries=0):
   38     ret = gfind_changelog_register(libgfc, brick, path, log_file,log_level, retries)
   39     if ret == -1:
   40         raise_oserr(prefix="gf_changelog_register")
   41 
   42 
   43 def cl_history_scan():
   44     ret = libgfc.gf_history_changelog_scan()
   45     if ret == -1:
   46         raise_oserr(prefix="gf_history_changelog_scan")
   47 
   48     return ret
   49 
   50 
   51 def cl_history_changelog(changelog_path, start, end, num_parallel):
   52     actual_end = c_ulong()
   53     ret = gfind_history_changelog(libgfc,changelog_path, start, end,
   54                                       num_parallel,
   55                                       byref(actual_end))
   56     if ret == -1:
   57         raise_oserr(prefix="gf_history_changelog")
   58 
   59     return actual_end.value
   60 
   61 
   62 def cl_history_startfresh():
   63     ret = libgfc.gf_history_changelog_start_fresh()
   64     if ret == -1:
   65         raise_oserr(prefix="gf_history_changelog_start_fresh")
   66 
   67 
   68 def cl_history_getchanges():
   69     """ remove hardcoding for path name length """
   70     def clsort(f):
   71         return f.split('.')[-1]
   72 
   73     changes = []
   74     buf = gf_create_string_buffer(4096)
   75 
   76     while True:
   77         ret = libgfc.gf_history_changelog_next_change(buf, 4096)
   78         if ret in (0, -1):
   79             break
   80         # py2 and py3 compatibility
   81         result = bytearray_to_str(buf.raw[:ret - 1])
   82         changes.append(result)
   83     if ret == -1:
   84         raise_oserr(prefix="gf_history_changelog_next_change")
   85 
   86     return sorted(changes, key=clsort)
   87 
   88 
   89 def cl_history_done(clfile):
   90     ret = gfind_history_changelog_done(libgfc, clfile)
   91     if ret == -1:
   92         raise_oserr(prefix="gf_history_changelog_done")