Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit c7b34b7

Browse files
committed
More cleanup stuff.
1 parent d89329a commit c7b34b7

File tree

2 files changed

+97
-97
lines changed

2 files changed

+97
-97
lines changed

cleanup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
66
cd "${SCRIPT_DIR}"
77

88
tjfind() {
9-
find . \( "$@" \) -and -not -path './.git/*' -and -not -path '*__pycache__*' -and -not -path '*PythonEnvironment*' -and -not -path './simc*' -and -not -path './Temp*' -print | sort
9+
find . \( "$@" \) -and -not -path './.git/*' -and -not -path './simc*' -and -not -path './Temp*' -print | sort
1010
}
1111

1212
# Remove executable flag on all files
@@ -22,7 +22,7 @@ tjfind -iname '*.lua' | parallel "sed -i 's/^local devMode = true/local devMode
2222
tjfind -iname '*.lua' | parallel "echo \"Formatting '{1}'\" && luaformatter -a -s4 '{1}'"
2323

2424
# Reformat perl scripts
25-
tjfind -iname '*.pl' | parallel "perltidy -pt=0 -l=200 '{1}' && cat '{1}.tdy' > '{1}' && rm '{1}.tdy'"
25+
tjfind -iname '*.pl' | parallel "perltidy -pt=2 -dws -nsak='if for while' -l=200 '{1}' && cat '{1}.tdy' > '{1}' && rm '{1}.tdy'"
2626

2727
# Make sure everything has Unix line endings
2828
tjfind -iname '*.toc' -or -iname '*.lua' -or -iname '*.sh' -or -iname '*.pl' -or -iname '*.simc' | parallel "dos2unix '{1}' >/dev/null 2>&1"

update-generated-data.pl

+95-95
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package cfg;
77

88
use File::Basename;
99
use Cwd qw/abs_path/;
10-
( our $script_path = abs_path( $0 ) ) =~ s|^(.*)(\[\/\])(.*)|$1$2|g;
11-
our $script_dir = dirname( $script_path );
10+
(our $script_path = abs_path($0)) =~ s|^(.*)(\[\/\])(.*)|$1$2|g;
11+
our $script_dir = dirname($script_path);
1212

13-
our $cachetime = 3600;
13+
our $cachetime = 86400;
1414

1515
package datacache;
1616

@@ -19,33 +19,33 @@ package datacache;
1919
use DBI;
2020
use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
2121

22-
my $dbh = DBI->connect( "dbi:SQLite:dbname=${cfg::script_dir}/datacache.sqlitedb", "", "", { RaiseError => 1 } ) or die $DBI::errstr;
23-
$dbh->do( "CREATE TABLE IF NOT EXISTS cache (urlhash TEXT PRIMARY KEY, timestamp INTEGER, data TEXT)" );
24-
my $sth = $dbh->prepare( "DELETE FROM cache WHERE timestamp < ?" );
25-
$sth->bind_param( 1, time - ${cfg::cachetime} );
22+
my $dbh = DBI->connect("dbi:SQLite:dbname=${cfg::script_dir}/datacache.sqlitedb", "", "", { RaiseError => 1 }) or die $DBI::errstr;
23+
$dbh->do("CREATE TABLE IF NOT EXISTS cache (urlhash TEXT PRIMARY KEY, timestamp INTEGER, data TEXT)");
24+
my $sth = $dbh->prepare("DELETE FROM cache WHERE timestamp < ?");
25+
$sth->bind_param(1, time - ${cfg::cachetime});
2626
$sth->execute();
2727

