// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// This is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation;
// either version 2.1 of the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// db_dump: dump database views in XML format
//
// usage: db_dump [-d n] -dump_spec file
// -d debug level (1,2,3)
//
// dump_spec file:
//
// x
// x
// [ X ]
//
//
// x
// x x = id, total_credit, expavg_credit
//
// ...
//
// ...
//
// output_dir is temp directory (usually ../html/stats_tmp)
// final_out_dir is what to rename this to when done (usually ../html/stats)
// (this is to avoid exporting incomplete stats)
// archive_dir: if present, when done, move old final_out_dir
// to archive_dir/stats_DATE
// Otherwise rename old final_out_dir to final_out_dir_DATE
// Note: this program is way more configurable than it needs to be.
// All projects export stats in the same format,
// as described in the default db_dump_spec.xml that is created for you.
#include "config.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "boinc_db.h"
#include "filesys.h"
#include "util.h"
#include "error_numbers.h"
#include "md5_file.h"
#include "parse.h"
#include "sched_config.h"
#include "sched_util.h"
#include "sched_msgs.h"
using std::string;
using std::vector;
#define LOCKFILE "db_dump.out"
#define COMPRESSION_NONE 0
#define COMPRESSION_GZIP 1
#define COMPRESSION_ZIP 2
#define SORT_NONE 0
#define SORT_ID 1
#define SORT_TOTAL_CREDIT 2
#define SORT_EXPAVG_CREDIT 3
#define TABLE_USER 0
#define TABLE_TEAM 1
#define TABLE_HOST 2
// must match the above
const char* table_name[3] = {"user", "team", "host"};
const char* tag_name[3] = {"users", "teams", "hosts"};
int nusers, nhosts, nteams;
double total_credit;
struct OUTPUT {
int recs_per_file;
bool detail;
int compression;
class ZFILE* zfile;
class NUMBERED_ZFILE* nzfile;
int parse(FILE*);
};
struct ENUMERATION {
int table;
int sort;
char filename[256];
vector")) return 0;
if (parse_int(buf, "", recs_per_file)) continue;
if (match_tag(buf, "")) {
detail = true;
continue;
}
if (parse_str(buf, "", buf2, sizeof(buf2))) {
if (!strcmp(buf2, "gzip")) {
compression = COMPRESSION_GZIP;
} else if (!strcmp(buf2, "zip")) {
compression = COMPRESSION_ZIP;
} else {
log_messages.printf(
SCHED_MSG_LOG::MSG_CRITICAL,
"unrecognized compression type: %s", buf
);
}
continue;
}
log_messages.printf(
SCHED_MSG_LOG::MSG_CRITICAL,
"OUTPUT::parse: unrecognized: %s", buf
);
}
return ERR_XML_PARSE;
}
int ENUMERATION::parse(FILE* in) {
char buf[256], buf2[256];
int retval, i;
table = -1;
sort = SORT_NONE;
strcpy(filename, "");
while (fgets(buf, 256, in)) {
if (match_tag(buf, "")) {
if (table == -1) return ERR_XML_PARSE;
if (sort == -1) return ERR_XML_PARSE;
if (!strlen(filename)) return ERR_XML_PARSE;
return 0;
}
if (match_tag(buf, "