<commit_before><?php

/**
 * @package    pake
 * @author     <NAME> <<EMAIL>>
 * @copyright  2004-2005 <NAME> <<EMAIL>>
 * @license    see the LICENSE file included in the distribution
 * @version    SVN: $Id$
 */

function pake_import($name, $import_default_tasks = true)
{
  $class_name = 'pake'.ucfirst(strtolower($name)).'Task';

  if (!class_exists($class_name)) {
    // plugin available?
    $plugin_path = '';
    foreach (pakeApp::get_plugin_dirs() as $dir) {
      if (file_exists($dir.'/'.$class_name.'.class.php')) {
        $plugin_path = $dir.'/'.$class_name.'.class.php';
        break;
      }
    }

    if (!$plugin_path) {
      throw new pakeException(sprintf('Plugin "%s" does not exist.', $name));
    }

    require_once $plugin_path;
  }

  if ($import_default_tasks && is_callable($class_name, 'import_default_tasks')) {
    call_user_func(array($class_name, 'import_default_tasks'));
  }
}

function pake_task($name)
{
  $args = func_get_args();
  array_shift($args);
  pakeTask::define_task($name, $args);

  return $name;
}

function pake_alias($alias, $name)
{
  pakeTask::define_alias($alias, $name);

  return $alias;
}

function pake_desc($comment)
{
  pakeTask::define_comment($comment);
}

function pake_properties($property_file)
{
  $file = $property_file;
  if (!pakeFinder::isPathAbsolute($file))
  {
    $file = getcwd().DIRECTORY_SEPARATOR.$property_file;
  }

  if (file_exists($file))
  {
    pakeApp::get_instance()->set_properties(parse_ini_file($file, true));
  }
  else
  {
    throw new pakeException('Properties file does not exist.');
  }
}

function pake_file($name)
{
  $args = func_get_args();
  array_shift($args);
  pakeFileTask::define_task($name, $args);

  return $name;
}

function pake_mkdirs($path, $mode = 0777)
{
  if (is_dir($path)) {
    return true;
  }

  if (file_exists($path)) {
    throw new pakeException('Can not create directory at "'.$path.'" as place is already occupied by file');
  }

  pake_echo_action('dir+', $path);

  return @mkdir($path, $mode, true);
}

/*
  override => boolean
*/
function pake_copy($origin_file, $target_file, $options = array())
{
  if (!array_key_exists('override', $options))
  {
    $options['override'] = false;
  }

  // we create target_dir if needed
  if (!is_dir(dirname($target_file)))
  {
    pake_mkdirs(dirname($target_file));
  }

  $most_recent = false;
  if (file_exists($target_file))
  {
    $stat_target = stat($target_file);
    $stat_origin = stat($origin_file);
    $most_recent = ($stat_origin['mtime'] > $stat_target['mtime']) ? true : false;
  }

  if ($options['override'] || !file_exists($target_file) || $most_recent)
  {
    pake_echo_action('file+', $target_file);
    copy($origin_file, $target_file);
  }
}<commit_msg>support of remote files in pake_copy. pake_copy("http://www.example.com/file.txt", "example.txt")<commit_after><?php

/**
 * @package    pake
 * @author     <NAME> <<EMAIL>>
 * @copyright  2004-2005 <NAME> <<EMAIL>>
 * @license    see the LICENSE file included in the distribution
 * @version    SVN: $Id$
 */

function pake_import($name, $import_default_tasks = true)
{
  $class_name = 'pake'.ucfirst(strtolower($name)).'Task';

  if (!class_exists($class_name)) {
    // plugin available?
    $plugin_path = '';
    foreach (pakeApp::get_plugin_dirs() as $dir) {
      if (file_exists($dir.'/'.$class_name.'.class.php')) {
        $plugin_path = $dir.'/'.$class_name.'.class.php';
        break;
      }
    }

    if (!$plugin_path) {
      throw new pakeException(sprintf('Plugin "%s" does not exist.', $name));
    }

    require_once $plugin_path;
  }

  if ($import_default_tasks && is_callable($class_name, 'import_default_tasks')) {
    call_user_func(array($class_name, 'import_default_tasks'));
  }
}

function pake_task($name)
{
  $args = func_get_args();
  array_shift($args);
  pakeTask::define_task($name, $args);

  return $name;
}

function pake_alias($alias, $name)
{
  pakeTask::define_alias($alias, $name);

  return $alias;
}

function pake_desc($comment)
{
  pakeTask::define_comment($comment);
}

function pake_properties($property_file)
{
  $file = $property_file;
  if (!pakeFinder::isPathAbsolute($file))
  {
    $file = getcwd().DIRECTORY_SEPARATOR.$property_file;
  }

  if (file_exists($file))
  {
    pakeApp::get_instance()->set_properties(parse_ini_file($file, true));
  }
  else
  {
    throw new pakeException('Properties file does not exist.');
  }
}

function pake_file($name)
{
  $args = func_get_args();
  array_shift($args);
  pakeFileTask::define_task($name, $args);

  return $name;
}

function pake_mkdirs($path, $mode = 0777)
{
  if (is_dir($path)) {
    return true;
  }

  if (file_exists($path)) {
    throw new pakeException('Can not create directory at "'.$path.'" as place is already occupied by file');
  }

  pake_echo_action('dir+', $path);

  return @mkdir($path, $mode, true);
}

/*
  override => boolean
*/
function pake_copy($origin_file, $target_file, $options = array())
{
    if (!array_key_exists('override', $options)) {
        $options['override'] = false;
    }

    // if origin is remote (http), we still override
    $override = (stream_is_local($origin_file) or $options['override']);

    // we create target_dir if needed
    if (!is_dir(dirname($target_file))) {
        pake_mkdirs(dirname($target_file));
    }

    $most_recent = false;
    if (false === $override and file_exists($target_file)) {
        $stat_target = stat($target_file);
        $stat_origin = stat($origin_file);
        $most_recent = ($stat_origin['mtime'] > $stat_target['mtime']) ? true : false;
    }

    if ($override || !file_exists($target_file) || $most_recent) {
        pake_echo_action('file+', $target_file);
        copy($origin_file, $target_file);
    }
}
{'fraction_non_alphanumeric': 0.1681109185441941, 'fraction_numerical': 0.004159445407279029, 'mean_word_length': 3.970714900947459, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1327950', 'n_tokens_mistral': 2072, 'n_tokens_neox': 2027, 'n_words': 382}