-
Notifications
You must be signed in to change notification settings - Fork 4
/
minimize_workflow.pl
67 lines (55 loc) · 2.23 KB
/
minimize_workflow.pl
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
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
#
# minimize_workflow.pl
#
# Utility to remove all metadata and objects associated with a
# Resolve Actions Express workflow, leaving only the base XML
# in-tact.
#
# Written by Derek Pascarella
# Include modules.
use strict;
use File::Slurp;
# Define input parameters.
my $workflow_source = $ARGV[0];
my $workflow_destination = $ARGV[1];
# Print error messages for missing input or other errors.
if(!defined $workflow_source || $workflow_source eq "")
{
die "Error: Must specify source and destination files.\nUsage: minimize_workflow <source_file> <destination_file>\n";
}
elsif(!defined $workflow_destination || $workflow_destination eq "")
{
die "Error: Must specify source and destination files.\nUsage: minimize_workflow <source_file> <destination_file>\n";
}
elsif(!-e $workflow_source)
{
die "Error: Source file is unreadable or does not exist.\nUsage: minimize_workflow <source_file> <destination_file>\n";
}
# Open source workflow.
my $workflow_source_contents = read_file($workflow_source);
# Extract workflow XML from source file.
(my $workflow_source_xml) = $workflow_source_contents =~ /Xoml=\"\s*([^]]+)\"\sXomlStatus=\"/x;
# Extract workflow name from source file.
(my $workflow_source_name) = $workflow_source_contents =~ /Name=\"\s*([^]]+)\"\sDescription=\"/x;
# Extract workflow description from source file.
(my $workflow_source_description) = $workflow_source_contents =~ /Description=\"\s*([^]]+)\"\sXoml=\"/x;
# Store new destination workflow XML.
my $workflow_destination_xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Workflow>\n\t<WorkflowInfo Name=\"$workflow_source_name\" Description=\"$workflow_source_description\" Details=\"\" XML=\"$workflow_source_xml\" />\n\t<Tags>\n\t</Tags>\n</Workflow>";
# Print status messages.
print "Workflow Name:\t\t$workflow_source_name\n";
print "Workflow Description:\t";
if($workflow_source_description eq "")
{
print "N/A\n\n";
}
else
{
print "$workflow_source_description\n\n";
}
# Write new workflow XML to destination file.
open(DEST, ">", $workflow_destination) or die $!;
print DEST $workflow_destination_xml;
close(DEST);
# Print final status message.
print "New workflow saved as \"$workflow_destination\".\n";