Skip to content
Snippets Groups Projects
Select Git revision
  • 5e15a5ed4089ee190f21832cf7af3ef6686e0c12
  • master default protected
  • diag
  • version1.3-archivematica
  • version1.2-archivematica
  • version1.1-archivematica
  • version1.0-archivematica
  • version1.0-rosetta
8 results

TA.pm

Blame
  • TA.pm 6.25 KiB
    use strict;
    use warnings;
    package SLUB::LZA::Rosetta::TA;
    use App::Cmd::Setup -app;
    use Path::Tiny qw( path );
    use YAML qw(LoadFile);
    use LWP::UserAgent;
    use Carp qw( croak );
    use feature qw(say);
    use Regexp::Optimizer;
    use IO::Zlib;
    # ABSTRACT: main module for ta-tool
    
    our %config;
    BEGIN{
        my $home = path($ENV{'HOME'});
        if ($home->is_dir() && !$home->is_rootdir) {
            my $config_path = $home->child('.config')->child('ta-tool.rc');
            our $config_file = $config_path;
            if ($config_path->is_file) {
                %config = YAML::LoadFile($config_path);
            }
        }
    }
    
    sub sru_search {
        my $searchtype = shift;
        my $query = shift;
        my $startrecord = shift;
        my $maxrecords = shift;
        my $is_verbose = shift;
        my %searchpaths = (
            ie   => 'permanent/ie',
            file => 'permanent/file',
            sip  => 'operational'
        );
    
        if (!exists $searchpaths{$searchtype}){
            croak ("Code error, wrong searchtype ($searchtype) used!");
        }
        my $protocol = 'https';
        my $host = $config{host};
        my $port = '8443';
        my $searchpath = $searchpaths{$searchtype};
        my $srubase="${protocol}://${host}:${port}/search/${searchpath}/sru";
        my $sru = "${srubase}?version=1.2&operation=searchRetrieve&startRecord=$startrecord&maximumRecords=$maxrecords&recordSchema=dc&query=${query}";
        my $ua = LWP::UserAgent->new(keep_alive => 1);
        $ua->agent("MyApp/0.1 ");
        $ua->timeout(3600);#1h
        $ua->default_headers->push_header('Accept-Encoding' => 'br, lzma, bzip2, gzip, compressed, deflate');
        $ua->ssl_opts(
            verify_hostname=>1,
            # SSL_ca_path => '/etc/ssl/',
        );
        if ($is_verbose) {
            say "searchurl = $sru";
        }
        my $req = $ua->get($sru);
        if ($req->is_success) {
            my  $xres = $req->decoded_content;
            return $xres;
        } else {
            croak ("Error was: ".$req->status_line());
        }
    }
    
    sub helper_scan_log {
        my $directory = shift;
        my $fh_processing = shift;
        for ($directory->children( qr/^server.log/ )) {