2018-02-03 Fred Gleason <fredg@paravelsystems.com>

* Converted rdpurgecasts(1) to use RDApplication.
This commit is contained in:
Fred Gleason 2018-02-02 17:01:43 -05:00
parent ddaf40ce4e
commit ebf7033a4c
3 changed files with 33 additions and 42 deletions

View File

@ -16641,3 +16641,5 @@
* Converted rdmaint(1) to use RDApplication. * Converted rdmaint(1) to use RDApplication.
2018-02-03 Fred Gleason <fredg@paravelsystems.com> 2018-02-03 Fred Gleason <fredg@paravelsystems.com>
* Converted rdmarkerset(8) to use RDApplication. * Converted rdmarkerset(8) to use RDApplication.
2018-02-03 Fred Gleason <fredg@paravelsystems.com>
* Converted rdpurgecasts(1) to use RDApplication.

View File

@ -2,7 +2,7 @@
// //
// A Utility to Purge Expired Podcasts. // A Utility to Purge Expired Podcasts.
// //
// (C) Copyright 2007,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2007,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@ -31,64 +31,59 @@
#include <qdir.h> #include <qdir.h>
#include <rd.h> #include <rd.h>
#include <rdconf.h>
#include <rdpurgecasts.h>
#include <rdlibrary_conf.h>
#include <rdescape_string.h>
#include <rddb.h> #include <rddb.h>
#include <rdurl.h> #include <rdapplication.h>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdfeed.h> #include <rdfeed.h>
#include <rdlibrary_conf.h>
#include <rdpodcast.h> #include <rdpodcast.h>
#include <rdurl.h>
#include "rdpurgecasts.h"
MainObject::MainObject(QObject *parent) MainObject::MainObject(QObject *parent)
:QObject(parent) :QObject(parent)
{ {
QString sql; QString sql;
RDSqlQuery *q; RDSqlQuery *q;
unsigned schema=0; QString err_msg;
// //
// Initialize Data Structures // Initialize Data Structures
// //
purge_verbose=false; purge_verbose=false;
//
// Open the Database
//
rda=new RDApplication("rdpurgecasts","rdpurgecasts",RDPURGECASTS_USAGE,this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"rdpurgecasts: %s\n",(const char *)err_msg);
exit(1);
}
// //
// Read Command Options // Read Command Options
// //
purge_cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(), if(rda->cmdSwitch()->keys()>2) {
"rdpurgecasts",RDPURGECASTS_USAGE);
if(purge_cmd->keys()>2) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
fprintf(stderr,"%s",RDPURGECASTS_USAGE); fprintf(stderr,"%s",RDPURGECASTS_USAGE);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
delete purge_cmd;
exit(256); exit(256);
} }
for(unsigned i=0;i<purge_cmd->keys();i++) { for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
if(purge_cmd->key(i)=="--verbose") { if(rda->cmdSwitch()->key(i)=="--verbose") {
purge_verbose=true; purge_verbose=true;
} rda->cmdSwitch()->setProcessed(i,true);
} }
// if(!rda->cmdSwitch()->processed(i)) {
// Read Configuration fprintf(stderr,"rdpurgecasts: unknown command option \"%s\"\n",
// (const char *)rda->cmdSwitch()->key(i));
purge_config=new RDConfig(); exit(2);
purge_config->load(); }
purge_config->setModuleName("rdpurgecasts");
//
// Open Database
//
QString err (tr("rdpurgecasts: "));
QSqlDatabase *db=RDInitDb(&schema,&err);
if(!db) {
fprintf(stderr,err.ascii());
delete purge_cmd;
exit(256);
} }
delete purge_cmd;
// //
// Scan Podcasts // Scan Podcasts
@ -129,9 +124,9 @@ void MainObject::PurgeCast(unsigned id)
where PODCASTS.ID=%u",id); where PODCASTS.ID=%u",id);
q=new RDSqlQuery(sql); q=new RDSqlQuery(sql);
while(q->next()) { while(q->next()) {
feed=new RDFeed(q->value(0).toUInt(),purge_config); feed=new RDFeed(q->value(0).toUInt(),rda->config());
cast=new RDPodcast(purge_config,id); cast=new RDPodcast(rda->config(),id);
cast->removeAudio(feed,&errs,purge_config->logXloadDebugData()); cast->removeAudio(feed,&errs,rda->config()->logXloadDebugData());
if(purge_verbose) { if(purge_verbose) {
printf("purging cast: ID=%d,cmd=\"%s\"\n",id,(const char *)cmd); printf("purging cast: ID=%d,cmd=\"%s\"\n",id,(const char *)cmd);
} }

View File

@ -2,7 +2,7 @@
// //
// A Utility to Purge Expired Podcasts. // A Utility to Purge Expired Podcasts.
// //
// (C) Copyright 2002-2007,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2002-2007,2016-2018 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as // it under the terms of the GNU General Public License version 2 as
@ -22,10 +22,6 @@
#define RDPURGECASTS_H #define RDPURGECASTS_H
#include <qobject.h> #include <qobject.h>
#include <qsqldatabase.h>
#include <rdconfig.h>
#include <rdcmd_switch.h>
#define RDPURGECASTS_USAGE "[--help] [--verbose]\n\nPurge expired podcasts.\n" #define RDPURGECASTS_USAGE "[--help] [--verbose]\n\nPurge expired podcasts.\n"
@ -36,9 +32,7 @@ class MainObject : public QObject
private: private:
void PurgeCast(unsigned id); void PurgeCast(unsigned id);
RDConfig *purge_config;
bool purge_verbose; bool purge_verbose;
RDCmdSwitch *purge_cmd;
}; };