00001
00035 #include "drms.h"
00036 #include "jsoc_main.h"
00037
00038 #define kKeepSums "k"
00039
00040
00041 ModuleArgs_t module_args[] = {
00042 {ARG_FLAG, kKeepSums, NULL, "If set, then the SUMS files belonging to the series will not be removed.", NULL},
00043 {ARG_END}
00044 };
00045
00046 char *module_name = "delete_series";
00047 int DoIt(void) {
00048 int len;
00049 const char *series;
00050 char yesno[20];
00051 char *series_lower;
00052 int keepsums = 0;
00053 int drmsstatus = DRMS_SUCCESS;
00054
00055 if (cmdparams_numargs (&cmdparams) < 2) goto usage;
00056
00057 series = cmdparams_getarg (&cmdparams, 1);
00058 series_lower = strdup(series);
00059
00060 keepsums = cmdparams_isflagset(&cmdparams, kKeepSums);
00061
00062
00063 if (!drms_series_exists(drms_env, series_lower, &drmsstatus))
00064 {
00065 printf("***** The series %s does not exist, and cannot be removed. *****\n Please try again with a valid series name\n", series);
00066 free(series_lower);
00067 return 1;
00068 }
00069
00070 free(series_lower);
00071 series_lower = NULL;
00072
00073
00074 printf("You are about to permanently erase all metadata for the series "
00075 "'%s'.\nAre you sure you want to do this (yes/no)? ",series);
00076 fgets(yesno,10,stdin);
00077 len = strlen(yesno);
00078 if (yesno[len-1]=='\n')
00079 yesno[len-1]=0;
00080 if (!strcmp(yesno,"yes"))
00081 {
00082 memset(yesno,0,10);
00083 printf("I repeat: All data records from '%s' will be erased.\n"
00084 "Are you REALLY sure you want to do this (yes/no)? ",series);
00085 fgets(yesno,10,stdin);
00086 len = strlen(yesno);
00087 if (yesno[len-1]=='\n')
00088 yesno[len-1]=0;
00089 if (!strcmp(yesno,"yes"))
00090 {
00091 printf("Removing existing series '%s'...\n",series);
00092 if (!drms_delete_series(drms_env, series, 1, keepsums))
00093 {
00094 return 0;
00095 }
00096 else
00097 {
00098 printf("'%s': Failed to delete DRMS series.\n",series);
00099 return 1;
00100 }
00101 }
00102 else
00103 {
00104 printf("Series %s is not removed.\n", series);
00105 return 0;
00106 }
00107 }
00108 else
00109 {
00110 printf("Series %s is not removed.\n", series);
00111 return 0;
00112 }
00113
00114 return 0;
00115
00116 usage:
00117 printf("Usage: %s seriesname\n",cmdparams_getarg(&cmdparams, 0));
00118 return 1;
00119 }
00120