<commit_before>#!/usr/bin/python
#####################################################################################################################################
# THIS FILE CONTAINS ALL THE FUNCTIONS USED IN PYTHON TEST FILES... HANDLE WITH CARE...
# FOR ANY QUERY - V-<EMAIL>
# DO NOT DELETE ANY STATEMENT FROM THE FUNCTION EVEN IF IT IS COMMENTED!!! BECAUSE I'M TRACKING, WHAT I'M DOING...
#####################################################################################################################################

import subprocess
import logging
import string
import os
import time
import os.path
import array
import linecache
import sys
import re

try:
    import commands
except ImportError:
    import subprocess as commands

py_ver_str = sys.version
#print(sys.version)

#THIS LOG WILL COLLECT ALL THE LOGS THAT ARE RUN WHILE THE TEST IS GOING ON...
RunLog = logging.getLogger("RuntimeLog : ")
WRunLog = logging.FileHandler('Runtime.log','w')
RunFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
WRunLog.setFormatter(RunFormatter)
RunLog.setLevel(logging.DEBUG)
RunScreen = logging.StreamHandler()
RunScreen.setFormatter(RunFormatter)
#RunLog.addHandler(RunScreen)
RunLog.addHandler(WRunLog)

#This will collect Result from every test case :
ResultLog = logging.getLogger("Result : ")
WResultLog = logging.FileHandler('Summary.log','w')
#ResultFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
ResultFormatter = logging.Formatter('%(message)s')
WResultLog.setFormatter(ResultFormatter)
ResultLog.setLevel(logging.DEBUG)
ResultScreen = logging.StreamHandler()
ResultScreen.setFormatter(ResultFormatter)
#ResultLog.addHandler(ResultScreen)
ResultLog.addHandler(WResultLog)

def UpdateRepos(current_distro):
    RunLog.info ("\nUpdating the repositoriy information...")
    rst, updaterepo_cmd = GetUpdateRepoCmdWithDistroType(current_distro)
    if rst:
        RunUpdate(updaterepo_cmd + " update")
    else:
        RunLog.error("Repo upgradation failed on:"+current_distro)
        return False

    RunLog.info ("Updating the repositoriy information... [done]")
    return True

def GetUpdateRepoCmdWithDistroType(current_distro):
    if (current_distro.find("ubuntu") != -1) or (current_distro.find("debian") != -1): 
        return (True, "apt-get")
    elif (current_distro.find("rhel") != -1) or (current_distro.find("Oracle") != -1) or (current_distro.find('centos') != -1):
        return (True, "yum -y")
    elif (current_distro.find("opensuse") != -1) or (current_distro.find("SUSE") != -1) or (current_distro.find("sles") != -1):
        return (True, "zypper --non-interactive --gpg-auto-import-keys")
    else:
        return (False, "")


def DownloadUrl(url, destination_folder, output_file=None):
    cmd = "wget -P "+destination_folder+" "+url+ " 2>&1"
    if output_file is not None:
        cmd = "wget {0} -O {1} 2>&1".format(url, output_file)

    rtrn = Run(cmd)

    if(rtrn.rfind("wget: command not found") != -1):
        InstallPackage("wget")
        rtrn = Run(cmd)

    if( rtrn.rfind("100%") != -1):
        return True
    else:
        RunLog.info (rtrn)
        return False

def DetectDistro():
    distribution = 'unknown'
    version = 'unknown'

    RunLog.info("Detecting Distro ")
    output = Run("cat /etc/*-release")<commit_msg>Revert "refine func to get update repo command against distro"<commit_after>#!/usr/bin/python
#####################################################################################################################################
# THIS FILE CONTAINS ALL THE FUNCTIONS USED IN PYTHON TEST FILES... HANDLE WITH CARE...
# FOR ANY QUERY - <EMAIL>
# DO NOT DELETE ANY STATEMENT FROM THE FUNCTION EVEN IF IT IS COMMENTED!!! BECAUSE I'M TRACKING, WHAT I'M DOING...
#####################################################################################################################################

import subprocess
import logging
import string
import os
import time
import os.path
import array
import linecache
import sys
import re

try:
    import commands
except ImportError:
    import subprocess as commands

py_ver_str = sys.version
print(sys.version)

#THIS LOG WILL COLLECT ALL THE LOGS THAT ARE RUN WHILE THE TEST IS GOING ON...
RunLog = logging.getLogger("RuntimeLog : ")
WRunLog = logging.FileHandler('Runtime.log','w')
RunFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
WRunLog.setFormatter(RunFormatter)
RunLog.setLevel(logging.DEBUG)
RunScreen = logging.StreamHandler()
RunScreen.setFormatter(RunFormatter)
#RunLog.addHandler(RunScreen)
RunLog.addHandler(WRunLog)

#This will collect Result from every test case :
ResultLog = logging.getLogger("Result : ")
WResultLog = logging.FileHandler('Summary.log','w')
#ResultFormatter = logging.Formatter('%(asctime)s : %(levelname)s : %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
ResultFormatter = logging.Formatter('%(message)s')
WResultLog.setFormatter(ResultFormatter)
ResultLog.setLevel(logging.DEBUG)
ResultScreen = logging.StreamHandler()
ResultScreen.setFormatter(ResultFormatter)
#ResultLog.addHandler(ResultScreen)
ResultLog.addHandler(WResultLog)

def UpdateRepos(current_distro):
    RunLog.info ("\nUpdating the repositoriy information...")
    if (current_distro.find("ubuntu") != -1) or (current_distro.find("debian") != -1): 
        #method 'RunUpdate': fix deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe
        RunUpdate("apt-get update")
    elif (current_distro.find("rhel") != -1) or (current_distro.find("Oracle") != -1) or (current_distro.find('centos') != -1):
        RunUpdate("yum -y update")
    elif (current_distro.find("opensuse") != -1) or (current_distro.find("SUSE") != -1) or (current_distro.find("sles") != -1):
        RunUpdate("zypper --non-interactive --gpg-auto-import-keys update")
    else:
        RunLog.info("Repo upgradation failed on:"+current_distro)
        return False

    RunLog.info ("Updating the repositoriy information... [done]")
    return True

def DownloadUrl(url, destination_folder, output_file=None):
    cmd = "wget -P "+destination_folder+" "+url+ " 2>&1"
    if output_file is not None:
        cmd = "wget {0} -O {1} 2>&1".format(url, output_file)

    rtrn = Run(cmd)

    if(rtrn.rfind("wget: command not found") != -1):
        InstallPackage("wget")
        rtrn = Run(cmd)

    if( rtrn.rfind("100%") != -1):
        return True
    else:
        RunLog.info (rtrn)
        return False

def DetectDistro():
    distribution = 'unknown'
    version = 'unknown'

    RunLog.info("Detecting Distro ")
    output = Run("cat /etc/*-release")
{'fraction_non_alphanumeric': 0.20810014727540502, 'fraction_numerical': 0.005596465390279823, 'mean_word_length': 4.668614357262103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5192114', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2075, 'n_words': 522}