<commit_before>#!/usr/bin/perl

use strict;
use warnings;

my %DBModel_replacements = (
    qr{(\s*compile\.dependencies\s=\sintermine/integrate/main)\s*$} => q{$1.", bio/core/main\n"},
   => q{},
)
my @DBModel_additions = (
   'so.termlist.file = resources/so_term_list.txt',
   'so.obo.file = ../../bio/sources/so/so.obo',
   'so.output.file = build/model/so_additions.xml',
)
my %DOTInterMine_replacements = (
    qr{org\.postgresql\.jdbc3\.Jdbc3PoolingDataSource} => q{"org.postgresql.ds.PGPoolingDataSource"},
)

my %BuildXML_replacements = (
    qr{<project\s.*$} => q!$& . '
<target name="create-so-model" depends="init, -init-deps">
    <taskdef name="so-model" classname="org.intermine.bio.task.SOToModelTask">
        <classpath refid="task.class.path"/>
    </taskdef>
    <so-model soTermListFile="${so.termlist.file}" soFile="${so.obo.file}" outputFile="${so.output.file}"/>
</target>
'!,
)

my $ext = '.orig';

# FIND ALL THE PROJECT PROPERTIES FILES AND BUILD.XML FILES IN DBMODEL DIRECTORIES
my $svn_loc = $ARGV[0];
opendir(my $svn_dir, $svn_loc) or die;
for my $mine (readdir($svn_dir)) {
    my $abs_mine = $svn_loc . '/' . $mine;
    if (-d $abs_mine) {
        opendir(my $subdir, $abs_mine) or die;
        for my $dbmodel (readdir($subdir)) {
            if ($dbmodel eq 'dbmodel' and -d $abs_mine . '/' . $dbmodel) {
                my %replacements = %DBModel_replacements;
                $replacements{qr{bio/sources/so/so_additions\.xml}}
                    = qq{{"$mine/dbmodel/build/model/so_additions.xml"}};
                process($abs_mine.'/dbmodel/project.properties', \%replacements, \@DBModel_additions);
                my $buildxml = $abs_mine.'/dbmodel/build.xml';
                process($buildxml, \%BuildXML_replacements, [])
                    if (qx{grep 'create-so-model' $buildxml}); # This is our test for it already being there
           }
        }
    }
}

# FIND ALL THE .intermine/$MINE.properties FILES
my $dot_intermine_loc = $ENV{HOME} . '/' . '.intermine'
opendir(my $home_dir, $dot_intermine_loc) or die;
for (map {"$dot_intermine_loc/$_"} readdir($home_dir)) {
    if (/\.properties$/) {
        process($_, \%DOTInterMine_replacements, []);
    }
}

# RUN THE REPLACEMENT LIST OVER THE FILES
sub process {
    my ($file, $replacements, $additions) = @_;
    open($in, '<', $file) or die;
    my $backup = $file . $ext;
    rename($file, $backup)
    open(my $out, '>', $file) or die;
    select($out);
    my @seen_lines;
    while (<$in>) {
        while (my ($k, $v) = each %$replacements) {
            s/$k/eval($v)/e;
        }
        push @seen_lines, $_; # keep track of what is already there
        print;
    }
    for my $a (@$additions) { # Only add the additional lines if they are not already there
        unless (grep {/$a/} @seen_lines) {
            print $a, "\n";
        }
    }
    close $in;
    close $out;
}

exit()
<commit_msg>Script for updating additional features<commit_after>#!/usr/bin/perl

# This script makes some straightforward changes to the project.properties
# and build.xml files in the dbmodel directories, as to the .intermine/mine.properties
# files in the users home directory

use strict;
use warnings;
use File::Copy;

