<commit_before>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

""" 
Contains information gathered during cooking, to be used mostly if the cook 
failed in order to resume using the same destdir
"""

import time

class BuildInfo(dict):

    def __init__(self, builddir):
	self.__builddir = builddir
	self.__infofile = builddir + "/conary-build-info"

    def read(self):
	# don't catch this error
	self.__fd = open(self.__infofile, "r")
	lines = self.__fd.readlines()
	self.__fd.close()
	for line in lines:
	    if line == '\n':
		continue
	    (key, value) = line.split(None, 1)
	    #handle macros.foo 
	    keys = key.split('.')
	    if len(keys) > 1:
		subdicts = keys[:-1]
		key = keys[-1]
		curdict = self
		for subdict in subdicts:
		    if subdict not in curdict:
			curdict[subdict] = {}
		    curdict = curdict[subdict]
		curdict[key] = value[:-1]
	    else:
		self[key] = value[:-1]

    def begin(self):
	self.__fd = open(self.__infofile, "w")
	tm = time.time()
	tmstr = time.asctime()
	self.start = "%s (%s)" % (tm, tmstr)

    def write(self, str):
	self.__fd.write(str)
	self.__fd.flush()

    def stop(self):
	tm = time.time()
	tmstr = time.asctime()
	self.end = "%s (%s)" % (tm, tmstr)
	self.__fd.close()

    def __setattr__(self, name, value):
        # Note that using buildinfo.foo = y
        # causes foo to be written to file, while using buildinfo['foo'] = y
        # does not
	if not name.startswith('_BuildInfo_'):
	    self.write('%s %s\n' % (name,value))
	self[name] = value

    def __getattr__(self, name):
	return self[name] <commit_msg>escape \n in buildinfo output<commit_after>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

""" 
Contains information gathered during cooking, to be used mostly if the cook 
failed in order to resume using the same destdir
"""

import time

class BuildInfo(dict):

    def __init__(self, builddir):
	self.__builddir = builddir
	self.__infofile = builddir + "/conary-build-info"

    def read(self):
	# don't catch this error
	self.__fd = open(self.__infofile, "r")
	lines = self.__fd.readlines()
	self.__fd.close()
	for line in lines:
	    if line == '\n':
		continue
	    (key, value) = line.split(None, 1)
	    #handle macros.foo 
	    keys = key.split('.')
	    if len(keys) > 1:
		subdicts = keys[:-1]
		key = keys[-1]
		curdict = self
		for subdict in subdicts:
		    if subdict not in curdict:
			curdict[subdict] = {}
		    curdict = curdict[subdict]
                #unescape \\ and \n
                value = value.replace('\\\\', '\0')
                value = value.replace('\\n', '\n')
                value = value.replace('\0', '\\')
		curdict[key] = value[:-1]
	    else:
                #unescape \\ and \n
                value = value.replace('\\\\', '\0')
                value = value.replace('\\n', '\n')
                value = value.replace('\0', '\\')
		self[key] = value[:-1]

    def begin(self):
	self.__fd = open(self.__infofile, "w")
	tm = time.time()
	tmstr = time.asctime()
	self.start = "%s (%s)" % (tm, tmstr)

    def write(self, str):
	self.__fd.write(str)
	self.__fd.flush()

    def stop(self):
	tm = time.time()
	tmstr = time.asctime()
	self.end = "%s (%s)" % (tm, tmstr)
	self.__fd.close()

    def __setattr__(self, name, value):
        # Note that using buildinfo.foo = y
        # causes foo to be written to file, while using buildinfo['foo'] = y
        # does not
	if not name.startswith('_BuildInfo_'):
            #escape \\ and \n
            value = value.replace('\\', '\\\\')
            value = value.replace('\n', '\\n')
	    self.write('%s %s\n' % (name,value))
	self[name] = value

    def __getattr__(self, name):
	return self[name] 
{'fraction_non_alphanumeric': 0.1352554589781641, 'fraction_numerical': 0.007631969472122111, 'mean_word_length': 2.7987117552334944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3678857', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1537, 'n_words': 514}