mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
add -check
This commit is contained in:
parent
84820396a5
commit
162f3ab06c
@ -31,6 +31,7 @@ HTTPBackup::
|
||||
HTTPBackup() {
|
||||
clear_runlines();
|
||||
add_runline("[opts] url");
|
||||
add_runline("-check <days> url");
|
||||
|
||||
set_program_description
|
||||
("This program is designed to run periodically as a "
|
||||
@ -118,6 +119,14 @@ HTTPBackup() {
|
||||
"deleting versions older than -maxage. The default is 1.",
|
||||
&HTTPBackup::dispatch_int, NULL, &_min_keep_versions);
|
||||
|
||||
add_option
|
||||
("check", "days", 0,
|
||||
"Instead of downloading any document, check the date of the most recent "
|
||||
"document downloaded. Returns success if that date is no more than the "
|
||||
"indicated number of days old (which may be a floating-point number), "
|
||||
"or failure otherwise.",
|
||||
&HTTPBackup::dispatch_double, &_got_check_days, &_check_days);
|
||||
|
||||
_dirname = ".";
|
||||
_catalog_name = "Catalog";
|
||||
_version_append = ".%Y-%m-%d.%H-%M";
|
||||
@ -138,6 +147,12 @@ HTTPBackup() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool HTTPBackup::
|
||||
handle_args(ProgramBase::Args &args) {
|
||||
if (_got_check_days && !_document_name.empty() && args.empty()) {
|
||||
// If -check and -n are both specified, we don't really need to
|
||||
// specify an URL. Accept it if we don't.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.size() != 1) {
|
||||
nout <<
|
||||
"You must specify the URL of the document to download "
|
||||
@ -250,25 +265,48 @@ run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Now try to fetch the document.
|
||||
if (!fetch_latest()) {
|
||||
nout << "Errors while processing latest.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!cleanup_old()) {
|
||||
nout << "Errors while cleaning up old versions.\n";
|
||||
// We don't bother to exit the program in this case.
|
||||
}
|
||||
|
||||
if (_catalog._dirty) {
|
||||
// Now write out the modified catalog.
|
||||
nout << "Writing " << _catalog_name << "\n";
|
||||
_catalog_name.make_dir();
|
||||
if (!_catalog.write(_catalog_name)) {
|
||||
nout << "Unable to rewrite " << _catalog_name << ".\n";
|
||||
if (_got_check_days) {
|
||||
// We're only checking the date of the latest download.
|
||||
BackupCatalog::Entries &entries = _catalog._table[_document_name];
|
||||
if (entries.empty()) {
|
||||
nout << "No previous downloads for " << _document_name << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
BackupCatalog::Entry *latest = entries[entries.size() - 1];
|
||||
int diff_secs = _now - latest->get_date();
|
||||
double diff_days = (double)diff_secs / (double)seconds_per_day;
|
||||
nout << "Most recent at " << latest->get_date().get_string()
|
||||
<< ", " << diff_days << " days old.\n";
|
||||
if (diff_days <= _check_days) {
|
||||
nout << "OK.\n";
|
||||
} else {
|
||||
nout << "Too old!\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Try to do the download.
|
||||
|
||||
// Now try to fetch the document.
|
||||
if (!fetch_latest()) {
|
||||
nout << "Errors while processing latest.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!cleanup_old()) {
|
||||
nout << "Errors while cleaning up old versions.\n";
|
||||
// We don't bother to exit the program in this case.
|
||||
}
|
||||
|
||||
if (_catalog._dirty) {
|
||||
// Now write out the modified catalog.
|
||||
nout << "Writing " << _catalog_name << "\n";
|
||||
_catalog_name.make_dir();
|
||||
if (!_catalog.write(_catalog_name)) {
|
||||
nout << "Unable to rewrite " << _catalog_name << ".\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,8 @@ private:
|
||||
int _max_keep_versions;
|
||||
bool _got_max_keep_versions;
|
||||
int _min_keep_versions;
|
||||
double _check_days;
|
||||
bool _got_check_days;
|
||||
|
||||
HTTPDate _max_keep_date;
|
||||
HTTPDate _min_keep_date;
|
||||
|
Loading…
x
Reference in New Issue
Block a user