<commit_before>#!/usr/bin/perl -w

package EPFLSTI::Docker::Paths;

use strict;

use base 'Exporter';

our @EXPORT_OK = qw(srv_dir);

use File::Spec;

=head1 NAME

EPFLSTI::Docker::Paths - Paths on the NOC and Blue Boxes

=head1 DESCRIPTION

Paths in the Blue Box Docker environment are fairly simple; yet we
don't want to hard-code them in order to facilitate development.

=cut

sub _is_prod {
  if ($^O ne "linux") { return 0; }
  if ($0 =~ m|/Users/| or $0 =~ m|/home/|) { return 0; }
  if ($0 =~ m|^/opt|) { return 1; }
  return undef;
}

our $_srv_dir;
sub srv_dir {
  if ($_srv_dir) {
    return $_srv_dir;
  }
  if  (_is_prod) {
    return ($_srv_dir = "/srv");
  }

  require File::Basename;
  my $scriptdir = File::Spec->rel2abs(File::Basename::dirname($0));
  chomp(my $checkoutdir = `set +x; cd "$scriptdir"; git rev-parse --show-toplevel`);
  if ($checkoutdir) {
    $_srv_dir = "$checkoutdir/var";
  } else {
    require File::Temp;
    $_srv_dir = File::Temp::tempdir("EPFL-Docker-Log-XXXXXX", TMPDIR => 1 );
  }
  warn "Substituting /srv with $_srv_dir for development\n";
  return $_srv_dir;
}

sub settable_srv_subpath {
  my ($class, $subpath) = @_;

  my $value;
  return sub {
    if (@_) {
    $value = $_[0];
    return;
    } elsif ($value) {
      return $value;
    } else {
      return ($value = File::Spec->catfile(srv_dir(), $subpath));
    };
  }
}

1;<commit_msg>Make srv_dir() settable; support class method-style invocation<commit_after>#!/usr/bin/perl -w

package EPFLSTI::Docker::Paths;

use strict;

use base 'Exporter';

our @EXPORT_OK = qw(srv_dir);

use File::Spec;

=head1 NAME

EPFLSTI::Docker::Paths - Paths on the NOC and Blue Boxes

=head1 DESCRIPTION

Paths in the Blue Box Docker environment are fairly simple; yet we
don't want to hard-code them in order to facilitate development.

=cut

sub _is_prod {
  if ($^O ne "linux") { return 0; }
  if ($0 =~ m|/Users/| or $0 =~ m|/home/|) { return 0; }
  if ($0 =~ m|^/opt|) { return 1; }
  return undef;
}

our $_srv_dir;
sub srv_dir {
  shift if UNIVERSAL::isa($_[0], __PACKAGE__);
  if (@_) {
    $_srv_dir = shift;
    return;
  } elsif ($_srv_dir) {
    return $_srv_dir;
  }
  elsif  (_is_prod) {
    return ($_srv_dir = "/srv");
  }

  require File::Basename;
  my $scriptdir = File::Spec->rel2abs(File::Basename::dirname($0));
  chomp(my $checkoutdir = `set +x; cd "$scriptdir"; git rev-parse --show-toplevel`);
  if ($checkoutdir) {
    $_srv_dir = "$checkoutdir/var";
  } else {
    require File::Temp;
    $_srv_dir = File::Temp::tempdir("EPFL-Docker-Log-XXXXXX", TMPDIR => 1 );
  }
  warn "Substituting /srv with $_srv_dir for development\n";
  return $_srv_dir;
}

sub settable_srv_subpath {
  my ($class, $subpath) = @_;

  my ($caller_pkg) = caller();
  my $value;
  return sub {
    shift if UNIVERSAL::isa($_[0], $caller_pkg);
    if (@_) {
      $value = $_[0];
      return;
    } elsif ($value) {
      return $value;
    } else {
      return ($value = File::Spec->catfile(srv_dir(), $subpath));
    };
  }
}

1;
{'fraction_non_alphanumeric': 0.16760330578512397, 'fraction_numerical': 0.009256198347107438, 'mean_word_length': 3.335243553008596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6633452', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1200, 'n_words': 304}