<commit_before>#!/usr/bin/env python

# pylint: disable=C0103,C0111

from GitAchievements.achievements import Achievement
from GitAchievements.plugin import Plugin, load_plugins
import GitAchievements.publisher
import GitAchievements.store
import GitAchievements.util

import argparse
import git
import git.config
import git.exc
import os.path
import sys

class GitAchievementsApp(object):
	"""
	The achievements application.
	"""

	git_cmd = '/usr/bin/git'

	def __init__(self):
		"""
		Setup the application.
		"""

		self.config = git.config.GitConfigParser(GitAchievements.util.expand_filepath('~/.gitconfig'))

		self.achievements_dir = self._get_achievements_dir()
		external_plugin_dir = self.config.get_value(
				'achievement', 'plugin_dir',
				default = os.path.join(self.achievements_dir, 'plugins'))

		plugin_dirs = [
			external_plugin_dir,
		]

		load_plugins(plugin_dirs)

		store_type_name = self.config.get_value('achievement', 'store_type',
												default = 'GitAchievements.store.file.LogFileStore')
		store_type      = Plugin.get_plugin_by_name(store_type_name)
		if not store_type:
			print 'Invalid achievement store plugin selected:\n{0}'.format(store_type_name)
			sys.exit(1)

		self.store = store_type(self.config)

		self.all_achievements      = [ a for a in Achievement.get_plugins() if a.name ]
		self.unlocked_achievements = self.store.get_unlocked_achievements()

		self.repo = None
		try:
			self.repo = git.Repo('.')
			self.git  = self.repo.git
		except git.exc.InvalidGitRepositoryError:
			self.git = git.Git()

	def run(self):
		"""
		Run the application.
		"""

		# Check if we're handling an achievements command. If not pass it on!
		command_args = sys.argv[1:]
		try:
			if len(command_args) > 0 and command_args[0] == 'achievements':
				self._handle_achievements_commands()
			else:
				self.git.execute([self.git_cmd] + command_args)
		except SystemExit:
			pass # Prevent exiting<commit_msg>Catch git errors and print stdout and stderr<commit_after>#!/usr/bin/env python

# pylint: disable=C0103,C0111

from GitAchievements.achievements import Achievement
from GitAchievements.plugin import Plugin, load_plugins
import GitAchievements.publisher
import GitAchievements.store
import GitAchievements.util

import argparse
import git
import git.config
import git.exc
import os.path
import StringIO
import sys

class GitAchievementsApp(object):
	"""
	The achievements application.
	"""

	git_cmd = '/usr/bin/git'

	def __init__(self):
		"""
		Setup the application.
		"""

		self.config = git.config.GitConfigParser(GitAchievements.util.expand_filepath('~/.gitconfig'))

		self.achievements_dir = self._get_achievements_dir()
		external_plugin_dir = self.config.get_value(
				'achievement', 'plugin_dir',
				default = os.path.join(self.achievements_dir, 'plugins'))

		plugin_dirs = [
			external_plugin_dir,
		]

		load_plugins(plugin_dirs)

		store_type_name = self.config.get_value('achievement', 'store_type',
												default = 'GitAchievements.store.file.LogFileStore')
		store_type      = Plugin.get_plugin_by_name(store_type_name)
		if not store_type:
			print 'Invalid achievement store plugin selected:\n{0}'.format(store_type_name)
			sys.exit(1)

		self.store = store_type(self.config)

		self.all_achievements      = [ a for a in Achievement.get_plugins() if a.name ]
		self.unlocked_achievements = self.store.get_unlocked_achievements()

		self.repo = None
		try:
			self.repo = git.Repo('.')
			self.git  = self.repo.git
		except git.exc.InvalidGitRepositoryError:
			self.git = git.Git()

	def run(self):
		"""
		Run the application.
		"""

		# Check if we're handling an achievements command. If not pass it on!
		command_args = sys.argv[1:]
		has_error    = False
		stdout       = StringIO.StringIO()
		stdout_value = ''
		stderr_value = ''
		try:
			if len(command_args) > 0 and command_args[0] == 'achievements':
				self._handle_achievements_commands()
			else:
				self.git.execute([self.git_cmd] + command_args, output_stream = stdout)
		except SystemExit:
			pass # Prevent exiting
		except git.GitCommandError as git_error:
			has_error    = True
			stdout_value = stdout.getvalue()[:-1] # Strip off trailing newline
			stderr_value = git_error.stderr
		finally:
			stdout.close()

		if has_error:
			if stdout_value != '':
				print stdout_value

			if stderr_value != '':
				print stderr_value

			return
{'fraction_non_alphanumeric': 0.10675182481751824, 'fraction_numerical': 0.0061587591240875915, 'mean_word_length': 4.110722610722611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3783845', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1479, 'n_words': 307}