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

* Converted rddelete(1) to use RDApplication.
This commit is contained in:
Fred Gleason 2018-01-31 15:20:06 -05:00
parent 941f846060
commit b1d43dde69
3 changed files with 55 additions and 96 deletions

View File

@ -16623,3 +16623,5 @@
* Converted rdcheckcuts(1) to use RDApplication. * Converted rdcheckcuts(1) to use RDApplication.
2018-02-01 Fred Gleason <fredg@paravelsystems.com> 2018-02-01 Fred Gleason <fredg@paravelsystems.com>
* Converted rdclilogedit(1) to use RDApplication. * Converted rdclilogedit(1) to use RDApplication.
2018-02-01 Fred Gleason <fredg@paravelsystems.com>
* Converted rddelete(1) to use RDApplication.

View File

@ -2,7 +2,7 @@
// //
// A Batch Deleter for Rivendell. // A Batch Deleter for Rivendell.
// //
// (C) Copyright 2013,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2013,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
@ -21,19 +21,17 @@
#include <qapplication.h> #include <qapplication.h>
#include <dbversion.h> #include <dbversion.h>
#include <rdapplication.h>
#include <rdcart.h>
#include <rdconf.h> #include <rdconf.h>
#include <rddelete.h> #include <rddelete.h>
#include <rdcart.h>
#include <rdlog.h> #include <rdlog.h>
MainObject::MainObject(QObject *parent) MainObject::MainObject(QObject *parent)
:QObject(parent) :QObject(parent)
{ {
// QString err_msg;
// Initialize Data Structures
//
bool skip_db_check=false;
unsigned schema=0;
int obj_start=qApp->argc(); int obj_start=qApp->argc();
del_carts=false; del_carts=false;
del_logs=false; del_logs=false;
@ -42,42 +40,59 @@ MainObject::MainObject(QObject *parent)
del_dry_run=false; del_dry_run=false;
del_obj_ptr=0; del_obj_ptr=0;
//
// Open the Database
//
rda=new RDApplication("rddelete","rddelete",RDDELETE_USAGE,this);
if(!rda->open(&err_msg)) {
fprintf(stderr,"rddelete: %s\n",(const char *)err_msg);
exit(1);
}
connect(RDDbStatus(),SIGNAL(logText(RDConfig::LogPriority,const QString &)),
this,SLOT(log(RDConfig::LogPriority,const QString &)));
// //
// Read Command Options // Read Command Options
// //
del_cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"rddelete",RDDELETE_USAGE); if(rda->cmdSwitch()->keys()<1) {
if(del_cmd->keys()<1) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
fprintf(stderr,"%s",RDDELETE_USAGE); fprintf(stderr,"%s",RDDELETE_USAGE);
fprintf(stderr,"\n"); fprintf(stderr,"\n");
delete del_cmd; delete rda->cmdSwitch();
exit(256); exit(256);
} }
for(unsigned i=0;i<del_cmd->keys();i++) { for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
if(del_cmd->key(i)=="--verbose") { if(rda->cmdSwitch()->key(i)=="--verbose") {
del_verbose=true; del_verbose=true;
rda->cmdSwitch()->setProcessed(i,true);
} }
if(del_cmd->key(i)=="--continue-after-error") { if(rda->cmdSwitch()->key(i)=="--continue-after-error") {
del_continue_after_error=true; del_continue_after_error=true;
rda->cmdSwitch()->setProcessed(i,true);
} }
if(del_cmd->key(i)=="--dry-run") { if(rda->cmdSwitch()->key(i)=="--dry-run") {
del_dry_run=true; del_dry_run=true;
rda->cmdSwitch()->setProcessed(i,true);
} }
if(del_cmd->key(i)=="--skip-db-check") { if(rda->cmdSwitch()->key(i)=="--carts") {
skip_db_check=true;
}
if(del_cmd->key(i)=="--carts") {
del_carts=true; del_carts=true;
obj_start=i+2; obj_start=i+2;
i=del_cmd->keys(); rda->cmdSwitch()->setProcessed(i,true);
i=rda->cmdSwitch()->keys();
break; break;
} }
if(del_cmd->key(i)=="--logs") { if(rda->cmdSwitch()->key(i)=="--logs") {
del_logs=true; del_logs=true;
obj_start=i+2; obj_start=i+2;
i=del_cmd->keys(); rda->cmdSwitch()->setProcessed(i,true);
i=rda->cmdSwitch()->keys();
break; break;
} }
if(!rda->cmdSwitch()->processed(i)) {
fprintf(stderr,"rddelete: unknown command option \"%s\"\n",
(const char *)rda->cmdSwitch()->key(i));
exit(2);
}
} }
// //
@ -92,52 +107,11 @@ MainObject::MainObject(QObject *parent)
} }
} }
//
// Read Configuration
//
del_config=new RDConfig();
del_config->load();
del_config->setModuleName("rddelete");
//
// Open Database
//
QString err;
del_db=RDInitDb(&schema,&err);
if(!del_db) {
fprintf(stderr,"rddelete: %s\n",(const char *)err);
exit(1);
}
if((schema!=RD_VERSION_DATABASE)&&(!skip_db_check)) {
fprintf(stderr,"rddelete: database version mismatch, should be %u, is %u\n",
RD_VERSION_DATABASE,schema);
exit(256);
}
connect (RDDbStatus(),SIGNAL(logText(RDConfig::LogPriority,const QString &)),
this,SLOT(log(RDConfig::LogPriority,const QString &)));
//
// System Configuration
//
del_system=new RDSystem();
//
// Station Configuration
//
del_station=new RDStation(del_config->stationName());
//
// User
//
del_user=NULL;
// //
// RIPC Connection // RIPC Connection
// //
del_ripc=new RDRipc(del_station,del_config,this); connect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData()));
connect(del_ripc,SIGNAL(userChanged()),this,SLOT(userData())); rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
del_ripc->connectHost("localhost",RIPCD_TCP_PORT,del_config->password());
// //
// Print Status Messages // Print Status Messages
@ -174,28 +148,25 @@ void MainObject::userData()
// //
// Get User Context // Get User Context
// //
disconnect(del_ripc,SIGNAL(userChanged()),this,SLOT(userData())); disconnect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData()));
if(del_user!=NULL) { rda->user()->setName(rda->ripc()->user());
delete del_user;
}
del_user=new RDUser(del_ripc->user());
// //
// Process Objects // Process Objects
// //
if(del_carts) { if(del_carts) {
if(!del_user->editAudio()) { if(!rda->user()->editAudio()) {
fprintf(stderr,"rdimport: user \"%s\" has no edit audio permission\n", fprintf(stderr,"rdimport: user \"%s\" has no edit audio permission\n",
(const char *)del_user->name()); (const char *)rda->user()->name());
exit(256); exit(256);
} }
DeleteCarts(); DeleteCarts();
} }
if(del_logs) { if(del_logs) {
if(!del_user->deleteLog()) { if(!rda->user()->deleteLog()) {
fprintf(stderr,"rdimport: user \"%s\" has no delete log permission\n", fprintf(stderr,"rdimport: user \"%s\" has no delete log permission\n",
(const char *)del_user->name()); (const char *)rda->user()->name());
exit(256); exit(256);
} }
DeleteLogs(); DeleteLogs();
@ -207,7 +178,7 @@ void MainObject::userData()
void MainObject::log(RDConfig::LogPriority prio,const QString &msg) void MainObject::log(RDConfig::LogPriority prio,const QString &msg)
{ {
del_config->log("rddelete",prio,msg); rda->config()->log("rddelete",prio,msg);
} }
@ -236,7 +207,7 @@ void MainObject::DeleteCarts()
} }
} }
else { else {
if(cart->remove(del_station,del_user,del_config)) { if(cart->remove(rda->station(),rda->user(),rda->config())) {
if(del_verbose) { if(del_verbose) {
printf("deleted cart %06u [%s]\n",cartnum,(const char *)title); printf("deleted cart %06u [%s]\n",cartnum,(const char *)title);
} }
@ -276,7 +247,7 @@ void MainObject::DeleteLogs()
} }
} }
else { else {
if(log->remove(del_station,del_user,del_config)) { if(log->remove(rda->station(),rda->user(),rda->config())) {
if(del_verbose) { if(del_verbose) {
printf("deleted log \"%s\"\n",(const char *)logname); printf("deleted log \"%s\"\n",(const char *)logname);
} }

View File

@ -2,7 +2,7 @@
// //
// A Batch Deleter for Rivendell. // A Batch Deleter for Rivendell.
// //
// (C) Copyright 2013,2016 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2013,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
@ -23,22 +23,15 @@
#include <vector> #include <vector>
#include <qobject.h>
#include <qsqldatabase.h>
#include <qfileinfo.h>
#include <qdatetime.h> #include <qdatetime.h>
#include <qfileinfo.h>
#include <qobject.h>
#include <rdwavedata.h>
#include <rdwavefile.h>
#include <rdconfig.h>
#include <rdcmd_switch.h>
#include <rdgroup.h>
#include <rdcart.h> #include <rdcart.h>
#include <rdcut.h> #include <rdcut.h>
#include <rdripc.h> #include <rdgroup.h>
#include <rduser.h> #include <rdwavedata.h>
#include <rdsystem.h> #include <rdwavefile.h>
#include <rdstation.h>
#define RDDELETE_STDIN_BUFFER_LENGTH 1024 #define RDDELETE_STDIN_BUFFER_LENGTH 1024
#define RDDELETE_USAGE "[options] <obj-type> [<obj-id> ...]\n\nDelete objects from a Rivendell system. Each type of object to be deleted\nis specified by an appropriate <obj-type> switch, followed optionally by\na list of objects. If no list is specified, then rddelete(1) will read\nthe list of objects from standard input.\n\nThe following object types can be deleted:\n--carts\n Delete carts. The <obj-id> values should be cart numbers.\n\n--logs\n Delete logs. The <obj-id> values should be log names.\n\nThe following options are available:\n\n--verbose\n Print progress messages during processing.\n\n--continue-after-error\n Continue processing list of objects even in the face of errors in\n that list.\n\n--dry-run\n Process list of objects, but don't actually delete anything.\n" #define RDDELETE_USAGE "[options] <obj-type> [<obj-id> ...]\n\nDelete objects from a Rivendell system. Each type of object to be deleted\nis specified by an appropriate <obj-type> switch, followed optionally by\na list of objects. If no list is specified, then rddelete(1) will read\nthe list of objects from standard input.\n\nThe following object types can be deleted:\n--carts\n Delete carts. The <obj-id> values should be cart numbers.\n\n--logs\n Delete logs. The <obj-id> values should be log names.\n\nThe following options are available:\n\n--verbose\n Print progress messages during processing.\n\n--continue-after-error\n Continue processing list of objects even in the face of errors in\n that list.\n\n--dry-run\n Process list of objects, but don't actually delete anything.\n"
@ -59,13 +52,6 @@ class MainObject : public QObject
bool GetNextObject(unsigned *cartnum); bool GetNextObject(unsigned *cartnum);
bool GetNextObject(QString *logname); bool GetNextObject(QString *logname);
bool GetNextStdinObject(QString *logname); bool GetNextStdinObject(QString *logname);
QSqlDatabase *del_db;
RDSystem *del_system;
RDStation *del_station;
RDCmdSwitch *del_cmd;
RDRipc *del_ripc;
RDUser *del_user;
RDConfig *del_config;
bool del_carts; bool del_carts;
bool del_logs; bool del_logs;
bool del_verbose; bool del_verbose;