def restart_package(): """ restart a Package :return: "" """ package_id = request.form["package_id"] package = Package.query.filter_by(id=package_id).first() if not package: abort(404) # cancel all currently running processes that belong to this package for file in package.files: if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) else: # clear progress, cancel_process() also does this file.clear() # set status of each file to "queued" file.status = StatusMap.queued.value db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def delete_package(): """ delete a Package :return: "" """ package_id = request.form["package_id"] package = Package.query.filter_by(id=package_id).first() if not package: abort(404) # cancel all currently running processes that belong to this package for file in package.files: if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) # mark this file to be deleted (even though SQLAlchemy handles this already) db.session.delete(file) db.session.delete(package) db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def restart_file(): """ restart a File :return: "" """ file_id = request.form["file_id"] file = File.query.filter_by(id=file_id).first() if not file: abort(404) if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) else: # clear progress, cancel_process() also does this file.clear() # set status of file to "queued" file.status = StatusMap.queued.value db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def restart_package(): """ restart a Package :return: "" """ package_id = request.form["package_id"] package = Package.query.filter_by(id=package_id).first() if not package: abort(404) # cancel all currently running processes that belong to this package for file in package.files: if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) else: # clear progress, cancel_process() also does this file.clear() # set status of each file to "queued" file.status = StatusMap.queued.value db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def delete_package(): """ delete a Package :return: "" """ package_id = request.form["package_id"] package = Package.query.filter_by(id=package_id).first() if not package: abort(404) # cancel all currently running processes that belong to this package for file in package.files: if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) # mark this file to be deleted (even though SQLAlchemy handles this already) db.session.delete(file) db.session.delete(package) db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def restart_file(): """ restart a File :return: "" """ file_id = request.form["file_id"] file = File.query.filter_by(id=file_id).first() if not file: abort(404) if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) else: # clear progress, cancel_process() also does this file.clear() # set status of file to "queued" file.status = StatusMap.queued.value db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def cancel_processes(): """ cancel all currently running Processes and check for new processes :return: "" """ ProcessRepository.cancel_all_processes() # after cancelling check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def add_package(): """ add a new Package :return: "1" """ i = 0 paths = json.loads(request.form["paths"]) for path in paths: paths[i] = html.unescape(path) path = paths[i] if not os.path.isfile(path): print(path + " does not exist..") return "not_existing" i += 1 last_package = Package.query.filter_by(queue=True).order_by(Package.position.desc()).limit(1).first() if not last_package: position = 0 else: position = last_package.position + 1 package = Package(user=current_user, title=request.form["title"], queue=(request.form["queue"] == "1"), position=position) db.session.add(package) file_pos = 0 for path in paths: file = File(filename=path, size=os.path.getsize(path), status=StatusMap.queued.value, position=file_pos) package.files.append(file) file_pos += 1 db.session.commit() # after adding, see if we have to start processes ProcessRepository.check_and_start_processes() return "1"
def delete_file(): """ delete a File :return: "" """ file_id = request.form["file_id"] file = File.query.filter_by(id=file_id).first() if not file: abort(404) # cancel the currently running processes that if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) db.session.delete(file) db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""
def delete_file(): """ delete a File :return: "" """ file_id = request.form["file_id"] file = File.query.filter_by(id=file_id).first() if not file: abort(404) # cancel the currently running processes that if ProcessRepository.is_running(file.id): ProcessRepository.cancel_process(file.id) db.session.delete(file) db.session.commit() # check if it's necessary to start new processes ProcessRepository.check_and_start_processes() return ""