コード例 #1
0
int RunLogOperation(int argc,char *argv[],const QString &svcname,
                    int start_offset,bool protect_existing,bool gen_log,
                    bool merge_mus,bool merge_tfc)
{
    QString sql;
    RDSqlQuery *q;
    QString report;
    QString unused_report;
    QString svcname_table=svcname;
    svcname_table.replace(" ","_");

    //
    // Some Basic Structures
    //
#ifndef WIN32
    rda->setUser(rda->station()->defaultName());
#endif  // WIN32
    RDSvc *svc=new RDSvc(svcname);
    if(!svc->exists()) {
        fprintf(stderr,"rdlogmanager: no such service\n");
        return 256;
    }
    QDate start_date=QDate::currentDate().addDays(1+start_offset);
    QString logname=RDDateDecode(svc->nameTemplate(),start_date);
    RDLog *log=new RDLog(logname);

    //
    // Generate Log
    //
    if(gen_log) {
        if(protect_existing&&log->exists()) {
            fprintf(stderr,"log \"%s\" already exists\n",
                    (const char *)log->name().utf8());
            exit(256);
        }
        log->removeTracks(rda->station(),rda->user(),rda->config());
        srand(QTime::currentTime().msec());
        sql=RDCreateStackTableSql(svcname_table);
        q=new RDSqlQuery(sql);
        if(!q->isActive()) {
            fprintf(stderr,"SQL: %s\n",(const char *)sql);
            fprintf(stderr,"SQL Error: %s\n",
                    (const char *)q->lastError().databaseText());
        }
        delete q;
        if(!svc->generateLog(start_date,
                             RDDateDecode(svc->nameTemplate(),start_date),
                             RDDateDecode(svc->nameTemplate(),start_date.addDays(1)),
                             &unused_report)) {
            fprintf(stderr,"rdlogmanager: unable to generate log\n");
            return 256;
        }
        log->updateTracks();

        //
        // Generate Exception Report
        //
        RDLogEvent *event=
            new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
        event->load();
        if((event->validate(&report,start_date)!=0)||
                (!unused_report.isEmpty())) {
            printf("%s\n\n%s",(const char*)report,(const char*)unused_report);
        }
        delete event;
    }

    //
    // Merge Music
    //
    if(merge_mus) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceMusic)==RDLog::LinkDone)) {
            fprintf(stderr,"rdlogmanager: music for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        log->removeTracks(rda->station(),rda->user(),rda->config());
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        svc->clearLogLinks(RDSvc::Music,start_date,logname);
        if(svc->linkLog(RDSvc::Music,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open music schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Music,start_date));
            exit(256);
        }
    }

    //
    // Merge Traffic
    //
    if(merge_tfc) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceTraffic)==RDLog::LinkDone)) {
            fprintf(stderr,
                    "rdlogmanager: traffic for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        if(svc->linkLog(RDSvc::Traffic,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open traffic schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Traffic,start_date));
        }
    }

    //
    // Clean Up
    //
    delete log;
    delete svc;
    return 0;
}
コード例 #2
0
ファイル: generate_log.cpp プロジェクト: WMFO/rivendell
void GenerateLog::createData()
{
  QString report;
  QString unused_report;
  QString str1;
  QString str2;
  unsigned tracks=0;

  //
  // Generate Log
  //
  RDSvc *svc=new RDSvc(gen_service_box->currentText(),this);
  QString logname=RDDateDecode(svc->nameTemplate(),gen_date_edit->date());
  RDLog *log=new RDLog(logname);
  if(log->exists()) {
    str1=QString(tr("The log for"));
    str2=QString(tr("already exists.  Recreating it\nwill remove any merged Music or Traffic events.\n\nRecreate?"));
    if(QMessageBox::question(this,tr("Log Exists"),
			     QString().sprintf("%s %s %s",(const char *)str1,
		 (const char *)gen_date_edit->date().toString("MM/dd/yyyy"),
					       (const char *)str2),
			     QMessageBox::Yes,QMessageBox::No)!=
       QMessageBox::Yes) {
      delete log;
      delete svc;
      return;
    }
    if((tracks=log->completedTracks())>0) {
      str1=QString(tr("This will also delete the"));
      str2=QString(tr("voice tracks associated with this log.\nContinue?"));
      if(QMessageBox::warning(this,tr("Tracks Exist"),
			      QString().sprintf("%s %u %s",
						(const char *)str1,
						tracks,
						(const char *)str2),
			      QMessageBox::Yes,QMessageBox::No)!=
	 QMessageBox::Yes) {
	delete log;
	delete svc;
	return;
      }
    }
  }
  log->removeTracks(rda->station(),rda->user(),rda->config());

  //
  // Scheduler
  //
  QString sql;
  RDSqlQuery *q;

  srand(QTime::currentTime().msec());
  sql=RDCreateStackTableSql(gen_service_box->currentText().replace(" ","_")); 

  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    fprintf(stderr,"SQL: %s\n",(const char *)sql);
    fprintf(stderr,"SQL Error: %s\n",
	    (const char *)q->lastError().databaseText());
    delete q;
  }
  delete q;

  connect(svc,SIGNAL(generationProgress(int)),
	  gen_progress_dialog,SLOT(setProgress(int)));
  svc->generateLog(gen_date_edit->date(),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date()),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date().
				addDays(1)),&unused_report);
  log->updateTracks();
  delete log;
  delete svc;

  //
  // Generate Exception Report
  //
  RDLogEvent *event=
    new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
  event->load();
  if((event->validate(&report,gen_date_edit->date())==0)&&
     unused_report.isEmpty()) {
    QMessageBox::information(this,tr("No Errors"),tr("No exceptions found."));
  }
  else {
    RDTextFile(report+"\n\n"+unused_report);
  }
  delete event;

  UpdateControls();
}