2828
sub get_url {
29-
my ( $url ) = @_;
30-
my $urlhash = sha1_base64( $url );
31-
my $sth = $dbh->prepare( "SELECT * FROM cache WHERE urlhash = ? AND timestamp > ?" );
32-
$sth->bind_param( 1, $urlhash );
33-
$sth->bind_param( 2, time - ${cfg::cachetime} );
29+
my ($url) = @_;
30+
my $urlhash = sha1_base64($url);
31+
my $sth = $dbh->prepare("SELECT * FROM cache WHERE urlhash = ? AND timestamp > ?");
32+
$sth->bind_param(1, $urlhash);
33+
$sth->bind_param(2, time - ${cfg::cachetime});
3434
$sth->execute();
3535

3636
my $row;
37-
if ( $row = $sth->fetchrow_hashref() ) {
37+
if($row = $sth->fetchrow_hashref()) {
3838
$sth->finish();
3939
return $row->{data};
4040
}
4141
else {
4242
print "Getting '$url'...\n";
4343
$sth->finish();
44-
my $data = get( $url );
45-
$sth = $dbh->prepare( "INSERT OR REPLACE INTO cache (urlhash, timestamp, data) VALUES(?, ?, ?)" );
46-
$sth->bind_param( 1, $urlhash );
47-
$sth->bind_param( 2, time );
48-
$sth->bind_param( 3, $data );
44+
my $data = get($url);
45+
$sth = $dbh->prepare("INSERT OR REPLACE INTO cache (urlhash, timestamp, data) VALUES(?, ?, ?)");
46+
$sth->bind_param(1, $urlhash);
47+
$sth->bind_param(2, time);
48+
$sth->bind_param(3, $data);
4949
$sth->execute();
5050
$sth->finish();
5151
return $data;
@@ -58,32 +58,32 @@ package simc;
5858
our $directory = "${cfg::script_dir}/simc";
5959

6060
my $last_branch = `cd "${directory}" && git rev-parse --abbrev-ref HEAD`;
61-
die unless ( ( $? >> 8 ) == 0 );
61+
die unless (($? >> 8) == 0);
6262
chomp $last_branch;
6363

6464
sub update {
65-
my ( $requested_branch ) = @_;
65+
my ($requested_branch) = @_;
6666
$requested_branch = $requested_branch || ${simc::branch};
6767

68-
if ( !-d "${simc::directory}/.git" ) {
69-
system( "git clone --depth=1 https://github.com/simulationcraft/simc \"${simc::directory}\"" );
70-
die unless ( ( $? >> 8 ) == 0 );
68+
if(!-d "${simc::directory}/.git") {
69+
system("git clone --depth=1 https://github.com/simulationcraft/simc \"${simc::directory}\"");
70+
die unless (($? >> 8) == 0);
7171
}
7272
else {
73-
system( "cd \"${simc::directory}\" && git pull" );
74-
die unless ( ( $? >> 8 ) == 0 );
73+
system("cd \"${simc::directory}\" && git pull");
74+
die unless (($? >> 8) == 0);
7575
}
7676

77-
if ( $requested_branch ne $last_branch ) {
78-
system( "cd \"${simc::directory}\" && git reset --hard HEAD && git clean -xfd && git checkout \"${requested_branch}\" && git pull" );
79-
die unless ( ( $? >> 8 ) == 0 );
77+
if($requested_branch ne $last_branch) {
78+
system("cd \"${simc::directory}\" && git reset --hard HEAD && git clean -xfd && git checkout \"${requested_branch}\" && git pull");
79+
die unless (($? >> 8) == 0);
8080
$last_branch = `cd "${simc::directory}" && git rev-parse --abbrev-ref HEAD`;
81-
die unless ( ( $? >> 8 ) == 0 );
82-
die unless ( $last_branch eq $requested_branch );
81+
die unless (($? >> 8) == 0);
82+
die unless ($last_branch eq $requested_branch);
8383
}
8484

85-
system( "cd \"${simc::directory}/engine\" && make -j9 OS=UNIX" );
86-
die unless ( ( $? >> 8 ) == 0 );
85+
system("cd \"${simc::directory}/engine\" && make -j9 OS=UNIX");
86+
die unless (($? >> 8) == 0);
8787
}
8888

8989
package generator;
@@ -155,48 +155,48 @@ package generator;
155155
};
156156

157157
sub create_action_lists {
158-
print( "\nPre-creating actions files...\n" );
159-
for my $cls ( sort keys %{$profiles} ) {
158+
print("\nPre-creating actions files...\n");
159+
for my $cls (sort keys %{$profiles}) {
160160
my $class_lua_actions_file = "${cfg::script_dir}/ActionProfileLists/actions-${cls}.lua";
161-
my $bn = basename( $class_lua_actions_file );
162-
print( " - ${bn}\n" );
163-
open( my $outfile, ">", $class_lua_actions_file );
161+
my $bn = basename($class_lua_actions_file);
162+
print(" - ${bn}\n");
163+
open(my $outfile, ">", $class_lua_actions_file);
164164
print {$outfile} "local _, internal = ...\n";
165165
print {$outfile} "internal.apls = internal.apls or {}\n\n";
166-
close( $outfile );
166+
close($outfile);
167167
}
168168

169-
print( "\nGenerating custom simc profile APLs:\n" );
170-
for my $cls ( sort keys %{$customprofiles} ) {
169+
print("\nGenerating custom simc profile APLs:\n");
170+
for my $cls (sort keys %{$customprofiles}) {
171171
my $class_lua_actions_file = "${cfg::script_dir}/ActionProfileLists/actions-${cls}.lua";
172-
open( my $outfile, ">>", $class_lua_actions_file );
172+
open(my $outfile, ">>", $class_lua_actions_file);
173173

174-
for my $spec ( @{ $customprofiles->{$cls} } ) {
175-
printf( "%14s / %s\n", $cls, $spec );
174+
for my $spec (@{ $customprofiles->{$cls} }) {
175+
printf("%14s / %s\n", $cls, $spec);
176176

177177
print {$outfile} "internal.apls['custom::${cls}::${spec}'] = [[\n";
178178

179179
my $custom_simc_file = "${cfg::script_dir}/CustomProfiles/${cls}_${spec}.simc";
180-
open( my $infile, "<", $custom_simc_file );
181-
while ( <$infile> ) {
180+
open(my $infile, "<", $custom_simc_file);
181+
while(<$infile>) {
182182
chomp $_;
183183
print {$outfile} "$_\n" if $_ =~ /^action/;
184184
}
185-
close( $infile );
185+
close($infile);
186186

187187
print {$outfile} "]]\n\n";
188188
}
189189

190-
close( $outfile );
190+
close($outfile);
191191
}
192192

193-
print( "\nGenerating normal simc APLs:\n" );
194-
for my $cls ( sort keys %{$profiles} ) {
193+
print("\nGenerating normal simc APLs:\n");
194+
for my $cls (sort keys %{$profiles}) {
195195
my $class_lua_actions_file = "${cfg::script_dir}/ActionProfileLists/actions-${cls}.lua";
196-
open( my $outfile, ">>", $class_lua_actions_file );
196+
open(my $outfile, ">>", $class_lua_actions_file);
197197

198-
for my $spec ( sort keys %{ $profiles->{$cls} } ) {
199-
printf( "%14s / %s\n", $cls, $spec );
198+
for my $spec (sort keys %{ $profiles->{$cls} }) {
199+
printf("%14s / %s\n", $cls, $spec);
200200

201201
print {$outfile} "internal.apls['${simc::branch}::${cls}::${spec}'] = [[\n";
202202

@@ -211,138 +211,138 @@ sub create_action_lists {
211211

212212
my $new_simc_file = "${cfg::script_dir}/Temp/${simc::branch}-${cls}_${spec}.simc";
213213
my $simc_cmd = "\"${simc::directory}/engine/simc\" ${cls}=${cls}_${spec} default_actions=1 level=110 spec=${spec} ${mainhand} ${offhand} ${artifact} \"save=${new_simc_file}\"";
214-
system( "{ $simc_cmd ;} >/dev/null 2>&1" );
215-
die unless ( ( $? >> 8 ) == 0 );
214+
system("{ $simc_cmd ;} >/dev/null 2>&1");
215+
die unless (($? >> 8) == 0);
216216

217-
open( my $infile, "<", $new_simc_file );
218-
while ( <$infile> ) {
217+
open(my $infile, "<", $new_simc_file);
218+
while(<$infile>) {
219219
chomp $_;
220220
print {$outfile} "$_\n" if $_ =~ /^action/;
221221
}
222-
close( $infile );
222+
close($infile);
223223

224224
print {$outfile} "]]\n\n";
225225
}
226226

227-
close( $outfile );
227+
close($outfile);
228228
}
229229
}
230230

231231
sub create_equipped_mapping {
232-
print( "\nGenerating equipped item mapping:\n" );
232+
print("\nGenerating equipped item mapping:\n");
233233
my $equipped_file = "${cfg::script_dir}/ActionProfileLists/equipped.lua";
234-
open( my $outfile, ">", $equipped_file );
234+
open(my $outfile, ">", $equipped_file);
235235
print {$outfile} "local _, internal = ...\n";
236236
print {$outfile} "internal.equipped_mapping = internal.equipped_mapping or {}\n\n";
237237

238238
my @files = <"${cfg::script_dir}/ActionProfileLists/actions-*.lua">;
239239
my %items;
240-
for my $file ( sort @files ) {
241-
open( my $infile, "<", $file );
242-
while ( <$infile> ) {
240+
for my $file (sort @files) {
241+
open(my $infile, "<", $file);
242+
while(<$infile>) {
243243
chomp $_;
244-
while ( $_ =~ m/equipped\.([a-zA-Z][[:alnum:]_]*)/g ) {
244+
while($_ =~ m/equipped\.([a-zA-Z][[:alnum:]_]*)/g) {
245245
$items{$1} = 1;
246246
}
247247
}
248-
close( $infile );
248+
close($infile);
249249
}
250250

251-
for my $item ( sort keys %items ) {
252-
print( " - Item: '${item}'\n" );
251+
for my $item (sort keys %items) {
252+
print(" - Item: '${item}'\n");
253253
my $urlitem = $item;
254254
$urlitem =~ s/_/+/g;
255255
my $url = "http://www.wowhead.com/items/name:${urlitem}/slot:16:18:5:8:11:10:1:23:7:21:2:22:13:24:15:28:14:4:3:19:25:12:17:6:9";
256-
my $data = datacache::get_url( $url );
256+
my $data = datacache::get_url($url);
257257

258258
my %itemids;
259-
while ( $data =~ m/_\[(\d+)\]/g ) {
259+
while($data =~ m/_\[(\d+)\]/g) {
260260
$itemids{$1} = 1;
261261
}
262262

263263
print {$outfile} "internal.equipped_mapping.${item} = { ";
264-
for my $itemid ( sort keys %itemids ) {
264+
for my $itemid (sort keys %itemids) {
265265
print " ID: $itemid\n";
266266
print {$outfile} "$itemid, ";
267267
}
268268
print {$outfile} "}\n";
269269
}
270270

271-
close( $outfile );
271+
close($outfile);
272272
}
273273

274274
sub create_itemset_bonuses {
275-
print( "\nGenerating set bonus listing:\n" );
275+
print("\nGenerating set bonus listing:\n");
276276
my $setbonus_file = "${cfg::script_dir}/ActionProfileLists/itemsets.lua";
277-
open( my $outfile, ">", $setbonus_file );
277+
open(my $outfile, ">", $setbonus_file);
278278
print {$outfile} "local _, internal = ...\n";
279279
print {$outfile} "internal.itemsets = internal.itemsets or {}\n\n";
280280

281-
open( my $infile, "<", "${simc::directory}/dbc_extract3/dbc/generator.py" );
281+
open(my $infile, "<", "${simc::directory}/dbc_extract3/dbc/generator.py");
282282
my $mode = 0;
283283
my $text = "";
284-
while ( <$infile> ) {
284+
while(<$infile>) {
285285
chomp $_;
286286
next if $_ =~ /^\s*#/;
287287
$_ =~ s/#.*//g;
288288
$_ =~ s/'/"/g;
289-
if ( $mode == 0 && $_ =~ /\s*set_bonus_map/ ) {
289+
if($mode == 0 && $_ =~ /\s*set_bonus_map/) {
290290
$mode = 1;
291291
$text .= "[\n";
292292
}
293-
elsif ( $mode == 1 && $_ ne "" ) {
293+
elsif ($mode == 1 && $_ ne "") {
294294
$text .= $_ . "\n";
295295
}
296-
elsif ( $mode == 1 ) {
296+
elsif ($mode == 1) {
297297
$mode = 2;
298298
}
299299
}
300300

301301
# Fixup trailing commas before container terminators
302302
$text =~ s/,([\s\r\n]*[\}\]])/$1/gi;
303303

304-
my $bonuses = from_json( $text );
305-
for my $bonus ( sort { $a->{name} cmp $b->{name} } @{$bonuses} ) {
304+
my $bonuses = from_json($text);
305+
for my $bonus (sort { $a->{name} cmp $b->{name} } @{$bonuses}) {
306306
print " - $bonus->{name}\n";
307307

308308
print {$outfile} "internal.itemsets.$bonus->{name} = { ";
309309

310-
for my $itemset ( sort @{ $bonus->{bonuses} } ) {
310+
for my $itemset (sort @{ $bonus->{bonuses} }) {
311311
my $url = "http://www.wowhead.com/item-set=${itemset}";
312-
my $data = datacache::get_url( $url );
312+
my $data = datacache::get_url($url);
313313
my %items;
314-
while ( $data =~ m/g_items\.add\((\d+)/g ) {
314+
while($data =~ m/g_items\.add\((\d+)/g) {
315315
$items{$1} = 1;
316316
}
317-
for my $itemid ( sort keys %items ) {
317+
for my $itemid (sort keys %items) {
318318
print {$outfile} "${itemid}, ";
319319
}
320320
}
321321

322322
print {$outfile} "}\n";
323323
}
324324

325-
close( $outfile );
325+
close($outfile);
326326
}
327327

328328
sub create_xml_wrapper {
329-
my ( $searchdir ) = @_;
329+
my ($searchdir) = @_;
330330

331-
my $bn = basename( $searchdir );
332-
print( "\nGenerating '${bn}/all.xml'\n" );
333-
open( my $out, ">", "${searchdir}/all.xml" );
331+
my $bn = basename($searchdir);
332+
print("\nGenerating '${bn}/all.xml'\n");
333+
open(my $out, ">", "${searchdir}/all.xml");
334334
print {$out} "<Ui xmlns=\"http://www.blizzard.com/wow/ui/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.blizzard.com/wow/ui/\n";
335335
print {$out} "..\\FrameXML\\UI.xsd\">\n";
336336

337337
my @actionfiles = <"${searchdir}/*.lua">;
338-
for my $actionfile ( sort @actionfiles ) {
339-
$bn = basename( $actionfile );
340-
print( " - ${bn}\n" );
338+
for my $actionfile (sort @actionfiles) {
339+
$bn = basename($actionfile);
340+
print(" - ${bn}\n");
341341
print {$out} " <Script file=\"${bn}\"/>\n";
342342
}
343343

344344
print {$out} "</Ui>\n";
345-
close( $out );
345+
close($out);
346346
}
347347

348348
package main;
@@ -351,5 +351,5 @@ package main;
351351
generator::create_action_lists();
352352
generator::create_equipped_mapping();
353353
generator::create_itemset_bonuses();
354-
generator::create_xml_wrapper( "${cfg::script_dir}/ActionProfileLists" );
355-
generator::create_xml_wrapper( "${cfg::script_dir}/Classes" );
354+
generator::create_xml_wrapper("${cfg::script_dir}/ActionProfileLists");
355+
generator::create_xml_wrapper("${cfg::script_dir}/Classes");

0 commit comments

Comments
 (0)