// Recurses dir for script files void SourceManager::recurseDirs( QDir dir ) { if (!dir.exists()) return; dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot); QFileInfoList files = dir.entryInfoList(); QFileInfo file; for (int x = 0; x < files.size(); x++) { qApp->processEvents(); file = files.at(x); if (file.isDir()) { QDir recurseTo(file.filePath()); recurseDirs(recurseTo); } if (file.isExecutable() && !(file.isDir())) { ScriptInfo *info = WeatherSource::ProbeScript(file); if (info) { m_scripts.append(info); LOG(VB_FILE, LOG_INFO, QString("Found Script '%1'") .arg(file.absoluteFilePath())); } } } return; }
int recurseDirs(const char *path, ThreadManager *threadman) { GValue message = {0,}; g_value_init(&message,G_TYPE_STRING); g_value_set_string(&message,"busy"); g_object_set_property(G_OBJECT(threadman),"status", &message); g_value_unset(&message); if(path==NULL) { return 1; } sleep(1); GFile *dir = g_file_new_for_path(path); GFileEnumerator *fileEnumerator; GError *errorHandler=NULL; fileEnumerator = g_file_enumerate_children(dir,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,&errorHandler); if(errorHandler!=NULL) { fprintf(stderr,"ERROR: %s\n",errorHandler->message); g_error_free(errorHandler); return 1; } if(fileEnumerator!=NULL) { GFileInfo *finfo = g_file_enumerator_next_file(fileEnumerator,NULL,NULL); while(finfo!=NULL) { if(!g_file_info_get_is_hidden(finfo)) { const gchar *name; char *fullPath; name = g_file_info_get_name(finfo); fullPath = strdup(path); fullPath = realloc(fullPath,strlen(path)+3+strlen(name)); strcat(fullPath,"/"); strcat(fullPath,name); if(g_file_info_get_file_type(finfo)==G_FILE_TYPE_DIRECTORY) { int res = recurseDirs(fullPath,threadman); if(res!=0) { fprintf(stderr,"Error with %s\n",fullPath); } } else { const gchar *type = g_file_info_get_attribute_string(finfo,G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); if(strcmp(type,"audio/mpeg")==0) { addToIndex(name,fullPath,type); } } free(fullPath); } finfo = g_file_enumerator_next_file(fileEnumerator,NULL,NULL); } g_object_unref(fileEnumerator); } return 0; }
void *searchFiles(void *arg) { ThreadManager *threadman = (ThreadManager *)arg; int res = recurseDirs(MUSIC_DIR,threadman); if(res==0) { fprintf(stdout,"completed cache\n"); // make the index available // emit a completed signal } else { fprintf(stdout,"caching error\n"); GValue message = {0,}; g_value_init(&message,G_TYPE_STRING); g_value_set_string(&message,"idle"); g_object_set_property(G_OBJECT(threadman),"status", &message); g_value_unset(&message); sleep(10); free(rootMusicLibraryEntry); rootMusicLibraryEntry=NULL; // clear the index and // then sleep for a while // we can try again later // emit idle signal until we resume } fprintf(stdout,"thread exit\n"); //free(rootMusicLibraryEntry); GValue message = {0,}; g_value_init(&message,G_TYPE_STRING); g_value_set_string(&message,"finished"); g_object_set_property(G_OBJECT(tm),"status", &message); g_value_unset(&message); indexReady=1; pthread_exit(0); }
bool SourceManager::findScripts() { QString path = GetShareDir() + "mythweather/scripts/"; QDir dir(path); dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs); if (!dir.exists()) { LOG(VB_GENERAL, LOG_ERR, "MythWeather: Scripts directory not found"); return false; } QString busymessage = tr("Searching for scripts"); MythScreenStack *popupStack = GetMythMainWindow()->GetStack("weather stack"); if (popupStack == nullptr) popupStack = GetMythMainWindow()->GetStack("popup stack"); MythUIBusyDialog *busyPopup = new MythUIBusyDialog(busymessage, popupStack, "mythweatherbusydialog"); if (busyPopup->Create()) { popupStack->AddScreen(busyPopup, false); } else { delete busyPopup; busyPopup = nullptr; } qApp->processEvents(); recurseDirs(dir); // run through and see if any scripts have been deleted MSqlQuery db(MSqlQuery::InitCon()); db.prepare("SELECT sourceid, path FROM weathersourcesettings " "WHERE hostname = :HOST;"); db.bindValue(":HOST", gCoreContext->GetHostName()); if (!db.exec()) MythDB::DBError("SourceManager::findScripts - select", db); QStringList toRemove; while (db.next()) { QFileInfo fi(db.value(1).toString()); if (!fi.isExecutable()) { toRemove << db.value(0).toString(); LOG(VB_GENERAL, LOG_ERR, QString("'%1' no longer exists") .arg(fi.absoluteFilePath())); } } db.prepare("DELETE FROM weathersourcesettings WHERE sourceid = :ID;"); for (int i = 0; i < toRemove.count(); ++i) { db.bindValue(":ID", toRemove[i]); if (!db.exec()) { // MythDB::DBError("Deleting weather source settings", db); } } if (busyPopup) { busyPopup->Close(); busyPopup = nullptr; } return m_scripts.count() > 0; }
void getHistosFromRE(const string& mhid, const string& filepath, const string& sre, vector<std::pair<string,wTH1*> >& v_wth1) { if (gl_verbose) cout<<"Searching for regexp "<<sre<<" in "<<filepath; // allow for multiple regexes in OR combination // vector<string> v_regexes; Tokenize(sre,v_regexes,"|"); if (!v_regexes.size()) v_regexes.push_back(sre); // Build validated TRegexp arguments in preparation for directory recursion // TObjArray *Args = new TObjArray(); for (size_t i=0; i<v_regexes.size(); i++) { TRegexp re(v_regexes[i].c_str(),kTRUE); if (re.Status() != TRegexp::kOK) { cerr << "The regexp " << v_regexes[i] << " is invalid, Status() = "; cerr << re.Status() << endl; exit(-1); } else { Args->AddLast(new TObjString(v_regexes[i].c_str())); } } // Get the root file // TFile *rootfile = openRootFile(filepath); if (!rootfile) { cerr << "File failed to open, " << filepath << endl; Args->Delete(); delete Args; return; } // Do the recursion, collect matches // TObjArray *Matches = new TObjArray(); recurseDirs(rootfile, ®exMatchHisto, Args, Matches); Args->Delete(); delete Args; // Returns two objects per match: // 1. the (string) path that was matched and // 2. the object whose path matched // int nx2matches = Matches->GetEntriesFast(); if (gl_verbose) cout << "... " << nx2matches/2 << " match(es) found."; // Add the matches to the global map of histos // int istart = v_wth1.size(); for (int i=0; i<nx2matches; i+=2) { TString fullspec = ((TObjString *)(*Matches)[i])->GetString(); wTH1 *wth1 = new wTH1((TH1 *)((*Matches)[i+1])); wth1->histo()->UseCurrentStyle(); wth1->histo()->SetLineColor(((i/2)%9)+1); wth1->histo()->SetLineStyle((i/18)+1); wth1->histo()->SetLineWidth(2); wth1->SetLegendEntry(wth1->histo()->GetName()); string hidi= mhid+"_"+int2str(istart+(i/2)); v_wth1.push_back(std::pair<string,wTH1 *>(hidi,wth1)); //glmap_objpath2id.insert(pair<string,string>(fullspec,hidi)); glmap_id2histo.insert(pair<string,wTH1 *>(hidi,wth1)); glmap_id2objpath.insert(pair<string,string>(hidi,string(fullspec.Data()))); } //Matches->Delete(); // need the histos! delete Matches; if (gl_verbose) cout << endl; } // getHistosFromRE