#!/usr/bin/perl -s -Ilib # PODNAME: dmoss-process # ABSTRACT: command line tool to process a software package use warnings; use strict; use DMOSS; use File::Fetch; use File::Copy; use File::Basename; use File::Path qw/make_path/; use File::Find; use Archive::Extract; use Data::Dumper; my $tmpdir = '/tmp/dmoss'; my $targetdir = $tmpdir.'/'.int(rand(10000)); make_path($targetdir) unless -e $targetdir; my $DEBUG = 0; our $stdout; my $source = shift; my $targetfile = ''; unless ($source) { print "Error: suply a file or URL to process\n", " \$ dmoss-process \n", exit; } # get file if url if ($source =~ m/^(http|ftp):\/\//) { my $ff = File::Fetch->new(uri => $source); $targetfile = $ff->fetch( to => $targetdir ); } else { # copy file if file only $targetfile = "$targetdir/".(basename $source); copy($source, $targetfile); } my $basedir = $targetdir; if ($targetfile =~ m/(tgz|gz|zip|)$/i) { my $ae = Archive::Extract->new( archive => $targetfile ); my $ok = $ae->extract( to => $targetdir ); $basedir = $ae->extract_path; } $basedir =~ s/(bin)\/?$//; print STDERR "targetfile $targetfile\n" if $DEBUG; print STDERR "basedir $basedir\n" if $DEBUG; # process basedir my @files; find(\&proc_file, $basedir); my $dmoss = DMOSS->new($basedir, @files); # clear previsou tmp data unless ($DEBUG) { unlink '/tmp/full_plain_text.txt' if -e '/tmp/full_plain_text.txt'; unlink '/tmp/full_func_id.txt' if -e '/tmp/full_func_id.txt'; } # process $dmoss->process; # final result if ($stdout) { # print to stdout print $dmoss->to_stdout; } else { # save to default file my $output = $dmoss->save; print STDERR "Data saved as $output\n"; } sub proc_file { my $f = $File::Find::name; return if -d $f; push @files, $f; } __END__ =encoding UTF-8 =head1 SYNOPSIS $ dmoss-process package-1.0.tgz Data saved as dmoss.data $ dmoss-process http://some_url/package-1.0.tgz Data saved as dmoss.data =head1 DESCRIPTION C is a front-end to the DMOSS toolkit. It can be used to process a software package. The data is saved by debault to C. To build a report from the gathered data view the C tool.