[Slim-Checkins] r10843 - in /trunk/server: Slim/Utils/Strings.pm
slimserver.pl
adrian at svn.slimdevices.com
adrian at svn.slimdevices.com
Sun Dec 3 10:47:10 PST 2006
Author: adrian
Date: Sun Dec 3 10:47:09 2006
New Revision: 10843
URL: http://svn.slimdevices.com?rev=10843&view=rev
Log:
Bug: N/A
Description: new commandline option to help plugin development:
--checkstrings. This will monitor mtime of string files and reload
any which have changed while the server is running.
Modified:
trunk/server/Slim/Utils/Strings.pm
trunk/server/slimserver.pl
Modified: trunk/server/Slim/Utils/Strings.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Strings.pm?rev=10843&r1=10842&r2=10843&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Strings.pm (original)
+++ trunk/server/Slim/Utils/Strings.pm Sun Dec 3 10:47:09 2006
@@ -57,26 +57,30 @@
=head2 init( )
- Initializes the module - called at server startup.
+Initializes the module - called at server startup.
=cut
sub init {
$currentLang = getLanguage();
loadStrings();
+
+ if ($::checkstrings) {
+ checkChangedStrings();
+ }
}
=head2 loadStrings( [ $argshash ] )
- Load/Reload Strings files for server and plugins using cache if valid.
- If stringcache file is valid this is loaded into memory and used as string hash, otherwise
- string text files are parsed and new stringhash creted which stored as the stringcache file.
-
- optional $argshash allows default behavious to be overridden, keys that can be set are:
- 'ignoreCache' - ignore cache file and reparse all files
- 'dontClear' - don't clear current string hash before loading file
- 'dontSave' - don't save new string hash to cache file [restart will use old cache file]
- 'storeString' - sub as alternative to storeString [e.g. for use by string editor]
+Load/Reload Strings files for server and plugins using cache if valid.
+If stringcache file is valid this is loaded into memory and used as string hash, otherwise
+string text files are parsed and new stringhash creted which stored as the stringcache file.
+
+optional $argshash allows default behavious to be overridden, keys that can be set are:
+'ignoreCache' - ignore cache file and reparse all files
+'dontClear' - don't clear current string hash before loading file
+'dontSave' - don't save new string hash to cache file [restart will use old cache file]
+'storeString' - sub as alternative to storeString [e.g. for use by string editor]
=cut
@@ -306,7 +310,7 @@
return if ($name eq 'LANGUAGE_CHOICES');
- if (defined $strings->{$currentLang}->{$name}) {
+ if (defined $strings->{$currentLang}->{$name} && $strings->{$currentLang}->{$name} ne $curString->{$currentLang}) {
$log->warn("redefined string: $name in $file");
}
@@ -443,4 +447,27 @@
}
+# Timer task to check mtime of string files and reload if they have changed.
+# Started by init when --checkstrings is present on command line.
+my $lastChange = time;
+
+sub checkChangedStrings {
+
+ my $reload;
+
+ for my $file (@{$strings->{'files'}}) {
+ if ((stat($file))[9] > $lastChange) {
+ $log->info("$file updated - reparsing");
+ loadFile($file);
+ $reload ||= time;
+ }
+ }
+
+ if ($reload) {
+ $lastChange = $reload;
+ }
+
+ Slim::Utils::Timers::setTimer(undef, time + 1, \&checkChangedStrings);
+}
+
1;
Modified: trunk/server/slimserver.pl
URL: http://svn.slimdevices.com/trunk/server/slimserver.pl?rev=10843&r1=10842&r2=10843&view=diff
==============================================================================
--- trunk/server/slimserver.pl (original)
+++ trunk/server/slimserver.pl Sun Dec 3 10:47:09 2006
@@ -213,6 +213,7 @@
$stop,
$perfmon,
$perfwarn,
+ $checkstrings,
$d_startup, # Needed for Slim::bootstrap
);
@@ -488,7 +489,7 @@
[--priority <priority>]
[--prefsfile <prefsfilepath> [--pidfile <pidfilepath>]]
[--perfmon] [--perfwarn=<threshold>]
- [--d_various]
+ [--checkstrings]
--help => Show this usage information.
--audiodir => The path to a directory of your MP3 files.
@@ -528,6 +529,7 @@
--noupnp => Disable UPnP subsystem
--perfmon => Enable internal server performance monitoring
--perfwarn => Generate log messages if internal tasks take longer than specified threshold
+ --checkstrings => Enable reloading of changed string files for plugin development
Commands may be sent to the server through standard in and will be echoed via
standard out. See complete documentation for details on the command syntax.
@@ -565,7 +567,8 @@
'noserver' => \$noserver,
'noupnp' => \$noupnp,
'perfmon' => \$perfmon,
- 'perfwarn=f' => \$perfwarn,
+ 'perfwarn=f' => \$perfwarn,
+ 'checkstrings' => \$checkstrings,
'd_startup' => \$d_startup, # Needed for Slim::bootstrap
)) {
showUsage();
More information about the checkins
mailing list