mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-16 14:13:37 +02:00
2018-02-01 Fred Gleason <fredg@paravelsystems.com>
* Converted rddelete(1) to use RDApplication.
This commit is contained in:
parent
941f846060
commit
b1d43dde69
@ -16623,3 +16623,5 @@
|
||||
* Converted rdcheckcuts(1) to use RDApplication.
|
||||
2018-02-01 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Converted rdclilogedit(1) to use RDApplication.
|
||||
2018-02-01 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Converted rddelete(1) to use RDApplication.
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// 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
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -21,19 +21,17 @@
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <dbversion.h>
|
||||
#include <rdapplication.h>
|
||||
#include <rdcart.h>
|
||||
#include <rdconf.h>
|
||||
#include <rddelete.h>
|
||||
#include <rdcart.h>
|
||||
#include <rdlog.h>
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
//
|
||||
// Initialize Data Structures
|
||||
//
|
||||
bool skip_db_check=false;
|
||||
unsigned schema=0;
|
||||
QString err_msg;
|
||||
|
||||
int obj_start=qApp->argc();
|
||||
del_carts=false;
|
||||
del_logs=false;
|
||||
@ -42,42 +40,59 @@ MainObject::MainObject(QObject *parent)
|
||||
del_dry_run=false;
|
||||
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
|
||||
//
|
||||
del_cmd=new RDCmdSwitch(qApp->argc(),qApp->argv(),"rddelete",RDDELETE_USAGE);
|
||||
if(del_cmd->keys()<1) {
|
||||
if(rda->cmdSwitch()->keys()<1) {
|
||||
fprintf(stderr,"\n");
|
||||
fprintf(stderr,"%s",RDDELETE_USAGE);
|
||||
fprintf(stderr,"\n");
|
||||
delete del_cmd;
|
||||
delete rda->cmdSwitch();
|
||||
exit(256);
|
||||
}
|
||||
for(unsigned i=0;i<del_cmd->keys();i++) {
|
||||
if(del_cmd->key(i)=="--verbose") {
|
||||
for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
|
||||
if(rda->cmdSwitch()->key(i)=="--verbose") {
|
||||
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;
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(del_cmd->key(i)=="--dry-run") {
|
||||
if(rda->cmdSwitch()->key(i)=="--dry-run") {
|
||||
del_dry_run=true;
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(del_cmd->key(i)=="--skip-db-check") {
|
||||
skip_db_check=true;
|
||||
}
|
||||
if(del_cmd->key(i)=="--carts") {
|
||||
if(rda->cmdSwitch()->key(i)=="--carts") {
|
||||
del_carts=true;
|
||||
obj_start=i+2;
|
||||
i=del_cmd->keys();
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
i=rda->cmdSwitch()->keys();
|
||||
break;
|
||||
}
|
||||
if(del_cmd->key(i)=="--logs") {
|
||||
if(rda->cmdSwitch()->key(i)=="--logs") {
|
||||
del_logs=true;
|
||||
obj_start=i+2;
|
||||
i=del_cmd->keys();
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
i=rda->cmdSwitch()->keys();
|
||||
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
|
||||
//
|
||||
del_ripc=new RDRipc(del_station,del_config,this);
|
||||
connect(del_ripc,SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
del_ripc->connectHost("localhost",RIPCD_TCP_PORT,del_config->password());
|
||||
connect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
rda->ripc()->connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
|
||||
|
||||
//
|
||||
// Print Status Messages
|
||||
@ -174,28 +148,25 @@ void MainObject::userData()
|
||||
//
|
||||
// Get User Context
|
||||
//
|
||||
disconnect(del_ripc,SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
if(del_user!=NULL) {
|
||||
delete del_user;
|
||||
}
|
||||
del_user=new RDUser(del_ripc->user());
|
||||
disconnect(rda->ripc(),SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
rda->user()->setName(rda->ripc()->user());
|
||||
|
||||
//
|
||||
// Process Objects
|
||||
//
|
||||
if(del_carts) {
|
||||
if(!del_user->editAudio()) {
|
||||
if(!rda->user()->editAudio()) {
|
||||
fprintf(stderr,"rdimport: user \"%s\" has no edit audio permission\n",
|
||||
(const char *)del_user->name());
|
||||
(const char *)rda->user()->name());
|
||||
exit(256);
|
||||
}
|
||||
DeleteCarts();
|
||||
}
|
||||
|
||||
if(del_logs) {
|
||||
if(!del_user->deleteLog()) {
|
||||
if(!rda->user()->deleteLog()) {
|
||||
fprintf(stderr,"rdimport: user \"%s\" has no delete log permission\n",
|
||||
(const char *)del_user->name());
|
||||
(const char *)rda->user()->name());
|
||||
exit(256);
|
||||
}
|
||||
DeleteLogs();
|
||||
@ -207,7 +178,7 @@ void MainObject::userData()
|
||||
|
||||
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 {
|
||||
if(cart->remove(del_station,del_user,del_config)) {
|
||||
if(cart->remove(rda->station(),rda->user(),rda->config())) {
|
||||
if(del_verbose) {
|
||||
printf("deleted cart %06u [%s]\n",cartnum,(const char *)title);
|
||||
}
|
||||
@ -276,7 +247,7 @@ void MainObject::DeleteLogs()
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(log->remove(del_station,del_user,del_config)) {
|
||||
if(log->remove(rda->station(),rda->user(),rda->config())) {
|
||||
if(del_verbose) {
|
||||
printf("deleted log \"%s\"\n",(const char *)logname);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// 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
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -23,22 +23,15 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qsqldatabase.h>
|
||||
#include <qfileinfo.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 <rdcut.h>
|
||||
#include <rdripc.h>
|
||||
#include <rduser.h>
|
||||
#include <rdsystem.h>
|
||||
#include <rdstation.h>
|
||||
#include <rdgroup.h>
|
||||
#include <rdwavedata.h>
|
||||
#include <rdwavefile.h>
|
||||
|
||||
#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"
|
||||
@ -59,13 +52,6 @@ class MainObject : public QObject
|
||||
bool GetNextObject(unsigned *cartnum);
|
||||
bool GetNextObject(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_logs;
|
||||
bool del_verbose;
|
||||
|
Loading…
x
Reference in New Issue
Block a user