bool GitRunner::isValidDirectory() { const QString initialPath(m_lastRepoRoot->toLocalFile(KUrl::RemoveTrailingSlash)); setDirectory(*m_lastRepoRoot); // A possible git repo has a .git subdicerctory const QString gitDir(".git"); // Also, git rev-parse --is-inside-work-tree returns "true" if we are // inside any subdirectory of the git tree. DvcsJob *job = new DvcsJob(); initJob(*job); *job << "rev-parse"; *job << "--is-inside-work-tree"; startJob(*job); QFileInfo finfo(initialPath); QDir dir; if (finfo.isFile()) { dir = finfo.absoluteDir(); } else { dir = QDir(initialPath); dir.makeAbsolute(); } return (dir.exists(gitDir) && m_result.compare("true")) ? true : false; }
bool NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, Frame* frame, bool defersLoading) { ASSERT(job.get()); // We shouldn't call methods on PassRefPtr so make a new RefPt. RefPtr<ResourceHandle> refJob(job); return startJob(playerId, refJob, refJob->firstRequest(), frame, defersLoading); }
void TTRssFetcher::finishedCategories() { if (!processResponse()) { return; } startJob(StoreCategories); }
void TTRssFetcher::finishedFeeds() { if (!processResponse()) { return; } startJob(StoreFeeds); }
void TTRssFetcher::finishedStream() { if (!processResponse()) { return; } startJob(StoreStream); }
void showProgressWindow() { startJob(); if (isCanceled()) fop_stop(m_fop); waitJob(); }
bool NetworkManager::startJob(int playerId, PassRefPtr<ResourceHandle> job, const ResourceRequest& request, Frame* frame, bool defersLoading) { Page* page = frame->page(); if (!page) return false; BlackBerry::Platform::NetworkStreamFactory* streamFactory = page->chrome()->platformPageClient()->networkStreamFactory(); return startJob(playerId, page->groupName(), job, request, streamFactory, frame, defersLoading ? 1 : 0); }
void showProgressWindow() { startJob(); if (isCanceled()) m_fop->stop(); waitJob(); }
DvcsJob::JobStatus GitRunner::branches() { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "branch"; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::log() { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "log"; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::newBranch(const QString &newBranch) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "branch"; *job << newBranch; startJob(*job); return m_jobStatus; }
void JobQueue::removeJob(Job *job) { m_runningJobs.removeAll(job); while (m_runningJobs.size()<m_maxConcurrentJobs && !m_jobs.isEmpty()) { Job* newJob = m_jobs.first(); m_jobs.removeFirst(); startJob(newJob); } }
int main(void) { pthread_mutex_init(&mutex, NULL); // foo10Secs(NULL); int err = initThreadPool(10); if(err != INIT_SUCCESS) { printf("an even bigger fail; error = %d\n", err); return 1; } /* for(int i = 0; i < 10; i++) { err = startJob(fooCounter, NULL); if(err != START_JOB_SUCCESS) { printf("couldn't start a job, error = %d\n", err); } } sleep(15);*/ for(int i = 0; i < 15; i++) { err = startJob(fooCounter, NULL); if(err != START_JOB_SUCCESS) { printf("couldn't start a job, error = %d\n", err); } } sleep(40); for(int i = 0; i < 6; i++) { err = startJob(fooCounter, NULL); if(err != START_JOB_SUCCESS) { printf("couldn't start a job, error = %d\n", err); } } sleep(100); err = 0; if((err = destroyThreadPool()) != DESTROY_SUCCESS) printf("destroy failed..: %d\n",err ); return 0; }
DvcsJob::JobStatus GitRunner::deleteCommit(const QString &sha1hash) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "reset"; *job << "--hard"; *job << sha1hash; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::init(const KUrl &directory) { // We need to tell the runner to change dir! m_lastRepoRoot->setDirectory(directory.pathOrUrl()); DvcsJob *job = new DvcsJob(); initJob(*job); *job << "init"; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::setEmail(const QString &email) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "config"; *job << "user.email"; *job << email; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::setAuthor(const QString &username) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "config"; *job << "user.name"; *job << username; startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::moveToCommit(const QString &sha1hash, const QString &newBranch) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "checkout"; *job << sha1hash; startJob(*job); if (m_jobStatus != DvcsJob::JobSucceeded) return m_jobStatus; job = new DvcsJob(); initJob(*job); *job << "checkout"; *job << "-b"; *job << newBranch; startJob(*job); return m_jobStatus; }
bool ftp_vfs::populateVfsList(const QUrl &origin, bool showHidden) { QString errorMsg; if (!origin.isValid()) errorMsg = i18n("Malformed URL:\n%1", origin.url()); if (!KProtocolManager::supportsListing(origin)) { if (origin.scheme() == "ftp" && KProtocolManager::supportsReading(origin)) errorMsg = i18n("Krusader does not support FTP access via HTTP.\nIf it is not the case, please check and change the proxy settings in the System Settings."); else errorMsg = i18n("Protocol not supported by Krusader:\n%1", origin.url()); } if (!errorMsg.isEmpty()) { printf("error\n"); if (!quietMode) emit error(errorMsg); return false; } busy = true; vfs_origin = origin.adjusted(QUrl::StripTrailingSlash); //QTimer::singleShot( 0,this,SLOT(startLister()) ); listError = false; // Open the directory marked by origin KIO::Job *job = KIO::listDir(vfs_origin, KIO::HideProgressInfo, showHidden); connect(job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)), this, SLOT(slotAddFiles(KIO::Job*, const KIO::UDSEntryList&))); connect(job, SIGNAL(redirection(KIO::Job*, const QUrl&)), this, SLOT(slotRedirection(KIO::Job*, const QUrl&))); connect(job, SIGNAL(permanentRedirection(KIO::Job*, const QUrl&, const QUrl&)), this, SLOT(slotPermanentRedirection(KIO::Job*, const QUrl&, const QUrl&))); connect(job, SIGNAL(result(KJob*)), this, SLOT(slotListResult(KJob*))); if(!parentWindow.isNull()) { KIO::JobUiDelegate *ui = static_cast<KIO::JobUiDelegate*>(job->uiDelegate()); ui->setWindow(parentWindow); } if (!quietMode) { emit startJob(job); } while (busy && vfs_processEvents()); if (listError) return false; return true; }
bool ResourceHandleManager::startScheduledJobs() { // TODO: Create a separate stack of jobs for each domain. bool started = false; while (!m_resourceHandleList.isEmpty() && m_runningJobs < maxRunningJobs) { ResourceHandle* job = m_resourceHandleList[0]; startJob(job); m_resourceHandleList.remove(0); started = true; } return started; }
/****** Interactive/qrsh/--qrsh_starter *************************************** * * NAME * qrsh_starter -- start a command special correct environment * * SYNOPSIS * qrsh_starter <environment file> <noshell> * int main(int argc, char **argv[]) * * FUNCTION * qrsh_starter is used to start a command, optionally with additional * arguments, in a special environment. * The environment is read from the given <environment file>. * The command to be executed is read from the environment variable * QRSH_COMMAND and executed either standalone, passed to a wrapper * script (environment variable QRSH_WRAPPER) or (default) in a users login * shell (<shell> -c <command>). * On exit of the command, or if an error occurs, an exit code is written * to the file $TMPDIR/qrsh_exit_code. * * qrsh_starter is called from qrsh to start the remote processes in * the correct environment. * * INPUTS * environment file - file with environment information, each line * contains a tuple <name>=<value> * noshell - if this parameter is passed, the command will be * executed standalone * * RESULT * EXIT_SUCCESS, if all actions could be performed, * EXIT_FAILURE, if an error occured * * EXAMPLE * setenv QRSH_COMMAND "echo test" * env > ~/myenvironment * rsh <hostname> qrsh_starter ~/myenvironment * * SEE ALSO * Interactive/qsh/--Interactive * **************************************************************************** */ int main(int argc, char *argv[]) { int exitCode = 0; char *command = NULL; char *wrapper = NULL; int noshell = 0; /* check for correct usage */ if(argc < 2) { fprintf(stderr, "usage: %s <job spooldir> [noshell]\n", argv[0]); exit(EXIT_FAILURE); } /* check for noshell */ if(argc > 2) { if(strcmp(argv[2], "noshell") == 0) { noshell = 1; } } if(!readConfig(argv[1])) { writeExitCode(EXIT_FAILURE, 0); exit(EXIT_FAILURE); } /* setup environment */ command = setEnvironment(argv[1], &wrapper); if(command == NULL) { writeExitCode(EXIT_FAILURE, 0); exit(EXIT_FAILURE); } if(!changeDirectory()) { writeExitCode(EXIT_FAILURE, 0); exit(EXIT_FAILURE); } /* start job */ exitCode = startJob(command, wrapper, noshell); /* JG: TODO: At this time, we could already pass the exitCode to qrsh. * Currently, this is done by shepherd, but only after * qrsh_starter and rshd exited. * If we pass exitCode to qrsh, we also have to implement the * shepherd_about_to_exit mechanism here. */ /* write exit code and exit */ return writeExitCode(EXIT_SUCCESS, exitCode); }
DvcsJob::JobStatus GitRunner::createWorkingCopy(const KUrl &repoOrigin, const KUrl &repoDestination) { // TODO: now supports only cloning a local repo(not very useful, I know =P), // so extend the method to be used over the Internet. m_lastRepoRoot->setDirectory(repoDestination.pathOrUrl()); DvcsJob *job = new DvcsJob(); initJob(*job); *job << "clone"; *job << repoOrigin.pathOrUrl(); startJob(*job); return m_jobStatus; }
/*! * Internally called by \ref ThreadJob when the \ref * ThreadJob::getJobCollection is set. Do not call directly. * * Ownership of \p job is NOT taken, the pointer will not be deleted by this * class. * * A single job cannot be removed from a job collection, jobs can be removed * using \ref resetCollection only. */ void ThreadJobCollection::addJob(ThreadJob* job) { if (getAllJobsAreAdded()) { throw Exception("ThreadJob::addJob() called after setAllJobsAreAdded() was called"); } if (!job) { throw NullPointerException("job"); } job->setJobCollection(this); mJobs.push_back(job); if (mStarted) { startJob(job); } }
DvcsJob::JobStatus GitRunner::mergeBranch(const QString &branchName, const QString &message) { DvcsJob *job = new DvcsJob(); initJob(*job); *job << "merge"; *job << "--no-ff"; *job << "-m"; *job << message; *job << branchName; startJob(*job); return m_jobStatus; }
/*! * Start all jobs that have been added to this collection (see \ref addJob). * If a job gets added after this point, it will get started immediately * (unless \ref resetCompleted has been called in between, which also resets * the started flag). */ void ThreadJobCollection::start() { if (mStarted) { return; } if (getAllJobsCompleted()) { throw Exception("Cannot start collection - all jobs already marked as completed"); } mStarted = true; if (mJobs.empty()) { allJobsCompleted(); } else { for (ListNode<ThreadJob*>* node = mJobs.getFirstNode(); node; node = node->getNext()) { startJob(node->getData()); } } }
DvcsJob::JobStatus GitRunner::commit(const QString &message) { // NOTE: git doesn't allow empty commit ! if (message.isEmpty()) return m_jobStatus = DvcsJob::JobCancelled; DvcsJob *job = new DvcsJob(); initJob(*job); *job << "commit"; *job << "-m"; //Note: the message is quoted somewhere else *job << message; startJob(*job); return m_jobStatus; }
bool ResourceHandleManager::startScheduledJobs() { bool started = false; ResourceHandleList* node = m_resourceHandleListHead; while (node) { ResourceHandleList* next = node->next(); if (!node->removed()) { startJob(node->job()); started = true; } delete node; node = next; } m_resourceHandleListHead = 0; return started; }
DvcsJob::JobStatus GitRunner::remove(const KUrl::List &files) { if (files.empty()) return m_jobStatus = DvcsJob::JobCancelled; DvcsJob *job = new DvcsJob(); initJob(*job); *job << "rm"; QStringList stringFiles = files.toStringList(); while (!stringFiles.isEmpty()) { *job << m_lastRepoRoot->pathOrUrl() + '/' + stringFiles.takeAt(0); } startJob(*job); return m_jobStatus; }
DvcsJob::JobStatus GitRunner::add(const KUrl::List &localLocations) { if (localLocations.empty()) return m_jobStatus = DvcsJob::JobCancelled; DvcsJob *job = new DvcsJob(); initJob(*job); *job << "add"; // Adding files to the runner. QStringList stringFiles = localLocations.toStringList(); while (!stringFiles.isEmpty()) { *job << m_lastRepoRoot->pathOrUrl() + '/' + stringFiles.takeAt(0); } startJob(*job); return m_jobStatus; }
void JobQueue::addJob(Job *newJob) { QList<Job*> const allJobs = m_jobs + m_runningJobs; foreach(Job* job, allJobs) { if (*job == *newJob) { qDebug() << "Ignoring job, still running"; return; } } connect(newJob, SIGNAL(finished(Job*)), this, SLOT(removeJob(Job*))); if (m_runningJobs.size()<m_maxConcurrentJobs) { startJob(newJob); } else { Logger::instance().setStatus(newJob->region().id() + '_' + newJob->transport(), newJob->region().name() + QLatin1String( " (" ) + newJob->transport() + ')', "waiting", "Queued."); m_jobs << newJob; } }