<commit_before>#!/usr/bin/python

import io
import os

import env
from constants import Systems, BashInputFiles, BashOutputFiles

def writeHeader(fileName, fileBuffer):
  fileBuffer.write(unicode("#!/bin/bash\n# ~/" + fileName + ": executed by bash(1) for non-login shells.\n# This file was generated by a script. Do not edit manually!\n"))

def writeInputFileContents(fileName, fileBuffer):
  with open(env.inputFilesDir + fileName) as inputFile:
    print "\tSourcing input file " + fileName
    for line in inputFile:
      fileBuffer.write(unicode(line))

def writeOutputFile(filePath, fileBuffer):
  print "\tWriting output file " + filePath
  with open(filePath, 'w') as outputFile:
    outputFile.write(fileBuffer.getvalue())

def compileBashFile(platform):
  if platform is Systems.DARWIN.value:
    bashFile = BashOutputFiles.BASH_PROFILE.value
    bashDotFile = BashOutputFiles.DOT_BASH_PROFILE.value
    bashPlatformFile = BashInputFiles.BASH_MAC.value
  elif platform is Systems.LINUX.value:
    bashFile = BashOutputFiles.BASHRC.value
    bashDotFile = BashOutputFiles.DOT_BASHRC.value
    bashPlatformFile = BashInputFiles.BASH_LINUX.value
  print "Compiling file: " + bashFile
  with io.StringIO() as fileBuffer:
    writeHeader(bashDotFile, fileBuffer)
    writeInputFileContents(BashInputFiles.BASH_COMMON.value, fileBuffer)
    writeInputFileContents(bashPlatformFile, fileBuffer)
    writeOutputFile(env.outputFilesDir + bashFile, fileBuffer)
    if env.platform is platform:
      if os.path.isfile(env.inputFilesDir + BashInputFiles.BASH_PRIVATE.value):
	writeInputFileContents(BashInputFiles.BASH_PRIVATE.value, fileBuffer)
	writeOutputFile(env.homeDir + bashDotFile, fileBuffer)
      else:
	print BashInputFiles.BASH_PRIVATE.value + " is not present. Skipping..."
    print "File completed."

def compileBashProfile():
  compileBashFile(Systems.DARWIN.value)
def compileBashrc():
  compileBashFile(Systems.LINUX.value)

def compileBashFiles():
  compileBashProfile()
  compileBashrc()<commit_msg>Always write bash dot-file in ~. Don't use 'is' for string comparison.<commit_after>#!/usr/bin/python

import io
import os

import env
from constants import Systems, BashInputFiles, BashOutputFiles

def writeHeader(fileName, fileBuffer):
  fileBuffer.write(unicode("#!/bin/bash\n# ~/" + fileName + ": executed by bash(1) for non-login shells.\n# This file was generated by a script. Do not edit manually!\n"))

def writeInputFileContents(fileName, fileBuffer):
  with open(env.inputFilesDir + fileName) as inputFile:
    print "\tSourcing input file " + fileName
    for line in inputFile:
      fileBuffer.write(unicode(line))

def writeOutputFile(filePath, fileBuffer):
  print "\tWriting output file " + filePath
  with open(filePath, 'w') as outputFile:
    outputFile.write(fileBuffer.getvalue())

def compileBashFile(platform):
  if platform == Systems.DARWIN.value:
    bashFile = BashOutputFiles.BASH_PROFILE.value
    bashDotFile = BashOutputFiles.DOT_BASH_PROFILE.value
    bashPlatformFile = BashInputFiles.BASH_MAC.value
  elif platform == Systems.LINUX.value:
    bashFile = BashOutputFiles.BASHRC.value
    bashDotFile = BashOutputFiles.DOT_BASHRC.value
    bashPlatformFile = BashInputFiles.BASH_LINUX.value
  print "Compiling file: " + bashFile
  with io.StringIO() as fileBuffer:
    writeHeader(bashDotFile, fileBuffer)
    writeInputFileContents(BashInputFiles.BASH_COMMON.value, fileBuffer)
    writeInputFileContents(bashPlatformFile, fileBuffer)
    writeOutputFile(env.outputFilesDir + bashFile, fileBuffer)
    if env.platform == platform:
      if os.path.isfile(env.inputFilesDir + BashInputFiles.BASH_PRIVATE.value):
	writeInputFileContents(BashInputFiles.BASH_PRIVATE.value, fileBuffer)
      else:
	print "\t" + BashInputFiles.BASH_PRIVATE.value + " is not present. Skipping..."
      writeOutputFile(env.homeDir + bashDotFile, fileBuffer)
    print "File completed."

def compileBashProfile():
  compileBashFile(Systems.DARWIN.value)
def compileBashrc():
  compileBashFile(Systems.LINUX.value)

def compileBashFiles():
  compileBashProfile()
  compileBashrc()
{'fraction_non_alphanumeric': 0.09564370893161353, 'fraction_numerical': 0.0004867364322219518, 'mean_word_length': 5.0, 'pattern_counts': {'":': 2, '<': 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': '1736438', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1275, 'n_words': 283}