File: sreview-copy

package info (click to toggle)
sreview 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,420 kB
  • sloc: perl: 11,901; javascript: 509; sh: 72; makefile: 8
file content (58 lines) | stat: -rw-r--r-- 1,488 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl -w

use strict;
use warnings;

use SReview::Config::Common;
use SReview::Files::Factory;
use Getopt::Long;
use File::Copy;

my $config = SReview::Config::Common::setup;

sub get_collection($) {
	my $collname = shift;
	my $relname;
	if($collname eq "input") {
		return SReview::Files::Factory->create($collname, $config->get('inputglob'));
	}
	if($collname eq "pub") {
		return SReview::Files::Factory->create("intermediate", $config->get('pubdir'));
	}
	if($collname eq "output") {
		return SReview::Files::Factory->create("output", $config->get('outputdir'));
	}
	return SReview::Files::Factory->create($collname, $config->get('extra_collections')->{$collname});
}

my $inputcoll;
my $outputcoll;
my $filename;
my $targetname;
my $move;

GetOptions(
	"inputcollection|i=s" => \$inputcoll,
	"outputcollection|o=s" => \$outputcoll,
	"filename|f=s" => \$filename,
	"targetname|t=s" => \$targetname,
	"move|m" => \$move,
);

if(!defined($targetname)) {
	$targetname = $filename;
}

die "input collection required" unless defined($inputcoll);
die "output collection required" unless defined($outputcoll);
die "filename required" unless defined($filename);

$inputcoll = get_collection($inputcoll);
$outputcoll = get_collection($outputcoll);
my $inputfile = $inputcoll->get_file(relname => $filename);
my $outputfile = $outputcoll->add_file(relname => $targetname);
copy($inputfile->filename, $outputfile->filename);
$outputfile->store_file;
if($move) {
	$inputfile->delete;
}