<commit_before>'''
    Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

    WSO2 Inc. licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file except
    in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
'''
import core.Manager as Manager
from custom.publishers.TemperaturePublisher import TemperaturePublisher
import time
import threading
import ConfigParser
import os
import pkgutil
import sys
import argparse

class Agent:

    def start(self):
        self.load_manager()
        arguments = self.pass_arguments()
        if(arguments.dmURL):
            self.configure_dm_url(arguments.dmURL)
        else:
            self.configure_dm_url("https://localhost:9453/")

        if(arguments.token):
            # if the token doesn't exists - ask the agent to enroll the device
            self.manager.enroll(self, arguments.token)
        else:
            enroll = self.agent_params['enroll']
            if(enroll):            
                print "Device was enrolled to Device Manager previously"
            else:
                self.manager.enroll(self)   
        self.add_process(TemperaturePublisher())
        self.execute()

    def pass_arguments(self):
        '''
            Parse command line arguments for the token
        '''
        parser = argparse.ArgumentParser()
        parser.add_argument("--token")
        parser.add_argument("--dmURL")
        args = parser.parse_args()
        # args.token = "<PASSWORD>"
        return args

    def __init__(self):
        '''
            Parse config files and setup agent variables
        '''
        self.config = ConfigParser.ConfigParser()
        self.config.read("config.conf")

        self.process_list = []
        self.agent_params = {}
        self.configs = {}
        # Runtime configs
        self.agent_params['timer'] = self.config.get('agent', 'timer')
        self.agent_params['timer_interval'] = float(self.config.get('agent', 'timer_interval'))
        self.agent_params['autoload'] = self.config.get('agent', 'autoload')

        self.configs['deviceId'] = device_id()

        # Security code
        if(self.config.has_section('security')):
            self.agent_params['access_token'] = self.config.get('security', 'access_token')
            self.agent_params['refresh_token'] = self.config.get('security', 'refresh_token')
            self.agent_params['enroll'] = self.config.get('security', 'enroll')
        else:
            self.agent_params['enroll'] = False

    def configure_dm_url(self, dm_url):
        self.manager.configure_dm_url(dm_url)

    def load_manager(self):
        '''
            Load the Platform specific Device Manager implementation using the core Device Manager
        '''
        #self.manager = RaspberryPiManager()
        self.manager = Manager.get_device_manager()
        if(self.manager==None):
            raise Exception("No Device Manager found for Platform")

    def add_process(self, process):
        self.process_list.append(process)
        print "Adding process " + str(process)

    def execute(self):
        '''
        The execution will run periodically based on the timer property in
        the config.conf file
        '''
        # print len(self.process_list)
        for process in self.process_list:
            print "Executing process"
            process.run()
<commit_msg>Fixed<commit_after>'''
    Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

    WSO2 Inc. licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file except
    in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
'''
import core.Manager as Manager
from custom.publishers.TemperaturePublisher import TemperaturePublisher
import time
import threading
import ConfigParser
import os
import pkgutil
import sys
import argparse

class Agent:

    def start(self):
        self.load_manager()
        arguments = self.pass_arguments()
        if(arguments.dmURL):
            self.configure_dm_url(arguments.dmURL)
        else:
            self.configure_dm_url("https://localhost:9453/")

        if(arguments.token):
            # if the token doesn't exists - ask the agent to enroll the device
            self.manager.enroll(self, arguments.token)
        else:
            enroll = self.agent_params['enroll']
            if(enroll):            
                print "Device was enrolled to Device Manager previously"
            else:
                self.manager.enroll(self)   
        self.add_process(TemperaturePublisher())
        self.execute()

    def pass_arguments(self):
        '''
            Parse command line arguments for the token
        '''
        parser = argparse.ArgumentParser()
        parser.add_argument("--token")
        parser.add_argument("--dmURL")
        args = parser.parse_args()
        # args.token = "<PASSWORD>"
        return args

    def __init__(self):
        '''
            Parse config files and setup agent variables
        '''
        self.config = ConfigParser.ConfigParser()
        self.config.read("config.conf")

        self.process_list = []
        self.agent_params = {}
        self.configs = {}
        # Runtime configs
        self.agent_params['timer'] = self.config.get('agent', 'timer')
        self.agent_params['timer_interval'] = float(self.config.get('agent', 'timer_interval'))
        self.agent_params['autoload'] = self.config.get('agent', 'autoload')

        self.configs['deviceId'] = self.config.get('agent', 'enrollment')

        # Security code
        if(self.config.has_section('security')):
            self.agent_params['access_token'] = self.config.get('security', 'access_token')
            self.agent_params['refresh_token'] = self.config.get('security', 'refresh_token')
            self.agent_params['enroll'] = self.config.get('security', 'enroll')
        

    def configure_dm_url(self, dm_url):
        self.manager.configure_dm_url(dm_url)

    def load_manager(self):
        '''
            Load the Platform specific Device Manager implementation using the core Device Manager
        '''
        #self.manager = RaspberryPiManager()
        self.manager = Manager.get_device_manager()
        if(self.manager==None):
            raise Exception("No Device Manager found for Platform")

    def add_process(self, process):
        self.process_list.append(process)
        print "Adding process " + str(process)

    def execute(self):
        '''
        The execution will run periodically based on the timer property in
        the config.conf file
        '''
        # print len(self.process_list)
        for process in self.process_list:
            print "Executing process"
            process.run()

{'fraction_non_alphanumeric': 0.09897879025923016, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 2.419427036705461, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '2983769', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1978, 'n_words': 566}