Пример #1
0
// called after parsing to ensure all tracks have timestamps
void Scrobble::check_timestamps()
{
    const int size = entries.size();

    if (0 == size)
        return;

    sort_tracks();

    // do we have at least one track without date/time info?
    if (0 == entries.at(0).when)
    {
        // do we have ANY tracks with dt info?
        if (0 == entries.at(size - 1).when)
        {
            // no? then recalc them all
            recalc_dt(get_gmt());
        }
        else
        {
            int i;
            // find where the good date info ends
            for (i = 1; i < size; i++)
            {
                if (0 != entries.at(i).when)
                    break;
            }
            // recalc the bad ones
            recalc_dt(get_gmt(), i);
        }
    }
}
Пример #2
0
Scrobble::Scrobble()
{
    parser = NULL;
    mutex = new QMutex();
    conf = new Conf();
    api_info = new GetTrackInfo();
    cache = new DBCache();
    connect(conf, SIGNAL(add_log(LOG_LEVEL,QString)),
            this, SLOT(add_log(LOG_LEVEL,QString)));
    connect(api_info, SIGNAL(finished(int,bool,int,int)),
            this, SLOT(updated_track_length(int,bool,int,int)));
    connect(api_info, SIGNAL(add_log(LOG_LEVEL,QString)),
            this, SLOT(add_log(LOG_LEVEL,QString)));
    connect(this, SIGNAL(missing_times_get(int,scrob_entry,int)),
            api_info, SLOT(get(int,scrob_entry,int)));
    connect(cache, SIGNAL(add_log(LOG_LEVEL,QString)),
            this, SLOT(add_log(LOG_LEVEL,QString)));
    api_info->start();
    conf->load_config();
    error_str = "";
    scrobble_method = SCROBBLE_NONE;
    log_print_level = LOG_INFO;
    proxy_set = false;
    db_ready = cache->init();

    // belt and braces
    QDateTime a, b;
    a.setTimeSpec(Qt::UTC);
    b.setTimeSpec(Qt::LocalTime);
    a = QDateTime::currentDateTime().toUTC();
    b = QDateTime::currentDateTime().toLocalTime();

    gmt_offset = b.toTime_t() -a.toTime_t();

    /* initialise TZ variables */
    tzset();

    // our own copy - returned via get_dst
    is_dst = daylight;
    int tzindex = (is_dst)?1:0;

    QTextCodec *codec = QTextCodec::codecForLocale();
    zonename = codec->toUnicode(tzname[tzindex]);

    if (is_dst < 0)
        add_log(LOG_ERROR, "is_dst < 0");

    add_log(LOG_DEBUG, "Detected Timezone: " + zonename);
    add_log(LOG_DEBUG, QString("Detected DST: %1").arg(is_dst));
    add_log(LOG_DEBUG, "Detected Offset: " + offset_str());
    add_log(LOG_DEBUG, QString("Detected GMT: %1").arg(get_gmt()));
}
Пример #3
0
bool Scrobble::check_age()
{
    bool too_old = false;
    // Now - 30 days
    time_t max_age = get_gmt() - 2592000;
    for ( int i = 0; i < entries.size(); i++) {
        scrob_entry tmp = entries.at(i);
        if ( tmp.when < max_age )
        {
            add_log(LOG_INFO, "Track too old: " + tmp.artist + " " + tmp.title);
            too_old = true;
        }
    }
    return too_old;
}
int main(int argc, char *argv[])
{
   char diagnosis[DRMAA_ERROR_STRING_BUFFER];
   char *s, jobid[100];
   int drmaa_errno, i;
   int ret = 0;
   struct timeval start_s, finish_s, wait_s;
  
   if (argc<2) {
      usage();
      return 1;
   }

   i = 1;
   do {
      if (!strcmp("-help", argv[i]) ||
          !strcmp("-h", argv[i])) {
         usage();
         return 0;

      } else if (!strcmp("-jobs", argv[i])) {
         i++; 
         if (argc < i+1) {
            usage();
            return 1;
         }
         njobs = atoi(argv[i]);
         i++; 

      } else if (!strcmp("-native", argv[i])) {
         i++; 
         if (argc < i+1) {
            usage();
            return 1;
         }
         native_spec = argv[i];
         i++; 

      } else if (!strcmp("-threads", argv[i])) {
         if (argc < i+1) {
            usage();
            return 1;
         }
         i++; 
         nthreads = atoi(argv[i]);
         i++; 

      } else if (!strcmp("-quiet", argv[i])) {
         i++; 
         if (argc < i+1) {
            usage();
            return 1;
         }
         if (!strcmp("yes", argv[i]) || !strcmp("y", argv[i])) 
            quiet = 1;
         else if (!strcmp("no", argv[i]) || !strcmp("n", argv[i])) 
            quiet = 0;
         else {
            usage();
            return 1;
         }
         i++; 

      } else if (!strcmp("-wait", argv[i])) {
         i++; 
         if (argc < i+1) {
            usage();
            return 1;
         }
         if (!strcmp("yes", argv[i]) || !strcmp("y", argv[i])) 
            dowait = 1;
         else if (!strcmp("no", argv[i]) || !strcmp("n", argv[i])) 
            dowait = 0;
         else {
            usage();
            return 1;
         }
         i++; 

      } else if (!strcmp("-scenario", argv[i])) {
         i++; 
         if (argc < i+1) {
            usage();
            return 1;
         }
         s = strchr(argv[i], '.');
         *s = '\0';
         if (strcmp("queue", argv[i]) && strcmp("type", argv[i]) && 
             strcmp("number", argv[i]) && strcmp("pe", argv[i])) {
            usage();
            return 1;
         }
         scenario = strdup(argv[i]);
        
         s++;
         if (strcmp("hostgroup", s) && strcmp("resource", s) && 
             strcmp("none", s) && strcmp("softresource", s) && 
             strcmp("softhostgroup", s)) {
            usage();
            return 1;
         }
         site_b = strdup(s);
         i++; 

      } else {
         job_path = argv[i];
         i++; 
         if (job_path[0]=='-') {
            usage();
            return 1;
         }

         if (argv[i]) {
            job_args = &argv[i];
         }
      }
   } while (i < argc && !job_path);

   if (!job_path) {
      usage();
      return 1;
   }

#if 0
   printf("job_path: \"%s\"\n", job_path);
   printf("njobs:    %d\n", njobs);
   printf("nthreads: %d\n", nthreads);
   printf("native:   %s\n", native_spec);
   printf("dowait:   %s\n", dowait?"yes":"no");
   printf("quiet:    %s\n", quiet?"yes":"no");
   printf("scenario: %s\n", scenario?scenario:"<no such>");
   printf("site_b:   %s\n", site_b?site_b:"<no such>");
   printf("1st arg:  %s\n", job_args?job_args[0]:"<noargs>");
#endif

   if (drmaa_init(NULL, diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
      fprintf(stderr, "drmaa_init() failed: %s\n", diagnosis);
      return 1;
   }

   get_gmt(&start_s);

   if (!scenario) {
      if (!getuid()) {
         fprintf(stderr, "switching to ah114088:gridware\n");
         setegid(339);
         seteuid(115088);
      }

      if (!(jt = create_job_template(job_path, NULL, 0))) {
         fprintf(stderr, "create_sleeper_job_template() failed\n");
         return 1;
      }

      if (nthreads==1) {
         if (submit_jobs(&argv[i]))
             return 1;
      } else {
         pthread_t *ids = NULL;
         ids = (pthread_t *)malloc(sizeof (pthread_t) * nthreads);

         for (i = 0; i < nthreads; i++) {
            if (pthread_create(&ids[i], NULL, submit_jobs, NULL)) {
               fprintf(stderr, "pthread_create() failed: %s\n", strerror(errno));
	       free(ids);
               return 1;
            }
         }

         for (i = 0; i < nthreads; i++) {
            pthread_join(ids[i], NULL);
         }
      }
   
      drmaa_delete_job_template(jt, NULL, 0);

      if (!getuid()) {
         fprintf(stderr, "switching to root:root\n");
         seteuid(0);
         setegid(0);
      }

   } else {
      if (submit_by_project("project1") || submit_by_project("project2") ||
          submit_by_project("project3") || submit_by_project("project4"))
            return 1;
   }

   get_gmt(&finish_s);
   printf("submission took %8.3f seconds\n", DELTA_SECONDS(start_s, finish_s)); 

   if (dowait) {
      int success = 1;

      for (i=0; i<njobs * nthreads; i++) {
         int stat;
         int aborted, exited, exit_status, signaled;

         drmaa_errno = drmaa_wait(DRMAA_JOB_IDS_SESSION_ANY, jobid, sizeof(jobid)-1, 
            &stat, DRMAA_TIMEOUT_WAIT_FOREVER, NULL, diagnosis, sizeof(diagnosis)-1);

         if (drmaa_errno != DRMAA_ERRNO_SUCCESS) {
            fprintf(stderr, "drmaa_wait() failed: %s\n", diagnosis);
            return 1;
         }

         /*
          * report how job finished 
          */
         drmaa_wifaborted(&aborted, stat, NULL, 0);
         if (aborted) {
            printf("job \"%s\" never ran\n", jobid);
            success = 0;
         } else {
            drmaa_wifexited(&exited, stat, NULL, 0);
            if (exited) {
               drmaa_wexitstatus(&exit_status, stat, NULL, 0);
               if (exit_status != 0) {
                  success = 0;
                  printf("job \"%s\" with exit status %d\n", jobid, exit_status);
               } else {
                  if (!quiet)
                     printf("job \"%s\" finished regularly\n", jobid);
               }
            } else {
               success = 0;
               drmaa_wifsignaled(&signaled, stat, NULL, 0);
               if (signaled) {
                  char termsig[DRMAA_SIGNAL_BUFFER+1];
                  drmaa_wtermsig(termsig, DRMAA_SIGNAL_BUFFER, stat, NULL, 0);
                  printf("job \"%s\" finished due to signal %s\n", jobid, termsig);
               } else
                  printf("job \"%s\" finished with unclear conditions\n", jobid);
            }
         }
      }

      if (!success)
         ret = 1;

      get_gmt(&wait_s);
      printf("wait took %8.3f seconds\n", DELTA_SECONDS(finish_s, wait_s)); 
      printf("jobs took %8.3f seconds\n", DELTA_SECONDS(start_s, wait_s)); 
   }

   if (drmaa_exit(diagnosis, sizeof(diagnosis)-1) != DRMAA_ERRNO_SUCCESS) {
      fprintf(stderr, "drmaa_exit() failed: %s\n", diagnosis);
      return 1;
   }
   
  return ret;
}
Пример #5
0
void Scrobble::recalc_now()
{
    recalc_dt(get_gmt());
}