* Fixed a bug in Words->parse_banged_string() where values with commas was breaking the processing of the string of variable/value pairs.

* Added '--refresh-json' to anvil-daemon that auto-selects '--run-once', '--main-loop-only' and '--no-start'.
* Updated anvil-update-system to not go more than a second between updates to the progress (save for when we're holding on data from 'dnf').

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent b656af88c7
commit 962ff89fc5
  1. 43
      Anvil/Tools/Words.pm
  2. 4
      share/words.xml
  3. 24
      tools/anvil-daemon
  4. 34
      tools/anvil-update-system

@ -250,6 +250,8 @@ sub language
This takes a string (usually from a DB record) in the format C<< <string_key>[,!!var1!value1!!,!!var2!value2!!,...,!!varN!valueN!! >> and converts it into an actual string. This takes a string (usually from a DB record) in the format C<< <string_key>[,!!var1!value1!!,!!var2!value2!!,...,!!varN!valueN!! >> and converts it into an actual string.
If there is a problem processing the string, C<< !!error!! >> is returned.
Parameters; Parameters;
=head3 key_string (required) =head3 key_string (required)
@ -291,31 +293,42 @@ sub parse_banged_string
key => $key, key => $key,
variable_string => $variable_string, variable_string => $variable_string,
}}); }});
foreach my $pair (split/,/, $variable_string) my $loop = 0;
while ($variable_string)
{ {
my $pair = ($variable_string =~ /^(!!.*?!.*?!!).*$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pair => $pair }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pair => $pair }});
my $name = "";
my $value = ""; my ($variable, $value) = ($pair =~ /^!!(.*?)!(.*?)!!$/);
if ($pair =~ /^!!(.*?)!(.*)!!$/)
{
$name = $1;
$value = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
name => $name, variable => $variable,
value => $value, value => $value,
}}); }});
}
elsif ($pair =~ /^!!(.*?)!!!$/) # Remove this pair
$variable_string =~ s/^$pair//;
$variable_string =~ s/^,//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_string => $variable_string }});
if (not $variable)
{ {
$name = $1; # Variable missing, nothing we can do with this.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { name => $name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0206", variables => { message => $message }});
} }
else else
{ {
# what?! # Record the variable/value pair
$variables->{$variable} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "variables->$variable" => $variables->{$variable} }});
}
$loop++;
if ($loop > 10000)
{
# Stuck in an infinite loop.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0037", variables => { message => $message }});
return("!!error!!");
} }
$variables->{$name} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "variables->$name" => $variables->{$name} }});
} }
# Parse the line now. # Parse the line now.

@ -92,7 +92,7 @@ Report if a reboot is needed: #!variable!program!#
<key name="message_0056">Previous run exited early. Restarting momentarily.</key> <key name="message_0056">Previous run exited early. Restarting momentarily.</key>
<key name="message_0057">No updates were found or needed.</key> <key name="message_0057">No updates were found or needed.</key>
<!-- NOTE: If you change the variable names below, you have to update 'anvil-update-system' as well. --> <!-- NOTE: If you change the variable names below, you have to update 'anvil-update-system' as well. -->
<key name="message_0058">Packages downloaded: [#!variable!downloaded!#], Installed/Updates: [#!variable!installed!#], Verified: [#!variable!verified!#], Output lines: [#!variable!lines!#].</key> <key name="message_0058">* Packages downloaded: [#!variable!downloaded!#], Installed or updated: [#!variable!installed!#], Verified: [#!variable!verified!#], Output lines: [#!variable!lines!#].</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>
@ -333,6 +333,7 @@ The database connection error was:
<key name="log_0203">Disconnected from all databases. Will reconnect when entering the main loop.</key> <key name="log_0203">Disconnected from all databases. Will reconnect when entering the main loop.</key>
<key name="log_0204">Starting the background process: [#!variable!call!#] now.</key> <key name="log_0204">Starting the background process: [#!variable!call!#] now.</key>
<key name="log_0205">Background process: [#!variable!call!#] running with PID: [#!variable!pid!#].</key> <key name="log_0205">Background process: [#!variable!call!#] running with PID: [#!variable!pid!#].</key>
<key name="log_0206">In Words->parse_banged_string(), while processing: [#!variable!message!#], a variable name was found to be missing.</key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. --> <!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key> <key name="t_0000">Test</key>
@ -529,6 +530,7 @@ The update appears to have not completed successfully. The output was:
==== ====
</key> </key>
<key name="error_0036"></key> <key name="error_0036"></key>
<key name="error_0037">In Words->parse_banged_string(), an infinite loop was detected while processing: [#!variable!message!#].</key>
<!-- These are units, words and so on used when displaying information. --> <!-- These are units, words and so on used when displaying information. -->
<key name="unit_0001">Yes</key> <key name="unit_0001">Yes</key>

@ -59,11 +59,19 @@ if (not $anvil->data->{sys}{database}{connections})
} }
# Read switches # Read switches
$anvil->data->{switches}{'run-once'} = ""; $anvil->data->{switches}{'refresh-json'} = "";
$anvil->data->{switches}{'main-loop-only'} = ""; $anvil->data->{switches}{'run-once'} = 0;
$anvil->data->{switches}{'main-loop-only'} = 0;
$anvil->data->{switches}{'no-start'} = 0; $anvil->data->{switches}{'no-start'} = 0;
$anvil->Get->switches; $anvil->Get->switches;
if ($anvil->data->{switches}{'refresh-json'})
{
$anvil->data->{switches}{'run-once'} = 1;
$anvil->data->{switches}{'main-loop-only'} = 1;
$anvil->data->{switches}{'no-start'} = 1;
}
# There are some things we only want to run on (re)start and don't need to always run. # There are some things we only want to run on (re)start and don't need to always run.
run_once($anvil) if not $anvil->data->{switches}{'main-loop-only'}; run_once($anvil) if not $anvil->data->{switches}{'main-loop-only'};
@ -335,10 +343,10 @@ sub run_jobs
} }
# Convert the double-banged strings into a proper message. # Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : ""; my $say_title = $job_title ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : ""; my $say_description = $job_description ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_description}) : "";
my $say_status = $job_status ? $anvil->Words->parse_banged_string({key_string => $job_status}) : ""; my $say_status = $job_status ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_status}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_title => $job_title, job_title => $job_title,
say_description => $say_description, say_description => $say_description,
say_status => $say_status, say_status => $say_status,
@ -349,7 +357,7 @@ sub run_jobs
{ {
my $html_strip = HTML::Strip->new(); my $html_strip = HTML::Strip->new();
$say_status = $html_strip->parse($say_status); $say_status = $html_strip->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }});
# Now make the resulting text string HTML friendly # Now make the resulting text string HTML friendly
my $text_to_html = HTML::FromText->new({ my $text_to_html = HTML::FromText->new({
@ -358,7 +366,7 @@ sub run_jobs
lines => 1, lines => 1,
}); });
$say_status = $text_to_html->parse($say_status); $say_status = $text_to_html->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }});
} }
# Add this to the jobs.json file # Add this to the jobs.json file

