<commit_before>#!/usr/bin/env python
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of StraitJacket.
#
# StraitJacket is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# StraitJacket is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

import time, os, subprocess, threading, base64, LibAppArmor, shutil

__author__ = "<NAME>"
__copyright__ = "Copyright 2011 Instructure, Inc."
__license__ = "AGPLv3"
__email__ = "<EMAIL>"

class Error_(Exception): pass
class AppArmorProtectionFailure(Error_): pass

def aa_change_onexec(profile):
  if LibAppArmor.aa_change_onexec(profile) != 0:
    raise AppArmorProtectionFailure, ("failed to switch to apparmor profile %s"
        % profile)

class BaseProfile(object):

  def __init__(self, config):
    self.config = config
    self.max_runtime = config.getint("general", "max_runtime")

  def _kill(self, pid, completed, max_runtime=None):
    if max_runtime is None: max_runtime = self.max_runtime
    for _ in xrange(max(int(max_runtime), 1)):
      if completed: return
      time.sleep(1)
    if not completed:
      os.kill(pid, 9)
      completed.append("killed")

  def _run_user_program(self, user_program, stdin, aa_profile, time_used=0,
      executable=None, chdir=None, custom_timelimit=None):
    if custom_timelimit == None: custom_timelimit = float('inf')
    completed = []
    runtime = None
    start_time = time.time()

    def preexec_fn():
      if chdir: os.chdir(chdir)
      aa_change_onexec(aa_profile)<commit_msg>don't require libapparmor for remote server tests<commit_after>#!/usr/bin/env python
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of StraitJacket.
#
# StraitJacket is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# StraitJacket is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

import time, os, subprocess, threading, base64, shutil
try:
  import LibAppArmor
except ImportError:
  LibAppArmor = None

__author__ = "<NAME>"
__copyright__ = "Copyright 2011 Instructure, Inc."
__license__ = "AGPLv3"
__email__ = "<EMAIL>"

class Error_(Exception): pass
class AppArmorProtectionFailure(Error_): pass

def aa_change_onexec(profile):
  if LibAppArmor is None or LibAppArmor.aa_change_onexec(profile) != 0:
    raise AppArmorProtectionFailure, ("failed to switch to apparmor profile %s"
        % profile)

class BaseProfile(object):

  def __init__(self, config):
    self.config = config
    self.max_runtime = config.getint("general", "max_runtime")

  def _kill(self, pid, completed, max_runtime=None):
    if max_runtime is None: max_runtime = self.max_runtime
    for _ in xrange(max(int(max_runtime), 1)):
      if completed: return
      time.sleep(1)
    if not completed:
      os.kill(pid, 9)
      completed.append("killed")

  def _run_user_program(self, user_program, stdin, aa_profile, time_used=0,
      executable=None, chdir=None, custom_timelimit=None):
    if custom_timelimit == None: custom_timelimit = float('inf')
    completed = []
    runtime = None
    start_time = time.time()

    def preexec_fn():
      if chdir: os.chdir(chdir)
      aa_change_onexec(aa_profile)
{'fraction_non_alphanumeric': 0.09247842170160296, 'fraction_numerical': 0.008384710234278668, 'mean_word_length': 4.24031007751938, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6051703', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1240, 'n_words': 425}