def cmd_start(options): import gevent import signal from tranny.manager import ServiceManager gevent.signal(signal.SIGQUIT, gevent.kill) application = ServiceManager() application.start()
def run_application(options): import gevent import signal from tranny.manager import ServiceManager gevent.signal(signal.SIGQUIT, gevent.kill) application = ServiceManager() from tranny.app import event_manager from tranny import metadata for handler in metadata.get_handlers(): event_manager.register_handler(handler) application.start()
def handler(): """ Called when a user used the popup modal to upload a torrent manually :return: Redirect response :rtype: Response """ form = forms.UploadForm() if form.validate_on_submit(): file_data = request.files['torrent_file'].stream.read() file_name = request.files['torrent_file'].filename if file_name.endswith(".torrent"): file_name = file_name[0:len(file_name)-8] try: torrent_struct = torrent.Torrent.from_str(file_data) tor_data = release.TorrentData(torrent_struct.name, file_data, form.section.data) if ServiceManager.add(Session(), tor_data, WebProvider()): flash("Torrent {} uploaded successfully".format(torrent_struct.name), "success") else: flash("Failed to upload torrent", "alert") except exceptions.TrannyException as err: flash(err.message, "alert") elif form.errors: for field, error in form.errors.items(): try: flash("[{}] {}".format(field, ' && '.join(error)), "alert") except: pass try: next_url = request.form['next_url'] except KeyError: next_url = url_for("home.index") return redirect(next_url)
def handler(): """ Called when a user used the popup modal to upload a torrent manually :return: Redirect response :rtype: Response """ form = forms.UploadForm() if form.validate_on_submit(): file_data = request.files['torrent_file'].stream.read() file_name = request.files['torrent_file'].filename if file_name.endswith(".torrent"): file_name = file_name[0:len(file_name) - 8] try: torrent_struct = torrent.Torrent.from_str(file_data) tor_data = release.TorrentData(torrent_struct.name, file_data, form.section.data) if ServiceManager.add(Session(), tor_data, WebProvider()): flash( "Torrent {} uploaded successfully".format( torrent_struct.name), "success") else: flash("Failed to upload torrent", "alert") except exceptions.TrannyException as err: flash(err.message, "alert") elif form.errors: for field, error in form.errors.items(): try: flash("[{}] {}".format(field, ' && '.join(error)), "alert") except: pass try: next_url = request.form['next_url'] except KeyError: next_url = url_for("home.index") return redirect(next_url)