def edit_job(job_id): """ Edit a job's name and/or notes """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound("Job not found") # Edit name if "job_name" in flask.request.form: name = flask.request.form["job_name"].strip() if not name: raise werkzeug.exceptions.BadRequest("name cannot be blank") job._name = name logger.info('Set name to "%s".' % job.name(), job_id=job.id()) # Edit notes if "job_notes" in flask.request.form: notes = flask.request.form["job_notes"].strip() if not notes: notes = None job._notes = notes logger.info("Updated notes.", job_id=job.id()) return "%s updated." % job.job_type()
def clone_job(clone): """ Clones a job with the id <clone>, populating the creation page with data saved in <clone> """ ## <clone> is the job_id to clone job = scheduler.get_job(clone) if job is None: raise werkzeug.exceptions.NotFound('Job not found') if isinstance(job, dataset.ImageClassificationDatasetJob): return flask.redirect( flask.url_for('image_classification_dataset_new') + '?clone=' + clone) if isinstance(job, dataset.GenericImageDatasetJob): return flask.redirect( flask.url_for('generic_image_dataset_new') + '?clone=' + clone) if isinstance(job, model.ImageClassificationModelJob): return flask.redirect( flask.url_for('image_classification_model_new') + '?clone=' + clone) if isinstance(job, model.GenericImageModelJob): return flask.redirect( flask.url_for('generic_image_model_new') + '?clone=' + clone) else: raise werkzeug.exceptions.BadRequest('Invalid job type')
def edit_job(job_id): """ Edit a job's name and/or notes """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') # Edit name if 'job_name' in flask.request.form: name = flask.request.form['job_name'].strip() if not name: raise werkzeug.exceptions.BadRequest('name cannot be blank') job._name = name logger.info('Set name to "%s".' % job.name(), job_id=job.id()) # Edit notes if 'job_notes' in flask.request.form: notes = flask.request.form['job_notes'].strip() if not notes: notes = None job._notes = notes logger.info('Updated notes.', job_id=job.id()) return '%s updated.' % job.job_type()
def delete_job(job_id): job = scheduler.get_job(job_id) if not job: return 'Job not found!', 404 if scheduler.delete_job(job_id): return 'Job deleted.' else: return 'Job could not deleted!', 403
def edit_job(job_id): job = scheduler.get_job(job_id) if job is None: abort(404) old_name = job.name() job._name = request.form['job_name'] return 'Changed job name from "%s" to "%s"' % (old_name, job.name())
def edit_job(job_id): """ Edit the name of a job """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') old_name = job.name() job._name = flask.request.form['job_name'] return 'Changed job name from "%s" to "%s"' % (old_name, job.name())
def job_status(job_id): job = scheduler.get_job(job_id) result = {} if job is None: result['error'] = 'Job not found.' else: result['error'] = None result['status'] = job.status.name result['name'] = job.name() result['type'] = job.job_type() return json.dumps(result)
def delete_job(job_id): job = scheduler.get_job(job_id) if not job: return 'Job not found!', 404 try: if scheduler.delete_job(job_id): return 'Job deleted.' else: return 'Job could not be deleted! Check log for more details', 403 except errors.DeleteError as e: return e.__str__(), 403
def edit_job_notes(job_id): """ Edit the notes of a job """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound("Job not found") old_notes = job.notes() job._notes = flask.request.form["job_notes"] return 'Changed job notes from "%s" to "%s"' % (old_notes, job.notes())
def show_job(job_id): job = scheduler.get_job(job_id) if job is None: abort(404) if isinstance(job, dataset.DatasetJob): return redirect(url_for('datasets_show', job_id=job_id)) if isinstance(job, model.ModelJob): return redirect(url_for('models_show', job_id=job_id)) else: abort(404)
def abort_job(job_id): """ Aborts a running job """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') if scheduler.abort_job(job_id): return 'Job aborted.' else: raise werkzeug.exceptions.Forbidden('Job not aborted')
def job_status(job_id): """ Returns a JSON objecting representing the status of a job """ job = scheduler.get_job(job_id) result = {} if job is None: result['error'] = 'Job not found.' else: result['error'] = None result['status'] = job.status.name result['name'] = job.name() result['type'] = job.job_type() return json.dumps(result)
def show_job(job_id): """ Redirects to the appropriate /datasets/ or /models/ page """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') if isinstance(job, dataset.DatasetJob): return flask.redirect(flask.url_for('datasets_show', job_id=job_id)) if isinstance(job, model.ModelJob): return flask.redirect(flask.url_for('models_show', job_id=job_id)) else: raise werkzeug.exceptions.BadRequest('Invalid job type')
def job_status(job_id): """ Returns a JSON objecting representing the status of a job """ job = scheduler.get_job(job_id) result = {} if job is None: result["error"] = "Job not found." else: result["error"] = None result["status"] = job.status.name result["name"] = job.name() result["type"] = job.job_type() return json.dumps(result)
def delete_job(job_id): """ Deletes a job """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') try: if scheduler.delete_job(job_id): return 'Job deleted.' else: raise werkzeug.exceptions.Forbidden('Job not deleted') except errors.DeleteError as e: raise werkzeug.exceptions.Forbidden(str(e))
def show_job(job_id): """ Redirects to the appropriate /datasets/ or /models/ page """ job = scheduler.get_job(job_id) if job is None: abort(404) if isinstance(job, dataset.DatasetJob): return redirect(url_for('datasets_show', job_id=job_id)) if isinstance(job, model.ModelJob): return redirect(url_for('models_show', job_id=job_id)) else: abort(404)
def delete_job(job_id): """ Deletes a job """ job = scheduler.get_job(job_id) if job is None: raise werkzeug.exceptions.NotFound('Job not found') if not utils.auth.has_permission(job, 'delete'): raise werkzeug.exceptions.Forbidden() try: if scheduler.delete_job(job_id): return 'Job deleted.' else: raise werkzeug.exceptions.Forbidden('Job not deleted') except utils.errors.DeleteError as e: raise werkzeug.exceptions.Forbidden(str(e))
def clone_job(clone): """ Clones a job with the id <clone>, populating the creation page with data saved in <clone> """ ## <clone> is the job_id to clone job = scheduler.get_job(clone) if job is None: raise werkzeug.exceptions.NotFound('Job not found') if isinstance(job, dataset.ImageClassificationDatasetJob): return flask.redirect(flask.url_for('image_classification_dataset_new') + '?clone=' + clone) if isinstance(job, dataset.GenericImageDatasetJob): return flask.redirect(flask.url_for('generic_image_dataset_new') + '?clone=' + clone) if isinstance(job, model.ImageClassificationModelJob): return flask.redirect(flask.url_for('image_classification_model_new') + '?clone=' + clone) if isinstance(job, model.GenericImageModelJob): return flask.redirect(flask.url_for('generic_image_model_new') + '?clone=' + clone) else: raise werkzeug.exceptions.BadRequest('Invalid job type')