<commit_before>import shell
from gitFunctions import Commiter
import shouter


class ImportHandler:
    dateFormat = "yyyy-MM-dd HH:mm:ss"
    informationSeparator = "@@"

    def __init__(self, config):
        self.config = config
        self.git = Commiter()

    def initialize(self):
        config = self.config
        repo = config.repo
        shell.execute("lscm login -r %s -u %s -P %s" % (repo, config.user, config.password))
        shell.execute("lscm create workspace -r %s -s %s %s" % (repo, config.earlieststreamname, config.workspace))
        # implement logic here for replacing components by oldest baseline - scm set components
        config.collectstreamuuids()
        shouter.shout("Starting initial load of workspace")
        shell.execute("lscm load -r %s %s" % (repo, config.workspace))
        shouter.shout("Initial load of workspace finished")

    def acceptchangesfromstreams(self):
        streamuuids = self.config.streamuuids
        for streamuuid in streamuuids:
            streamname = self.config.streamnames[streamuuids.index(streamuuid)]
            self.git.branch(streamname)
            for componentBaseLineEntry in self.getbaselinesfromstream(streamuuid):
                self.acceptchangesfrombaseline(componentBaseLineEntry)
            self.git.pushbranch(streamname)

    def getbaselinesfromstream(self, stream):
        filename = self.config.getlogpath("StreamComponents_" + stream + ".txt")
        shell.execute("lscm --show-alias n --show-uuid y list components -v -r " + self.config.repo + " " + stream,
                      filename)
        componentbaselinesentries = []
        skippedfirstrow = False
        islinewithcomponent = 2
        component = None<commit_msg>added function for replacing components<commit_after>import shell
from gitFunctions import Commiter
import shouter


class ImportHandler:
    dateFormat = "yyyy-MM-dd HH:mm:ss"
    informationSeparator = "@@"

    def __init__(self, config):
        self.config = config
        self.git = Commiter()

    def initialize(self):
        config = self.config
        repo = config.repo
        shell.execute("lscm login -r %s -u %s -P %s" % (repo, config.user, config.password))
        shell.execute("lscm create workspace -r %s -s %s %s" % (repo, config.earlieststreamname, config.workspace))
        # implement logic here for replacing components by oldest baseline - scm set components
        config.collectstreamuuids()
        shouter.shout("Starting initial load of workspace")
        shell.execute("lscm load -r %s %s" % (repo, config.workspace))
        shouter.shout("Initial load of workspace finished")

    def acceptchangesfromstreams(self):
        streamuuids = self.config.streamuuids
        for streamuuid in streamuuids:
            streamname = self.config.streamnames[streamuuids.index(streamuuid)]
            self.git.branch(streamname)
            componentbaselineentries = self.getbaselinesfromstream(streamuuid)
            for componentBaseLineEntry in componentbaselineentries:
                self.acceptchangesfrombaseline(componentBaseLineEntry)
            self.git.pushbranch(streamname)
            self.setcomponentsofnextstreamtoworkspace(componentbaselineentries)

    def setcomponentsofnextstreamtoworkspace(self, componentbaselineentries):
        for componentbaselineentry in componentbaselineentries:
            replacecommand = "lscm set component -r %s - b % s %s stream %s %s"
            shell.execute(replacecommand %
                          (self.config.repo, componentbaselineentry.baseline, self.config.workspace,
                           self.config.mainStream, componentbaselineentry.component))

    def getbaselinesfromstream(self, stream):
        filename = self.config.getlogpath("StreamComponents_" + stream + ".txt")
        shell.execute("lscm --show-alias n --show-uuid y list components -v -r " + self.config.repo + " " + stream,
                      filename)
        componentbaselinesentries = []
        skippedfirstrow = False
        islinewithcomponent = 2
        component = None
{'fraction_non_alphanumeric': 0.09153038808884549, 'fraction_numerical': 0.000488162069807176, 'mean_word_length': 2.739051094890511, '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': '4463019', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1071, 'n_words': 275}