<commit_before>"""Automatic mechanism to make sure code style of PRs is checked."""

import logging
import json
import threading
import os
import subprocess
import shlex
import github
import Queue
import errno
import shutil
from requests import Session, get
from time import sleep
from styleguard_config import cfg
from stat import S_IEXEC

# TODO: log to file
LOGGER = logging.getLogger('styleguard')
logging.basicConfig(level=cfg['logging_level'])

logging.getLogger('github.Requester').setLevel(logging.INFO)
MY_QUEUE = Queue.Queue()
MY_DICT = dict(TOKEN='', OWNER_REPO='')


class PrHandler(threading.Thread):
	"""Threaded PR Worker"""

	def __init__(self):
		LOGGER.debug("Starting PR worker thread")
		threading.Thread.__init__(self)
		self.queue = MY_QUEUE
		self.payload = None
		self.reporoot = os.getenv('OPENSHIFT_REPO_DIR', '')
		# base directory:
		self.basedir = os.path.abspath(os.path.join(os.getcwd(),
													cfg['storage_dir']))
		self.repodir = os.path.join(self.basedir, cfg['repo_local_path'])
		self.stylerdir = os.path.join(self.basedir, cfg['styler_local_path'])
		# TODO: check for existence of folders in data dir, create if necessary
		LOGGER.debug('PATH: ' + os.getenv('PATH', 'unset'))

		self.api_github = self.init_authentication()
		if self.api_github == 1:
			raise PRHandlerException('Initialization failed. Aborting.')
		LOGGER.debug('Remaining Github API calls: ' +
					str(self.api_github.rate_limiting[0]))
		if cfg['fetch_method'] == 'git':
			if os.path.isdir(os.path.join(self.repodir, '.git')):
				LOGGER.info('Local git repo at ' + str(self.repodir))
			else:
				raise PRHandlerException('Not a git repo directory: ' +
										str(self.repodir))
			LOGGER.info('Checking repo')<commit_msg>Ensure existence of storage directories.<commit_after>"""Automatic mechanism to make sure code style of PRs is checked."""

import logging
import json
import threading
import os
import subprocess
import shlex
import github
import Queue
import errno
import shutil
from requests import Session, get
from time import sleep
from styleguard_config import cfg
from stat import S_IEXEC

# TODO: log to file
LOGGER = logging.getLogger('styleguard')
logging.basicConfig(level=cfg['logging_level'])

logging.getLogger('github.Requester').setLevel(logging.INFO)
MY_QUEUE = Queue.Queue()
MY_DICT = dict(TOKEN='', OWNER_REPO='')


class PrHandler(threading.Thread):
	"""Threaded PR Worker"""

	def __init__(self):
		LOGGER.debug("Starting PR worker thread")
		threading.Thread.__init__(self)
		self.queue = MY_QUEUE
		self.payload = None
		self.reporoot = os.getenv('OPENSHIFT_REPO_DIR', '')
		# base directory:
		self.basedir = os.path.abspath(os.path.join(os.getcwd(),
													cfg['storage_dir']))
		self.repodir = os.path.join(self.basedir, cfg['repo_local_path'])
		self.stylerdir = os.path.join(self.basedir, cfg['styler_local_path'])
		if not os.path.exists(self.repodir):
			os.mkdir(self.repodir)
		if not os.path.exists(self.stylerdir):
			os.mkdir(self.stylerdir)
		LOGGER.debug('PATH: ' + os.getenv('PATH', 'unset'))

		self.api_github = self.init_authentication()
		if self.api_github == 1:
			raise PRHandlerException('Initialization failed. Aborting.')
		LOGGER.debug('Remaining Github API calls: ' +
					str(self.api_github.rate_limiting[0]))
		if cfg['fetch_method'] == 'git':
			if os.path.isdir(os.path.join(self.repodir, '.git')):
				LOGGER.info('Local git repo at ' + str(self.repodir))
			else:
				raise PRHandlerException('Not a git repo directory: ' +
										str(self.repodir))
			LOGGER.info('Checking repo')
{'fraction_non_alphanumeric': 0.1304226140498181, 'fraction_numerical': 0.001119507416736636, 'mean_word_length': 4.773828756058158, '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': '4841660', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1205, 'n_words': 279}