<commit_before>import os, operator
from backupcommon import SnapHandler, Configuration, scriptpath, info, error, debug, UIElement
from ConfigParser import SafeConfigParser, NoOptionError
from datetime import datetime, timedelta
from NaServer import *

class Netapp(SnapHandler):
    _exceptionbase = "netapp"
    _blocksize = 1024
    _filer = None
    _cacert = None

    def __init__(self, configname):
        zfscredfilename = os.path.join(scriptpath(), 'netappcredentials.cfg')
        if not os.path.isfile(zfscredfilename):
            raise Exception(self._exceptionbase, "Configuration file %s not found" % zfscredfilename)
        # Authentication information
        zfscredconfig = SafeConfigParser()
        zfscredconfig.read(zfscredfilename)
        zfsauth = (zfscredconfig.get('netappcredentials','user'), zfscredconfig.get('netappcredentials','password'))
        #
        self._filer = Configuration.get('filer', 'netapp')
        self._srv = NaServer(self._filer, 1, 1)
        # Check if CA certificate validation is needed
        try:
            self._cacert = os.path.join(scriptpath(), 'certs', Configuration.get('cacert', 'netapp'))
        except NoOptionError:
            self._cacert = None
        if self._cacert:
            self._srv.set_ca_certs(self._cacert)
            self._srv.set_server_cert_verification(True)
            self._srv.set_hostname_verification(False)
        #
        self._srv.set_admin_user(zfscredconfig.get('netappcredentials','user'), zfscredconfig.get('netappcredentials','password'))
        self._volprefix = Configuration.get('volumeprefix', 'netapp')
        self._volname = "%s%s" % (self._volprefix, configname)
        super(Netapp, self).__init__(configname)

    def _check_netapp_error(self, output, errmsg):
        if output.results_errno() != 0:
            raise Exception(self._exceptionbase, "%s. %s" % (errmsg, output.results_reason()))
    
    def _volsize_to_num(self, volsize):
        unit = volsize[-1].lower()
        factor = 1
        if unit == "m":
            factor = 20<commit_msg>Possibility to override Netapp connection details in credentials file<commit_after>import os, operator
from backupcommon import SnapHandler, Configuration, scriptpath, info, error, debug, UIElement
from ConfigParser import SafeConfigParser, NoOptionError
from datetime import datetime, timedelta
from NaServer import *

class Netapp(SnapHandler):
    _exceptionbase = "netapp"
    _blocksize = 1024
    _filer = None
    _cacert = None

    def _read_netapp_config(self, attribute, zfscredconfig):
        # Try reading Netapp configuration first from the credentials file, then fail over to main configuration file
        value = None
        try:
            return zfscredconfig.get('netapp', attribute)
        except NoOptionError:
            pass
        try:
            return Configuration.get(attribute, 'netapp')
        except NoOptionError:
            raise NoOptionError("Attribute %s not found" % attribute)
        
    def __init__(self, configname):
        zfscredfilename = os.path.join(scriptpath(), 'netappcredentials.cfg')
        if not os.path.isfile(zfscredfilename):
            raise Exception(self._exceptionbase, "Configuration file %s not found" % zfscredfilename)
        # Authentication information
        zfscredconfig = SafeConfigParser()
        zfscredconfig.read(zfscredfilename)
        #
        self._filer = self._read_netapp_config('filer', zfscredconfig)
        self._srv = NaServer(self._filer, 1, 1)
        # Check if CA certificate validation is needed
        try:
            self._cacert = os.path.join(scriptpath(), 'certs', self._read_netapp_config('cacert', zfscredconfig))
        except NoOptionError:
            self._cacert = None
        if self._cacert:
            self._srv.set_ca_certs(self._cacert)
            self._srv.set_server_cert_verification(True)
            self._srv.set_hostname_verification(False)
        #
        self._srv.set_admin_user(zfscredconfig.get('netappcredentials','user'), zfscredconfig.get('netappcredentials','password'))
        self._volprefix = self._read_netapp_config('volumeprefix', zfscredconfig)
        self._volname = "%s%s" % (self._volprefix, configname)
        super(Netapp, self).__init__(configname)

    def _check_netapp_error(self, output, errmsg):
        if output.results_errno() != 0:
            raise Exception(self._exceptionbase, "%s. %s" % (errmsg, output.results_reason()))
    
    def _volsize_to_num(self, volsize):
        unit = volsize[-1].lower()
        factor = 1
        if unit == "m":
            factor = 20
{'fraction_non_alphanumeric': 0.09984871406959153, 'fraction_numerical': 0.004754700669980549, 'mean_word_length': 3.0243478260869567, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3537668', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1371, 'n_words': 297}