<commit_before>var fs		= require('fs');
var path	= require('path');
var sys		= require('sys');

exports.mounts = function( ){
	var returnObj = Array( );
	var currentMounts	= fs.readFileSync( "/etc/mtab", 'utf8' ).replace( RegExp( '\n$' ), '' ).split( "\n" );
	for( var x=0; x<currentMounts.length; x++ ){
		var currentMountParts	= currentMounts[x].split( " " );
		returnObj[x]		= new Array( );
		returnObj[x].device	= currentMountParts[0];		// This dot is ugly, and could potentially cause problems.
		returnObj[x].mountpoint	= currentMountParts[1].replace( RegExp( '.040' ), ' ' );
		returnObj[x].fs		= currentMountParts[2];
		returnObj[x].options	= currentMountParts[3];
	}
	
	return returnObj;
}

exports.ps = function( ){
	var returnArray	= Array( );
	try{
		var procContents	= fs.readdirSync( "/proc" );
		for( var x=0; x<procContents.length; x++ ){
			if( parseInt( procContents[x] ) ){ 
				// procContents[x] is a pid number..
				returnArray.push( getPidDetails( procContents[x] ) );
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.ps.pid	= function( pidToGet ){
	return getPidDetails( pidToGet );
}

function getPidDetails( pidNumber ){
	var returnArray = Array( );
	try{
		var statusLines	= fs.readFileSync( "/proc/" + pidNumber + "/status", 'utf8').split( "\n" );
		for( var x=0; x<statusLines.length; x++ ){
			var tmpSplit		= statusLines[x].split( ":" );
			// This if statement takes care of trailing \n's
			if( tmpSplit.length > 1 ){
				var tmpKey		= tmpSplit[0].toLowerCase( );
				// The status gives more number than we care about, seperated by tabs.. remove them.
				if( tmpKey == 'uid' || tmpKey == 'gid' ){
					returnArray[tmpKey]	= tmpSplit[1].trim().replace( RegExp( "\t.*" ), '' );
				}else{
					returnArray[tmpKey]	= tmpSplit[1].trim( );
				}
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.acpi	= function( ){

}

exports.acpi.batteries = function( ){
	var returnArray	= Array( );
	try{
		var batteries	= fs.readdirSync( "/proc/acpi/battery/", 'utf8' );
		for( var x=0; x<batteries.length; x++ ){
			var batteryName		= batteries[x];
			returnArray[x]		= new Array( );
		
			var batteryDetails	= getBatteryDetails( batteryName );
			batteryDetails['name']	= batteryName;

			returnArray[x]	= batteryDetails;
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.acpi.battery = function( batteryName ){
	return getBatteryDetails( batteryName );
}

function getBatteryDetails( batteryName ){
	var returnArray	= Array( );
	try{ 
		var batteryStateLines	= fs.readFileSync( "/proc/acpi/battery/" + batteryName + "/state", 'utf8' ).split( "\n" );
		for( var x=0; x<batteryStateLines.length; x++ ){
			var tmpSplit	= batteryStateLines[x].split( ":" );
			if( tmpSplit.length > 1 ){
				var tmpKey		= tmpSplit[0].replace( RegExp( " " ), "_" ).trim( );
				returnArray[tmpKey]	= tmpSplit[1].trim( );
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.sysctl = function( args ){
	var returnArray	= Array( );
	try{
		return arrayToObj( recurseDirReturnArray( "/proc/sys/" ), "returnObj" );

	}catch( err ){
		console.log( "ERROR: " + err );
		return false;
	}
}

function arrayToObj( arrayInput, runningObjString ){
	var returnObj = Object();

	for( var tmpArray in arrayInput ){
		if( arrayInput[tmpArray].constructor == Array ){
			var safeTmpArray	= tmpArray.replace( RegExp( /-/g ), '_' ).replace( RegExp( /[0-9]/g ), '_' );
			var evalString	= "returnObj." + safeTmpArray + " = [ {" + arrayToObj( arrayInput[tmpArray], runningObjString+"."+safeTmpArray ) + " } ]";
			console.log( evalString );
		}else{
			var safeTmpArray	= tmpArray.replace( RegExp( /-/g ), '_' ).replace( RegExp( /[0-9]/g ), '_' );
			var evalString	= runningObjString + "." + safeTmpArray + " = function( ){ return " + arrayInput[tmpArray].toString().replace( RegExp( "\n" ), '' ) + " }";
			console.log( evalString );
		}
	} 
	return returnObj;
}

function recurseDirReturnArray( directoryToRecurse ){
	var returnArray	= Array( );
	try{
		var directoryContents	= fs.readdirSync( directoryToRecurse, 'utf8' );
		for( var x=0; x<directoryContents.length; x++ ){
			var tmpStatObj	= fs.lstatSync( path.join( directoryToRecurse, directoryContents[x] ) );
			if( tmpStatObj.isDirectory() ){
				returnArray[directoryContents[x]]	= recurseDirReturnArray( path.join( directoryToRecurse, directoryContents[x] ) );
			}else{
				// Open the file for reading..
				var tmpFileContent	= fs.readFileSync( path.join( directoryToRecurse, directoryContents[x] ), 'utf8' );<commit_msg>Sysctl obj works?<commit_after>var fs		= require('fs');
var path	= require('path');
var sys		= require('sys');

exports.mounts = function( ){
	var returnObj = Array( );
	var currentMounts	= fs.readFileSync( "/etc/mtab", 'utf8' ).replace( RegExp( '\n$' ), '' ).split( "\n" );
	for( var x=0; x<currentMounts.length; x++ ){
		var currentMountParts	= currentMounts[x].split( " " );
		returnObj[x]		= new Array( );
		returnObj[x].device	= currentMountParts[0];		// This dot is ugly, and could potentially cause problems.
		returnObj[x].mountpoint	= currentMountParts[1].replace( RegExp( '.040' ), ' ' );
		returnObj[x].fs		= currentMountParts[2];
		returnObj[x].options	= currentMountParts[3];
	}
	
	return returnObj;
}

exports.ps = function( ){
	var returnArray	= Array( );
	try{
		var procContents	= fs.readdirSync( "/proc" );
		for( var x=0; x<procContents.length; x++ ){
			if( parseInt( procContents[x] ) ){ 
				// procContents[x] is a pid number..
				returnArray.push( getPidDetails( procContents[x] ) );
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.ps.pid	= function( pidToGet ){
	return getPidDetails( pidToGet );
}

function getPidDetails( pidNumber ){
	var returnArray = Array( );
	try{
		var statusLines	= fs.readFileSync( "/proc/" + pidNumber + "/status", 'utf8').split( "\n" );
		for( var x=0; x<statusLines.length; x++ ){
			var tmpSplit		= statusLines[x].split( ":" );
			// This if statement takes care of trailing \n's
			if( tmpSplit.length > 1 ){
				var tmpKey		= tmpSplit[0].toLowerCase( );
				// The status gives more number than we care about, seperated by tabs.. remove them.
				if( tmpKey == 'uid' || tmpKey == 'gid' ){
					returnArray[tmpKey]	= tmpSplit[1].trim().replace( RegExp( "\t.*" ), '' );
				}else{
					returnArray[tmpKey]	= tmpSplit[1].trim( );
				}
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.acpi	= function( ){

}

exports.acpi.batteries = function( ){
	var returnArray	= Array( );
	try{
		var batteries	= fs.readdirSync( "/proc/acpi/battery/", 'utf8' );
		for( var x=0; x<batteries.length; x++ ){
			var batteryName		= batteries[x];
			returnArray[x]		= new Array( );
		
			var batteryDetails	= getBatteryDetails( batteryName );
			batteryDetails['name']	= batteryName;

			returnArray[x]	= batteryDetails;
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.acpi.battery = function( batteryName ){
	return getBatteryDetails( batteryName );
}

function getBatteryDetails( batteryName ){
	var returnArray	= Array( );
	try{ 
		var batteryStateLines	= fs.readFileSync( "/proc/acpi/battery/" + batteryName + "/state", 'utf8' ).split( "\n" );
		for( var x=0; x<batteryStateLines.length; x++ ){
			var tmpSplit	= batteryStateLines[x].split( ":" );
			if( tmpSplit.length > 1 ){
				var tmpKey		= tmpSplit[0].replace( RegExp( " " ), "_" ).trim( );
				returnArray[tmpKey]	= tmpSplit[1].trim( );
			}
		}
	}catch( err ){
		return false;
	}

	return returnArray;
}

exports.sysctl = function( args ){
	var returnArray	= Array( );
	try{
		return arrayToObj( recurseDirReturnArray( "/proc/sys/" ) );

	}catch( err ){
		console.log( "ERROR: " + err );
		return false;
	}
}

function toGoodSysctlValue( objToMakeGood ){
	if( typeof objToMakeGood == 'string' ){
		return '"' + objToMakeGood.replace( RegExp( "\\n", "g" ), "" ) + '"';
	}else if( typeof objToMakeGood == 'int' ){
		return objToMakeGood;
	}else{
		return objToMakeGood;
	} 
}

function arrayToObj( arrayInput, runningObjString, runningReturnObj ){

	if( !runningObjString ){
		runningObjString = "runningReturnObj";
	}

	if( !runningReturnObj ){
		var runningReturnObj = Object();
	}

	for( var tmpArray in arrayInput ){
		if( arrayInput[tmpArray].constructor == Array ){
			var safeTmpArray	= tmpArray.replace( RegExp( /-/g ), '_' ).replace( RegExp( /[0-9]/g ), '_' );


			var tmpEvalString	= runningObjString + "." + safeTmpArray + " = function( ){ }";
			console.log( tmpEvalString );
			eval( tmpEvalString );

			arrayToObj( arrayInput[tmpArray], runningObjString + "." + safeTmpArray, runningReturnObj );
		}else{
			var safeTmpArray	= tmpArray.replace( RegExp( /-/g ), '_' ).replace( RegExp( /[0-9]/g ), '_' );
			var evalString	= runningObjString + "." + safeTmpArray + " = function( ){ return " + toGoodSysctlValue(arrayInput[tmpArray] ) + " }";
			console.log( evalString );
			eval( evalString );
		}
	} 
	return runningReturnObj;
}

function recurseDirReturnArray( directoryToRecurse ){
	var returnArray	= Array( );
	try{
		var directoryContents	= fs.readdirSync( directoryToRecurse, 'utf8' );
		for( var x=0; x<directoryContents.length; x++ ){
			var tmpStatObj	= fs.lstatSync( path.join( directoryToRecurse, directoryContents[x] ) );
			if( tmpStatObj.isDirectory() ){
				returnArray[directoryContents[x]]	= recurseDirReturnArray( path.join( directoryToRecurse, directoryContents[x] ) );
			}else{
				// Open the file for reading..
				var tmpFileContent	= fs.readFileSync( path.join( directoryToRecurse, directoryContents[x] ), 'utf8' );
{'fraction_non_alphanumeric': 0.1661980631052796, 'fraction_numerical': 0.006248047485160888, 'mean_word_length': 3.797202797202797, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 7, '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': '1114834', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3384, 'n_words': 761}