@ -141,6 +141,7 @@ WHERE
} }
# Clea any old runs. # Clea any old runs.
$anvil->data->{sys}{last_update} = time;
update_progress($anvil, 0, "clear"); update_progress($anvil, 0, "clear");
# We'll keep a count of lines and packages to show the user. # We'll keep a count of lines and packages to show the user.
@ -150,8 +151,8 @@ $anvil->data->{counts}{verified} = 0;
$anvil->data->{counts}{lines} = 0; $anvil->data->{counts}{lines} = 0;
# Mark that we're starting # Mark that we're starting
update_progress($anvil, 1, "message_0033"); update_progress($anvil, 1, "message_0058,!!downloaded!0!!,!!installed!0!!,!!verified!0!!,!!lines!0!!");
update_progress($anvil, 2, "message_0058,!!downloaded!0!!,!!installed!0!!,!!verified!0!!,!!lines!0!!"); update_progress($anvil, 2, "message_0033");
# Make sure maintenance mode is enabled. # Make sure maintenance mode is enabled.
$anvil->System->maintenance_mode({debug => 3, set => 1}); $anvil->System->maintenance_mode({debug => 3, set => 1});
@ -248,13 +249,23 @@ WHERE
# Insert counts # Insert counts
if ($job_status =~ /message_0058/gs) if ($job_status =~ /message_0058/gs)
{ {
my $downloaded = $anvil->Convert->add_commas({number => $anvil->data->{counts}{downloaded}}); my $downloaded = $anvil->data->{counts}{downloaded} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{downloaded}}) : 0;
my $installed = $anvil->Convert->add_commas({number => $anvil->data->{counts}{installed}}); my $installed = $anvil->data->{counts}{installed} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{installed}}) : 0;
my $verified = $anvil->Convert->add_commas({number => $anvil->data->{counts}{verified}}); my $verified = $anvil->data->{counts}{verified} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{verified}}) : 0;
my $lines = $anvil->Convert->add_commas({number => $anvil->data->{counts}{lines}}); my $lines = $anvil->data->{counts}{lines} ? $anvil->Convert->add_commas({number => $anvil->data->{counts}{lines}}) : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:counts::downloaded" => $anvil->data->{counts}{downloaded},
"s2:downloaded" => $downloaded,
"s3:counts::installed" => $anvil->data->{counts}{installed},
"s4:installed" => $installed,
"s5:counts::verified" => $anvil->data->{counts}{verified},
"s6:verified" => $verified,
"s7:counts::lines" => $anvil->data->{counts}{lines},
"s8:lines" => $lines,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ">> job_status" => $job_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ">> job_status" => $job_status }});
$job_status =~ s/message_0058,!!downloaded!\d+!!,!!installed!\d+!!,!!verified!\d+!!,!!lines!\d+!!/message_0058,!!downloaded!$downloaded!!,!!installed!$installed!!,!!verified!$verified!!,!!lines!$lines!!/sm; $job_status =~ s/message_0058,!!downloaded!.*?!!,!!installed!.*?!!,!!verified!.*?!!,!!lines!.*?!!/message_0058,!!downloaded!$downloaded!!,!!installed!$installed!!,!!verified!$verified!!,!!lines!$lines!!/sm;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "<< job_status" => $job_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "<< job_status" => $job_status }});
} }
@ -273,6 +284,9 @@ WHERE
"; ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
# Note this update time
$anvil->data->{sys}{last_update} = time;
} }
return(0); return(0);
@ -416,6 +430,12 @@ sub run_os_update
update_progress($anvil, $progress, ""); update_progress($anvil, $progress, "");
} }
} }
# Update the progress if it's been more than a second since the last update.
if (time > $anvil->data->{sys}{last_update})
{
update_progress($anvil, $progress, "");
}
} }
close $file_handle; close $file_handle;

Loading…
Cancel
Save