-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog.pl
105 lines (90 loc) · 2.42 KB
/
catalog.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl
require "xmlParser.pl";
require "checksum.pl";
require "config.pl";
require "catCommsIndex.pl";
use Data::Dumper;
sub parseCatalog($)
{
my $catalogString = shift || "parseCatalog called with no catalog string\n";
my @parsedFiles = ();
my @catalogHash = xmlParser($catalogString);
print "catalogHash: ";
print(Dumper $catalogHash[1]);
my $filesArray = $catalogHash[1];
foreach $file (keys %$filesArray)
{
my $fileName = $file;
print "File in catalog:\n";
print(Dumper $file);
my $checksum = $filesArray->{$file}->{checksum};
print "Checksum in catalog: $checksum\n";
my @tags = ();
my $tagsArray = $filesArray->{$file}->{tags};
my $tagArray = $tagsArray->{tag};
foreach $tag (@$tagArray)
{
push(@tags, $tag);
}
my %fileHash = ();
$fileHash{name} = $fileName;
$fileHash{checksum} = $checksum;
$fileHash{tags} = \@tags;
push(@parsedFiles, \%fileHash);
}
return @parsedFiles;
}
sub composeCatalog()
{
parseConfig();
my @allFiles = allFilePaths();
my @allFilesFullPath = sharedFilesFullPath();
my %catalog = ();
my @filesElement = ();
print("Going through files\n");
foreach my $sharedFile (@allFiles)
{
my $fileChecksum = checksumForFile($sharedFile);
my @categories = categoriesForFile($sharedFile);
print("dumping categories\n");
print(Dumper @categories);
my %fileHash = ();
my %tagsHash = ();
$tagsHash{tag} = \@categories;
$fileHash{name} = [$sharedFile];
$fileHash{checksum} = [$fileChecksum];
$fileHash{tags} = [\%tagsHash];
push(@filesElement, \%fileHash);
}
$catalog{file} = \@filesElement;
return xmlStringWithRootItem(\%catalog, "catalog");
}
sub catalogForFiles(@)
{
parseConfig();
my %catalog = ();
my @filesElement = ();
print("dumping parameter files\n");
print(Dumper @_);
foreach my $sharedFile (@_)
{
print("dumping sharedFile\n");
print(Dumper $sharedFile);
my $fileChecksum = $sharedFile->{checksum};
my $categories = $sharedFile{tags};
print("dumping categories\n");
print(Dumper @$categories);
my %fileHash = ();
my %tagsHash = ();
$tagsHash{tag} = $categories;
$fileHash{name} = [$sharedFile->{name}];
$fileHash{checksum} = [$fileChecksum];
$fileHash{tags} = [\%tagsHash];
push(@filesElement, \%fileHash);
}
print("dumping request files\n");
print(Dumper @filesElement);
$catalog{file} = \@filesElement;
return xmlStringWithRootItem(\%catalog, "catalog");
}
1;