<commit_before># -*- coding: iso-8859-1 -*-

import yaml, codecs, sys, os.path, optparse

from pyinotify import ProcessEvent

class Process(ProcessEvent):
    def __init__(self, logger, config):
       self.logger = logger
       self.ins_file = config['instance_file']
       self.bns_base = config['bns_base']
       self.container_relative_path = config['container_relative_path']
       self.container_base_path = config['container_base_path']
       self.clusterid = config['cluster_id']
       self.clustersuf = config['cluster_suffix']

    def process_default(self, event):
        """
        override default processing method
        """
        self.logger.debug('Process::process_default')
        # call base method
        super(Process, self).process_default(event)
    
    def process_IN_MOVED_TO(self, event):
        """
        process 'IN_MOVED_TO' events 
        """
        self.logger.debug('Process::process_IN_MOVED_TO')
        super(Process, self).process_default(event)
        fl = yaml.load(file(self.ins_file,'rb').read())
        self.update_bns_link(fl)

    def make_bns_path(self, ins):
        """
        process make bns_path 
        """
        bns_offset = 10000*int(ins['application_db_id'])+int(ins['instance_index'])*10+int(self.clusterid)
        bns_node = ins['tags']['bns_node']
        bnsset = bns_node.split('-')
        bns_name = '%s-%s-%s'%(bnsset[0],bnsset[1],bnsset[2])
        bns_path = "%s/%s.%s.%s" %(self.bns_base, bns_offset,bns_name,self.clustersuf)
        return "%s" % bns_path

    def update_bns_link(self, agent_data):
        """
        generate bns link for instances
        """
        self.logger.info('Starting checking the links.')
        raw_links = os.listdir(self.bns_base)
        current_links = set([])
        for lk in raw_links:
           current_links.add(self.bns_base + '/' + lk)

        required_links = set([])

        for ins in agent_data['instances']:
            if 'RUNNING' == ins['state']:
                 container_path = self.container_base_path + '/' + \
                     ins['warden_handle'] + '/%s' %(self.container_relative_path)
                 if  not os.path.exists(container_path):
                     self.logger.error('Container %s not exist, the data file is staled.' %(\
                     ins['warden_handle']))
                 else:
                     bns_path = self.make_bns_path(ins)
                     required_links.add(bns_path)
                     if not os.path.islink(bns_path):
                         self.logger.info('Ready to create symlink for #%s instance of %s.'
                         %(ins['instance_index'], ins['application_name']))
                         os.symlink(container_path, bns_path)
                     elif not os.access(bns_path, os.W_OK):
                         self.logger.warn('Remove staled bns path %s!'%(bns_path))
                         os.remove(bns_path)<commit_msg>delete %s of func make_bns_path's return<commit_after># -*- coding: iso-8859-1 -*-

import yaml, codecs, sys, os.path, optparse

from pyinotify import ProcessEvent

class Process(ProcessEvent):
    def __init__(self, logger, config):
       self.logger = logger
       self.ins_file = config['instance_file']
       self.bns_base = config['bns_base']
       self.container_relative_path = config['container_relative_path']
       self.container_base_path = config['container_base_path']
       self.clusterid = config['cluster_id']
       self.clustersuf = config['cluster_suffix']

    def process_default(self, event):
        """
        override default processing method
        """
        self.logger.debug('Process::process_default')
        # call base method
        super(Process, self).process_default(event)
    
    def process_IN_MOVED_TO(self, event):
        """
        process 'IN_MOVED_TO' events 
        """
        self.logger.debug('Process::process_IN_MOVED_TO')
        super(Process, self).process_default(event)
        fl = yaml.load(file(self.ins_file,'rb').read())
        self.update_bns_link(fl)

    def make_bns_path(self, ins):
        """
        process make bns_path 
        """
        bns_offset = 10000*int(ins['application_db_id'])+int(ins['instance_index'])*10+int(self.clusterid)
        bns_node = ins['tags']['bns_node']
        bnsset = bns_node.split('-')
        bns_name = '%s-%s-%s'%(bnsset[0],bnsset[1],bnsset[2])
        bns_path = "%s/%s.%s.%s" %(self.bns_base, bns_offset,bns_name,self.clustersuf)
        return bns_path

    def update_bns_link(self, agent_data):
        """
        generate bns link for instances
        """
        self.logger.info('Starting checking the links.')
        raw_links = os.listdir(self.bns_base)
        current_links = set([])
        for lk in raw_links:
           current_links.add(self.bns_base + '/' + lk)

        required_links = set([])

        for ins in agent_data['instances']:
            if 'RUNNING' == ins['state']:
                 container_path = self.container_base_path + '/' + \
                     ins['warden_handle'] + '/%s' %(self.container_relative_path)
                 if  not os.path.exists(container_path):
                     self.logger.error('Container %s not exist, the data file is staled.' %(\
                     ins['warden_handle']))
                 else:
                     bns_path = self.make_bns_path(ins)
                     required_links.add(bns_path)
                     if not os.path.islink(bns_path):
                         self.logger.info('Ready to create symlink for #%s instance of %s.'
                         %(ins['instance_index'], ins['application_name']))
                         os.symlink(container_path, bns_path)
                     elif not os.access(bns_path, os.W_OK):
                         self.logger.warn('Remove staled bns path %s!'%(bns_path))
                         os.remove(bns_path)
{'fraction_non_alphanumeric': 0.12656091798852515, 'fraction_numerical': 0.005062436719541006, 'mean_word_length': 2.139300847457627, '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': '7428628', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1789, 'n_words': 319}