my %DBModel_replacements = (
    qr{(\s*compile\.dependencies\s=\sintermine/integrate/main)\s*$} => q{$1.", bio/core/main\n"},
);
my @DBModel_additions = (
   'so.termlist.file = resources/so_term_list.txt',
   'so.obo.file = ../../bio/sources/so/so.obo',
   'so.output.file = build/model/so_additions.xml',
);
my %DOTInterMine_replacements = (
    qr{org\.postgresql\.jdbc3\.Jdbc3PoolingDataSource} => q{"org.postgresql.ds.PGPoolingDataSource"},
);

my %BuildXML_replacements = (
    qr{<project\s.*$} => q!$& . '
<target name="create-so-model" depends="init, -init-deps">
    <taskdef name="so-model" classname="org.intermine.bio.task.SOToModelTask">
        <classpath refid="task.class.path"/>
    </taskdef>
    <so-model soTermListFile="${so.termlist.file}" soFile="${so.obo.file}" outputFile="${so.output.file}"/>
</target>
'!,
);

# Do not delete the original, but back it up to file.old.orig
my $ext = '.orig';

# FIND ALL THE PROJECT PROPERTIES FILES AND BUILD.XML FILES IN DBMODEL DIRECTORIES
my $svn_loc = $ARGV[0];

die "We need to know where the svn directory is"
    unless $svn_loc;

my $reverting = ($ARGV[1] and $ARGV[1] eq 'revert');

opendir(my $svn_dir, $svn_loc) or die;
for my $mine (readdir($svn_dir)) {
    my $abs_mine = $svn_loc . '/' . $mine;
    if (-d $abs_mine) {
        opendir(my $subdir, $abs_mine) or die;
        for my $dbmodel (readdir($subdir)) {
            if ($dbmodel eq 'dbmodel' and -d $abs_mine . '/' . $dbmodel) {
                my %replacements = %DBModel_replacements;
                $replacements{qr{bio/sources/so/so_additions\.xml}}
                    = qq{{"$mine/dbmodel/build/model/so_additions.xml"}};
                process($abs_mine.'/dbmodel/project.properties', \%replacements, \@DBModel_additions);
                my $buildxml = $abs_mine.'/dbmodel/build.xml';
                process($buildxml, \%BuildXML_replacements, [])
                    if (qx{grep 'create-so-model' $buildxml});
                    # This is our test for it already being there
           }
        }
    }
}

# FIND ALL THE .intermine/$MINE.properties FILES
my $dot_intermine_loc = $ENV{HOME} . '/' . '.intermine';
opendir(my $home_dir, $dot_intermine_loc) or die;
for (map {"$dot_intermine_loc/$_"} readdir($home_dir)) {
    if (/\.properties$/) {
        process($_, \%DOTInterMine_replacements, []);
    }
}

# RUN THE REPLACEMENT LIST OVER THE FILES
sub process {
    my ($file, $replacements, $additions) = @_;
    open(my $in, '<', $file) or die;
    my $backup = $file . $ext;
    print STDERR "backing up $file to $backup\n";
    if (-f $backup) {
        if ($reverting) {
            move($backup, $file);
            return;
        } else {
            die "Back up file ($backup) exists - we do not want to overwrite it";
        }
    }
    rename($file, $backup);
    open(my $out, '>', $file) or die;
    select($out);
    my @seen_lines;
    while (<$in>) {
        while (my ($k, $v) = each %$replacements) {
            s/$k/eval($v)/e;
        }
        push @seen_lines, $_; # keep track of what is already there
        print;
    }
    for my $a (@$additions) { # Only add the additional lines if they are not already there
        unless (grep {/$a/} @seen_lines) {
            print $a, "\n";
        }
    }
    close $in or die "Cannot close original file, $!";
    close $out or die "Cannot close new file, $!";
    print STDERR "finished processing $file\n";
}

exit()

{'fraction_non_alphanumeric': 0.16609204017388698, 'fraction_numerical': 0.00149902563333833, 'mean_word_length': 2.6861878453038672, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 15}, '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': '2484247', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2365, 'n_words': 546}