<commit_before>import logging
import vmcatcher.databaseDefinition as model
from smimeX509validation import TrustStore, LoadDirChainOfTrust,smimeX509validation, smimeX509ValidationError
from hepixvmitrust.vmitrustlib import time_format_definition as time_format_definition

class output_driver_base(object):
    def __init__(self,file_pointer,session,anchor):
        self.session = session
        self.log = logging.getLogger("db_actions")
        self.file_pointer = file_pointer
        self.anchor = anchor
    def display_subscription_imagelist(self,subscription,imagelist):
        status = None

        self.display_subscription(subscription)
        self.display_imagelist(imagelist)

        return True
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        pass
    def subscriptions_lister(self):
        pass
    def display_image_def(self,subscription):
        pass


class output_driver_smime(output_driver_base):
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        self.file_pointer.write (imagelist.data)
        return True
    def display_imagelistImage(self,imagedef,imagelist,image):
        if not self.display_imagelist(imagelist):
            return False
        return True


class output_driver_message(output_driver_base):
    def __init__(self,file_pointer,session,anchor):
        output_driver_base.__init__(self,file_pointer,session,anchor)
        self.log = logging.getLogger("output_driver_message")
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        smimeProcessor =  smimeX509validation(self.anchor)
        try:
            smimeProcessor.Process(str(imagelist.data))
        except smimeX509ValidationError,E:
            self.log.error("Failed to validate text for '%s' produced error '%s'" % (imagelist,E))
            return False
        if not smimeProcessor.verified:
            self.log.error("Failed to validate text for '%s' produced error '%s'" % (subscriptionKey,E))
            return False
        self.file_pointer.write (smimeProcessor.InputDaraStringIO.getvalue())
        return True

    def display_imagelistImage(self,imagedef,imagelist,image):
        if not self.display_imagelist(imagelist):
            return False
        return True


