-
Notifications
You must be signed in to change notification settings - Fork 20
/
3503_add_version_info.pl
executable file
·68 lines (51 loc) · 1.91 KB
/
3503_add_version_info.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
#!/usr/bin/env perl
# Adds version metadata to HashObject and DualIndexHashObject JSON files.
use warnings; use strict;
BEGIN {
use File::Basename;
my $location = -l __FILE__ ? dirname readlink __FILE__ : dirname __FILE__;
unshift @INC, $location;
}
use lib3503::HashObject;
use lib3503::DualIndexHashObject;
use lib3503::PBot;
my ($data_dir, $version, $last_update) = @ARGV;
print "Adding version info... version: $version, last_update: $last_update, data_dir: $data_dir\n";
my @hashobjects = qw/channels commands capabilities/;
my @dualindex = qw/unban_timeouts unmute_timeouts ban-exemptions ignorelist registry spam_keywords users/;
my $pbot = lib3503::PBot->new();
foreach my $hashobject (@hashobjects) {
print "Updating $data_dir/$hashobject ...\n";
my $obj = lib3503::HashObject->new(name => $hashobject, filename => "$data_dir/$hashobject", pbot => $pbot);
$obj->load;
my $ver = $obj->get_data('$metadata$', 'update_version');
if (defined $ver) {
print "$hashobject last update version $ver; ";
if ($ver >= 3503) {
print "no update needed\n";
next;
} else {
print "updating...\n";
}
}
print "Adding version info\n";
$obj->add('$metadata$', { update_version => 3503 });
}
foreach my $hashobject (@dualindex) {
print "Updating $data_dir/$hashobject ...\n";
my $obj = lib3503::DualIndexHashObject->new(name => $hashobject, filename => "$data_dir/$hashobject", pbot => $pbot);
$obj->load;
my $ver = $obj->get_data('$metadata$', '$metadata$', 'update_version');
if (defined $ver) {
print "$hashobject last update version $ver; ";
if ($ver >= 3503) {
print "no update needed\n";
next;
} else {
print "updating...\n";
}
}
print "Adding version info\n";
$obj->add('$metadata$', '$metadata$', { update_version => 3503 });
}
exit 0;