<commit_before>
import ConfigParser
import sys
import time
import logging
import logging.handlers
import os
import signal
import pwd
import shutil

from campus_factory.ClusterStatus import ClusterStatus
from campus_factory.util.ExternalCommands import RunExternal
from campus_factory.OfflineAds.OfflineAds import OfflineAds
from campus_factory.util.DaemonWrangler import DaemonWrangler
from campus_factory.Cluster import *
from campus_factory.util.StreamToLogger import StreamToLogger
from campus_factory.util.CampusConfig import get_option, set_config_file, set_option

BOSCO_CLUSTERLIST = "~/.bosco/.clusterlist"

class Factory:
    """
    The main class of the factory.  Designed to be run inside the condor scheduler.
    
    @author: <NAME> (<EMAIL>)
    
    """
    def __init__(self, options):
        """
        Initialization function.
        
        @param options: A set of options in the form of an options parser
                Required options: config - location of configuration File
        """
        
        self.options = options

        
    
    def Intialize(self):
        """
        
        Function to initialize the factory's variables such as configuration
        and logging
        """
        # Set the sighup signal handler
        signal.signal(signal.SIGHUP, self.Intialize)
        
        # Read in the configuration file
        self.config_file = self.options.config
        files_read = set_config_file(self.config_file)

        # check if no files read in
        if len(files_read) < 1:
            sys.stderr.write("No configuration files found.  Location = %s\n" % self.config_file)
            sys.exit(1)
            
        self._SetLogging()
        
        if os.getuid() == 0 or get_option("factory_user"):
            logging.info("Detected that factory should change user")
            self._DropPriv()
       
        if  get_option("useoffline", "false").lower() == "true":
            self.UseOffline = True
        else:
            self.UseOffline = False
        
        self.cluster_list = []
        # Get the cluster lists
        if get_option("clusterlist", "") is not "":
            logging.debug("Using the cluster list in the campus factory configuration.")
            for cluster_id in get_option("clusterlist").split(','):
                self.cluster_list.append(Cluster(cluster_id, useOffline = self.UseOffline))
        else:
            # Check for the bosco cluster command
            (stdout, stderr) = RunExternal("bosco_cluster -l")
            if len(stdout) != 0 and stdout is not "No clusters configured":
                logging.debug("Using the cluster list installed with BOSCO")
                for cluster_id in stdout.split("\n"):
                    if len(cluster_id) > 0 and cluster_id != "":
                        self.cluster_list.append(Cluster(cluster_id, useOffline = self.UseOffline))
            else:
                # Initialize as empty, which infers to submit 'here'
                self.cluster_list = [ Cluster(get_option("CONDOR_HOST"), useOffline = self.UseOffline) ]
        
        # Tar up the executables
        wrangler = DaemonWrangler()
        wrangler.Package()
            

    def _DropPriv(self):
        factory_user = get_option("factory_user")
        current_uid = os.getuid()
        if factory_user is None:
            logging.warning("factory_user is not set in campus factory config file")
            if get_option("CONDOR_IDS"):<commit_msg>do not do DaemonWrangler during glidein packaging<commit_after>
import ConfigParser
import sys
import time
import logging
import logging.handlers
import os
import signal
import pwd
import shutil

from campus_factory.ClusterStatus import ClusterStatus
from campus_factory.util.ExternalCommands import RunExternal
from campus_factory.OfflineAds.OfflineAds import OfflineAds
from campus_factory.util.DaemonWrangler import DaemonWrangler
from campus_factory.Cluster import *
from campus_factory.util.StreamToLogger import StreamToLogger
from campus_factory.util.CampusConfig import get_option, set_config_file, set_option

BOSCO_CLUSTERLIST = "~/.bosco/.clusterlist"

class Factory:
    """
    The main class of the factory.  Designed to be run inside the condor scheduler.
    
    @author: <NAME> (<EMAIL>)
    
    """
    def __init__(self, options):
        """
        Initialization function.
        
        @param options: A set of options in the form of an options parser
                Required options: config - location of configuration File
        """
        
        self.options = options

        
    
    def Intialize(self):
        """
        
        Function to initialize the factory's variables such as configuration
        and logging
        """
        # Set the sighup signal handler
        signal.signal(signal.SIGHUP, self.Intialize)
        
        # Read in the configuration file
        self.config_file = self.options.config
        files_read = set_config_file(self.config_file)

        # check if no files read in
        if len(files_read) < 1:
            sys.stderr.write("No configuration files found.  Location = %s\n" % self.config_file)
            sys.exit(1)
            
        self._SetLogging()
        
        if os.getuid() == 0 or get_option("factory_user"):
            logging.info("Detected that factory should change user")
            self._DropPriv()
       
        if  get_option("useoffline", "false").lower() == "true":
            self.UseOffline = True
        else:
            self.UseOffline = False
        
        self.cluster_list = []
        # Get the cluster lists
        if get_option("clusterlist", "") is not "":
            logging.debug("Using the cluster list in the campus factory configuration.")
            for cluster_id in get_option("clusterlist").split(','):
                self.cluster_list.append(Cluster(cluster_id, useOffline = self.UseOffline))
        else:
            # Check for the bosco cluster command
            (stdout, stderr) = RunExternal("bosco_cluster -l")
            if len(stdout) != 0 and stdout is not "No clusters configured":
                logging.debug("Using the cluster list installed with BOSCO")
                for cluster_id in stdout.split("\n"):
                    if len(cluster_id) > 0 and cluster_id != "":
                        self.cluster_list.append(Cluster(cluster_id, useOffline = self.UseOffline))
            else:
                # Initialize as empty, which infers to submit 'here'
                self.cluster_list = [ Cluster(get_option("CONDOR_HOST"), useOffline = self.UseOffline) ]
        
        # Tar up the executables
        # N.B. This is not generally needed, and causes failures
        # when BOSCO is shared among multiple uids.
        # - <EMAIL>
        if false:
            wrangler = DaemonWrangler()
            wrangler.Package()
            

    def _DropPriv(self):
        factory_user = get_option("factory_user")
        current_uid = os.getuid()
        if factory_user is None:
            logging.warning("factory_user is not set in campus factory config file")
            if get_option("CONDOR_IDS"):
{'fraction_non_alphanumeric': 0.08065190137902215, 'fraction_numerical': 0.001392951664577239, 'mean_word_length': 2.213965980304387, 'pattern_counts': {'":': 8, '<': 10, '<?xml version=': 0, '>': 10, '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': '138182', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1895, 'n_words': 564}