mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
add -check
This commit is contained in:
parent
84820396a5
commit
162f3ab06c
@ -31,6 +31,7 @@ HTTPBackup::
|
|||||||
HTTPBackup() {
|
HTTPBackup() {
|
||||||
clear_runlines();
|
clear_runlines();
|
||||||
add_runline("[opts] url");
|
add_runline("[opts] url");
|
||||||
|
add_runline("-check <days> url");
|
||||||
|
|
||||||
set_program_description
|
set_program_description
|
||||||
("This program is designed to run periodically as a "
|
("This program is designed to run periodically as a "
|
||||||
@ -118,6 +119,14 @@ HTTPBackup() {
|
|||||||
"deleting versions older than -maxage. The default is 1.",
|
"deleting versions older than -maxage. The default is 1.",
|
||||||
&HTTPBackup::dispatch_int, NULL, &_min_keep_versions);
|
&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 = ".";
|
_dirname = ".";
|
||||||
_catalog_name = "Catalog";
|
_catalog_name = "Catalog";
|
||||||
_version_append = ".%Y-%m-%d.%H-%M";
|
_version_append = ".%Y-%m-%d.%H-%M";
|
||||||
@ -138,6 +147,12 @@ HTTPBackup() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool HTTPBackup::
|
bool HTTPBackup::
|
||||||
handle_args(ProgramBase::Args &args) {
|
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) {
|
if (args.size() != 1) {
|
||||||
nout <<
|
nout <<
|
||||||
"You must specify the URL of the document to download "
|
"You must specify the URL of the document to download "
|
||||||
@ -250,25 +265,48 @@ run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now try to fetch the document.
|
if (_got_check_days) {
|
||||||
if (!fetch_latest()) {
|
// We're only checking the date of the latest download.
|
||||||
nout << "Errors while processing latest.\n";
|
BackupCatalog::Entries &entries = _catalog._table[_document_name];
|
||||||
exit(1);
|
if (entries.empty()) {
|
||||||
}
|
nout << "No previous downloads for " << _document_name << ".\n";
|
||||||
|
|
||||||
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);
|
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;
|
int _max_keep_versions;
|
||||||
bool _got_max_keep_versions;
|
bool _got_max_keep_versions;
|
||||||
int _min_keep_versions;
|
int _min_keep_versions;
|
||||||
|
double _check_days;
|
||||||
|
bool _got_check_days;
|
||||||
|
|
||||||
HTTPDate _max_keep_date;
|
HTTPDate _max_keep_date;
|
||||||
HTTPDate _min_keep_date;
|
HTTPDate _min_keep_date;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user