class output_driver_lines(output_driver_base):
    def __init__(self,file_pointer,session,anchor):
        output_driver_base.__init__(self,file_pointer,session,anchor)
        self.log = logging.getLogger("output_driver_lines")

    def display_subscription(self,subscription):
        
        self.file_pointer.write ('subscription.dc:identifier=%s\n' % (subscription.identifier))
        self.file_pointer.write ('subscription.dc:description=%s\n' % (subscription.description))
        self.file_pointer.write ('subscription.sl:authorised=%s\n' % (subscription.authorised))
        self.file_pointer.write ('subscription.hv:uri=%s\n' % (subscription.uri))
        if subscription.updated:
            self.file_pointer.write ('subscription.dc:date:updated=%s\n' % (subscription.updated.strftime(time_format_definition)))
        else:
            self.file_pointer.write ('subscription.dc:date:updated=%s\n'% (False))
        return True

    def display_imagelist(self,imagelist):
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (imagelist.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (imagelist.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (imagelist.expires.strftime(time_format_definition)))
        if imagelist.expired == None:
            self.file_pointer.write ('imagelist.expired=0\n')
        else:
            self.file_pointer.write ('imagelist.expired=%s\n' % (imagelist.expired.strftime(time_format_definition)))
    def subscriptions_lister(self):
        subauthq = self.session.query(model.Subscription).all()
        for item in subauthq:
            self.file_pointer.write ("%s\t%s\t%s\n" % (item.identifier,item.authorised,item.uri))

    def display_image_def(self,imagedef):
        self.file_pointer.write ('subscription.image.dc:identifier=%s\n' % (imagedef.identifier))

    def endorser_lister(self,allendorsers):
        for endorser in allendorsers:
            EndId = str(endorser.identifier)
            subauthq = self.session.query(model.Endorser,model.EndorserPrincible).\
                filter(model.Endorser.id==model.EndorserPrincible.endorser).\
                filter(model.Endorser.identifier==EndId)
            for item in subauthq:
                endorser = item[0]
                princible = item[1]
                self.file_pointer.write ("'%s'\t'%s'\t'%s'\n" % (endorser.identifier,princible.hv_dn,princible.hv_ca))

    def links_lister(self,allLinks):
        for sub,endorser,aubauth in allLinks:
            self.file_pointer.write ("'%s'\t'%s'\t'%s'\n" % (endorser.identifier,sub.identifier,aubauth.authorised))

    def display_endorser(self,endorser):
        self.file_pointer.write ("endorser.dc:identifier=%s\n" % (endorser.identifier))
        princible_query = self.query.princible_by_endorserId(endorser.id)
        if princible_query.count() == 0:
            self.log.warning("endorser '%s' has no princibles" % (selector_filter))
            return False
        for princible in princible_query:
            self.file_pointer.write("endorser.hv:dn=%s\n" % (princible.hv_dn))
            self.file_pointer.write("endorser.hv:ca=%s\n" % (princible.hv_ca))
        subauth_query = self.query.subscriptionAuth_by_endorserId(endorser.id)
        for subauth in subauth_query:
            #self.file_pointer.write("subauth.authorised=%s\n" % (subauth.authorised))
            subscription_query = self.query.subscription_by_id(subauth.subscription)
            for subscription in subscription_query:
                self.display_subscription(subscription)


    def display_imagelistImage(self,imagedef,imagelist,image):
        self.file_pointer.write ('imagelist.dc:identifier=%s\n' % (imagedef.identifier))
        
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (imagelist.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (imagelist.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (imagelist.expires.strftime(time_format_definition)))
        self.file_pointer.write ('imagedef.dc:identifier=%s\n' % (imagedef.identifier))
        self.file_pointer.write ('imagedef.cache=%s\n' % (imagedef.cache))
        self.file_pointer.write ('image.dc:description=%s\n' % (image.description))
        self.file_pointer.write ('image.dc:title=%s\n' % (image.title))
        self.file_pointer.write ('image.hv:hypervisor=%s\n' % (image.hypervisor))
        self.file_pointer.write ('image.hv:size=%s\n' % (image.size))
        self.file_pointer.write ('image.hv:uri=%s\n' % (image.uri))
        self.file_pointer.write ('image.hv:version=%s\n' % (image.version))
        self.file_pointer.write ('image.sl:arch=%s\n' % (image.hypervisor))
        self.file_pointer.write ('image.sl:checksum:sha512=%s\n' % (image.sha512))
        self.file_pointer.write ('image.sl:comments=%s\n' % (image.comments))
        self.file_pointer.write ('image.sl:os=%s\n' % (image.os))
        self.file_pointer.write ('image.sl:osversion=%s\n' % (image.osversion))
        return True
        
    def display_subscriptionInfo(self,imagedef,imagelist,image):
        #self.log.info(type(imagedef))
        #self.log.info(type(imagelist))
        #self.log.info(type(image))
        #self.log.info(dir(image))
        msg = "expired=%s" % (image.expired)
        self.file_pointer.write (msg)
        self.log.info(msg)
        msg = "imagelist.version=%s" % (image.version)
        self.file_pointer.write (msg)
        self.log.info(msg)
        
        
        
        self.file_pointer.write ('imagelist.dc:identifier=%s\n' % (image.id))
        
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (image.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (image.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (image.expires.strftime(time_format_definition)))
        self.file_pointer.write ('imagedef.dc:identifier=%s\n' % (imagedef.identifier))
        #self.file_pointer.write ('imagedef.cache=%s\n' % (imagedef.cache))<commit_msg>now we are grettting thigns out<commit_after>import logging
import vmcatcher.databaseDefinition as model
from smimeX509validation import TrustStore, LoadDirChainOfTrust,smimeX509validation, smimeX509ValidationError
from hepixvmitrust.vmitrustlib import time_format_definition as time_format_definition

class output_driver_base(object):
    def __init__(self,file_pointer,session,anchor):
        self.session = session
        self.log = logging.getLogger("db_actions")
        self.file_pointer = file_pointer
        self.anchor = anchor
    def display_subscription_imagelist(self,subscription,imagelist):
        status = None

        self.display_subscription(subscription)
        self.display_imagelist(imagelist)

        return True
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        pass
    def subscriptions_lister(self):
        pass
    def display_image_def(self,subscription):
        pass


class output_driver_smime(output_driver_base):
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        self.file_pointer.write (imagelist.data)
        return True
    def display_imagelistImage(self,imagedef,imagelist,image):
        if not self.display_imagelist(imagelist):
            return False
        return True


class output_driver_message(output_driver_base):
    def __init__(self,file_pointer,session,anchor):
        output_driver_base.__init__(self,file_pointer,session,anchor)
        self.log = logging.getLogger("output_driver_message")
    def display_subscription(self,subscription):
        pass
    def display_imagelist(self,imagelist):
        smimeProcessor =  smimeX509validation(self.anchor)
        try:
            smimeProcessor.Process(str(imagelist.data))
        except smimeX509ValidationError,E:
            self.log.error("Failed to validate text for '%s' produced error '%s'" % (imagelist,E))
            return False
        if not smimeProcessor.verified:
            self.log.error("Failed to validate text for '%s' produced error '%s'" % (subscriptionKey,E))
            return False
        self.file_pointer.write (smimeProcessor.InputDaraStringIO.getvalue())
        return True

    def display_imagelistImage(self,imagedef,imagelist,image):
        if not self.display_imagelist(imagelist):
            return False
        return True
    def display_subscriptionInfo(self,imagedef,imagelist,image):
        return self.display_imagelist(image)

class output_driver_lines(output_driver_base):
    def __init__(self,file_pointer,session,anchor):
        output_driver_base.__init__(self,file_pointer,session,anchor)
        self.log = logging.getLogger("output_driver_lines")

    def display_subscription(self,subscription):
        
        self.file_pointer.write ('subscription.dc:identifier=%s\n' % (subscription.identifier))
        self.file_pointer.write ('subscription.dc:description=%s\n' % (subscription.description))
        self.file_pointer.write ('subscription.sl:authorised=%s\n' % (subscription.authorised))
        self.file_pointer.write ('subscription.hv:uri=%s\n' % (subscription.uri))
        if subscription.updated:
            self.file_pointer.write ('subscription.dc:date:updated=%s\n' % (subscription.updated.strftime(time_format_definition)))
        else:
            self.file_pointer.write ('subscription.dc:date:updated=%s\n'% (False))
        return True

    def display_imagelist(self,imagelist):
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (imagelist.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (imagelist.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (imagelist.expires.strftime(time_format_definition)))
        if imagelist.expired == None:
            self.file_pointer.write ('imagelist.expired=0\n')
        else:
            self.file_pointer.write ('imagelist.expired=%s\n' % (imagelist.expired.strftime(time_format_definition)))
    def subscriptions_lister(self):
        subauthq = self.session.query(model.Subscription).all()
        for item in subauthq:
            self.file_pointer.write ("%s\t%s\t%s\n" % (item.identifier,item.authorised,item.uri))

    def display_image_def(self,imagedef):
        self.file_pointer.write ('subscription.image.dc:identifier=%s\n' % (imagedef.identifier))

    def endorser_lister(self,allendorsers):
        for endorser in allendorsers:
            EndId = str(endorser.identifier)
            subauthq = self.session.query(model.Endorser,model.EndorserPrincible).\
                filter(model.Endorser.id==model.EndorserPrincible.endorser).\
                filter(model.Endorser.identifier==EndId)
            for item in subauthq:
                endorser = item[0]
                princible = item[1]
                self.file_pointer.write ("'%s'\t'%s'\t'%s'\n" % (endorser.identifier,princible.hv_dn,princible.hv_ca))

    def links_lister(self,allLinks):
        for sub,endorser,aubauth in allLinks:
            self.file_pointer.write ("'%s'\t'%s'\t'%s'\n" % (endorser.identifier,sub.identifier,aubauth.authorised))

    def display_endorser(self,endorser):
        self.file_pointer.write ("endorser.dc:identifier=%s\n" % (endorser.identifier))
        princible_query = self.query.princible_by_endorserId(endorser.id)
        if princible_query.count() == 0:
            self.log.warning("endorser '%s' has no princibles" % (selector_filter))
            return False
        for princible in princible_query:
            self.file_pointer.write("endorser.hv:dn=%s\n" % (princible.hv_dn))
            self.file_pointer.write("endorser.hv:ca=%s\n" % (princible.hv_ca))
        subauth_query = self.query.subscriptionAuth_by_endorserId(endorser.id)
        for subauth in subauth_query:
            #self.file_pointer.write("subauth.authorised=%s\n" % (subauth.authorised))
            subscription_query = self.query.subscription_by_id(subauth.subscription)
            for subscription in subscription_query:
                self.display_subscription(subscription)


    def display_imagelistImage(self,imagedef,imagelist,image):
        self.file_pointer.write ('imagelist.dc:identifier=%s\n' % (imagedef.identifier))
        
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (imagelist.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (imagelist.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (imagelist.expires.strftime(time_format_definition)))
        self.file_pointer.write ('imagedef.dc:identifier=%s\n' % (imagedef.identifier))
        self.file_pointer.write ('imagedef.cache=%s\n' % (imagedef.cache))
        self.file_pointer.write ('image.dc:description=%s\n' % (image.description))
        self.file_pointer.write ('image.dc:title=%s\n' % (image.title))
        self.file_pointer.write ('image.hv:hypervisor=%s\n' % (image.hypervisor))
        self.file_pointer.write ('image.hv:size=%s\n' % (image.size))
        self.file_pointer.write ('image.hv:uri=%s\n' % (image.uri))
        self.file_pointer.write ('image.hv:version=%s\n' % (image.version))
        self.file_pointer.write ('image.sl:arch=%s\n' % (image.hypervisor))
        self.file_pointer.write ('image.sl:checksum:sha512=%s\n' % (image.sha512))
        self.file_pointer.write ('image.sl:comments=%s\n' % (image.comments))
        self.file_pointer.write ('image.sl:os=%s\n' % (image.os))
        self.file_pointer.write ('image.sl:osversion=%s\n' % (image.osversion))
        return True
        
    def display_subscriptionInfo(self,imagedef,imagelist,image):
        #self.log.info(type(imagedef))
        #self.log.info(type(imagelist))
        #self.log.info(type(image))
        #self.log.info(dir(image))
        if image.expired == None:
            msg = "imagelist.expired=False\n"
            
        else:
            msg = "imagelist.expired=True\n"
        self.file_pointer.write (msg)
        self.file_pointer.write ('imagelist.dc:date:imported=%s\n' % (image.imported.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:created=%s\n' % (image.created.strftime(time_format_definition)))
        self.file_pointer.write ('imagelist.dc:date:expires=%s\n' % (image.expires.strftime(time_format_definition)))
        #self.file_pointer.write ('imagedef.dc:identifier=%s\n' % (imagedef.identifier))
        #self.file_pointer.write ('imagedef.cache=%s\n' % (imagedef.cache))
{'fraction_non_alphanumeric': 0.12502874223959531, 'fraction_numerical': 0.0028742239595309265, 'mean_word_length': 3.421092757306226, 'pattern_counts': {'":': 0, '<': 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': '6312843', 'n_tokens_mistral': 5557, 'n_tokens_neox': 5430, 'n_words': 723}