<commit_before>import subprocess

from django.conf import settings
from core.models import LivySession, SupervisorRPCClient


def combine_settings(request):
	
	'''
	Make some settings variables available to all templates
	'''

	return {
		'APP_HOST': settings.APP_HOST,		
		'DPLA_API_KEY': settings.DPLA_API_KEY,
		'OAI_RESPONSE_SIZE':settings.OAI_RESPONSE_SIZE,
		'COMBINE_OAI_IDENTIFIER':settings.COMBINE_OAI_IDENTIFIER,
		'INCLUDE_ATTRIBUTES_GENERIC_MAPPER':settings.INCLUDE_ATTRIBUTES_GENERIC_MAPPER
	}


def livy_session(request):

	'''
	Make Livy session information available to all views
	'''

	# get active livy session
	lv = LivySession.get_active_session()
	if lv:
		lv.refresh_from_livy()

	return {
		'LIVY_SESSION':lv
	}


def bgtasks_proc(request):

	'''
	Get status of Background Tasks
		- improvements would be to determine if task running, but would require DB query
	'''

	try:
		# get supervisor and status
		sp = SupervisorRPCClient()
		proc = sp.check_process('combine_background_tasks')

		# return
		return {
			'BGTASKS_PROC':proc
		}

	except:
		pass


def combine_git_info(request):

	'''
	Return branch of combine git repo
	'''

	branch = subprocess.Popen("git rev-parse --abbrev-ref HEAD", shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').rstrip("\n")
	return {'COMBINE_GIT_BRANCH':branch}<commit_msg>fix for reading tags detatched state<commit_after>import subprocess

from django.conf import settings
from core.models import LivySession, SupervisorRPCClient


def combine_settings(request):
	
	'''
	Make some settings variables available to all templates
	'''

	return {
		'APP_HOST': settings.APP_HOST,		
		'DPLA_API_KEY': settings.DPLA_API_KEY,
		'OAI_RESPONSE_SIZE':settings.OAI_RESPONSE_SIZE,
		'COMBINE_OAI_IDENTIFIER':settings.COMBINE_OAI_IDENTIFIER,
		'INCLUDE_ATTRIBUTES_GENERIC_MAPPER':settings.INCLUDE_ATTRIBUTES_GENERIC_MAPPER
	}


def livy_session(request):

	'''
	Make Livy session information available to all views
	'''

	# get active livy session
	lv = LivySession.get_active_session()
	if lv:
		lv.refresh_from_livy()

	return {
		'LIVY_SESSION':lv
	}


def bgtasks_proc(request):

	'''
	Get status of Background Tasks
		- improvements would be to determine if task running, but would require DB query
	'''

	try:
		# get supervisor and status
		sp = SupervisorRPCClient()
		proc = sp.check_process('combine_background_tasks')

		# return
		return {
			'BGTASKS_PROC':proc
		}

	except:
		pass


def combine_git_info(request):

	'''
	Return branch of combine git repo
	'''

	# attempt to read tag
	tag_query = subprocess.Popen("git describe --tags", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	out = tag_query.stdout.read().decode('utf-8').rstrip("\n")
	err = tag_query.stderr.read().decode('utf-8').rstrip("\n")

	# if tag found, use
	if out != '':
		branch = out

	# else, read branch 
	else:
		branch = subprocess.Popen("git rev-parse --abbrev-ref HEAD", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.read().decode('utf-8').rstrip("\n")

	# return
	return {'COMBINE_GIT_BRANCH':branch}















{'fraction_non_alphanumeric': 0.11010946555054733, 'fraction_numerical': 0.00128783000643915, 'mean_word_length': 4.732472324723247, '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': '1848598', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1062, 'n_words': 235}