def handle(self, *args, **options): # Eliminate irrelevant settings for opt in BaseCommand.option_list: del options[opt.dest] # Parse the crappy way that runcherrypy takes args, # or the host/port for arg in args: if "=" in arg: (key,val) = arg.split("=") options[key] = val elif ":" in arg: (options["host"], options["port"]) = arg.split(":") elif isnumeric(arg): options["port"] = arg else: raise CommandError("Unexpected argument format: %s" % arg) # In order to avoid doing this twice when the autoreloader # loads this process again, only execute the initialization # code if autoreloader won't be run (daemonize), or if # RUN_MAIN is set (autoreloader has started) if options["daemonize"] or os.environ.get("RUN_MAIN"): self.setup_server_if_needed() # we do this on every server request, # as we don't know what happens when we're not looking. self.reinitialize_server() # Now call the proper command if not options["daemonize"]: call_command("runserver", "%s:%s" % (options["host"], options["port"])) else: call_command("runcherrypyserver", *["%s=%s" % (key,val) for key, val in options.iteritems()])
def wrapper_fn_pfr(request, *args, **kwargs): if request.GET.get("process_id", None): # Get by ID--direct! if not isnumeric(request.GET["process_id"]): return JsonResponseMessageError(_("process_id is not numeric.")); else: process_log = get_object_or_404(UpdateProgressLog, id=request.GET["process_id"]) elif request.GET.get("process_name", None): process_name = request.GET["process_name"] if "start_time" not in request.GET: start_time = datetime.datetime.now() else: start_time = make_naive(dateutil.parser.parse(request.GET["start_time"]), get_current_timezone()) try: # Get the latest one of a particular name--indirect process_log = UpdateProgressLog.get_active_log(process_name=process_name, create_new=False) if not process_log: # Still waiting; get the very latest, at least. logs = UpdateProgressLog.objects \ .filter(process_name=process_name, completed=True, end_time__gt=start_time) \ .order_by("-end_time") if logs: process_log = logs[0] except Exception as e: # The process finished before we started checking, or it's been deleted. # Best to complete silently, but for debugging purposes, will make noise for now. return JsonResponseMessageError(unicode(e)); else: return JsonResponse({"error": _("Must specify process_id or process_name")}) return handler(request, process_log, *args, **kwargs)
def handle(self, *args, **options): # Eliminate irrelevant settings for opt in BaseCommand.option_list: del options[opt.dest] # Parse the crappy way that runcherrypy takes args, # or the host/port for arg in args: if "=" in arg: (key, val) = arg.split("=") options[key] = val elif ":" in arg: (options["host"], options["port"]) = arg.split(":") elif isnumeric(arg): options["port"] = arg else: raise CommandError("Unexpected argument format: %s" % arg) # Now, validate the server. try: if Settings.get("private_key") and Device.objects.count(): # The only success case pass elif not Device.objects.count(): # Nothing we can do to recover raise CommandError( "You are screwed, buddy--you went through setup but you have no devices defined! Call for help!" ) else: # Force hitting recovery code, by raising a generic error # that gets us to the "except" clause raise DatabaseError except DatabaseError: self.stdout.write( "Setting up KA Lite; this may take a few minutes; please wait!\n" ) call_command("setup", interactive=False) # show output to the user #out = call_command_with_output("setup", interactive=False) #if out[1] or out[2]: # # Failed; report and exit # self.stderr.write(out[1]) # raise CommandError("Failed to setup/recover.") # Now call the proper command if options["run_in_proc"]: call_command("runserver", "%s:%s" % (options["host"], options["port"])) else: call_command( "runcherrypyserver", *["%s=%s" % (key, val) for key, val in options.iteritems()])
def browser_submit_answer(self, answer): """ From an exercise page, insert an answer into the text box and submit. """ self.browser.find_element_by_css_selector('#solutionarea input[type=text]').click() self.browser_send_keys(str(answer)) self.browser_send_keys(Keys.RETURN) # Convert points to a number, when appropriate time.sleep(0.25) points = self.browser_get_current_points() return float(points) if isnumeric(points) else points
def get_activity_int(cls, activity_type): """Helper function converts from string or int to the underlying int""" if type(activity_type).__name__ in ["str", "unicode"]: if activity_type in cls.KNOWN_TYPES: return cls.KNOWN_TYPES[activity_type] else: raise Exception("Unrecognized activity type: %s" % activity_type) elif isnumeric(activity_type): return int(activity_type) else: raise Exception("Cannot convert requested activity_type to int")
def handle(self, *args, **options): # Eliminate irrelevant settings for opt in BaseCommand.option_list: del options[opt.dest] # Parse the crappy way that runcherrypy takes args, # or the host/port for arg in args: if "=" in arg: (key,val) = arg.split("=") options[key] = val elif ":" in arg: (options["host"], options["port"]) = arg.split(":") elif isnumeric(arg): options["port"] = arg else: raise CommandError("Unexpected argument format: %s" % arg) # Now, validate the server. try: if Settings.get("private_key") and Device.objects.count(): # The only success case pass elif not Device.objects.count(): # Nothing we can do to recover raise CommandError("You are screwed, buddy--you went through setup but you have no devices defined! Call for help!") else: # Force hitting recovery code, by raising a generic error # that gets us to the "except" clause raise DatabaseError except DatabaseError: self.stdout.write("Setting up KA Lite; this may take a few minutes; please wait!\n") call_command("setup", interactive=False) # show output to the user #out = call_command_with_output("setup", interactive=False) #if out[1] or out[2]: # # Failed; report and exit # self.stderr.write(out[1]) # raise CommandError("Failed to setup/recover.") # Now call the proper command if options["run_in_proc"]: call_command("runserver", "%s:%s" % (options["host"], options["port"])) else: call_command("runcherrypyserver", *["%s=%s" % (key,val) for key, val in options.iteritems()])
def wrapper_fn_pfr(request, *args, **kwargs): if request.GET.get("process_id", None): # Get by ID--direct! if not isnumeric(request.GET["process_id"]): return JsonResponseMessageError( _("process_id is not numeric.")) else: process_log = get_object_or_404(UpdateProgressLog, id=request.GET["process_id"]) elif request.GET.get("process_name", None): process_name = request.GET["process_name"] if "start_time" not in request.GET: start_time = datetime.datetime.now() else: start_time = make_naive( dateutil.parser.parse(request.GET["start_time"]), get_current_timezone()) try: # Get the latest one of a particular name--indirect process_log = UpdateProgressLog.get_active_log( process_name=process_name, create_new=False) if not process_log: # Still waiting; get the very latest, at least. logs = UpdateProgressLog.objects \ .filter(process_name=process_name, completed=True, end_time__gt=start_time) \ .order_by("-end_time") if logs: process_log = logs[0] except Exception as e: # The process finished before we started checking, or it's been deleted. # Best to complete silently, but for debugging purposes, will make noise for now. return JsonResponseMessageError(unicode(e)) else: return JsonResponse( {"error": _("Must specify process_id or process_name")}) return handler(request, process_log, *args, **kwargs)
def handle(self, *args, **options): # Eliminate irrelevant settings for opt in BaseCommand.option_list: del options[opt.dest] # Parse the crappy way that runcherrypy takes args, # or the host/port for arg in args: if "=" in arg: (key, val) = arg.split("=") options[key] = val elif ":" in arg: (options["host"], options["port"]) = arg.split(":") elif isnumeric(arg): options["port"] = arg else: raise CommandError("Unexpected argument format: %s" % arg) # In order to avoid doing this twice when the autoreloader # loads this process again, only execute the initialization # code if autoreloader won't be run (daemonize), or if # RUN_MAIN is set (autoreloader has started) if options["daemonize"] or os.environ.get("RUN_MAIN"): self.setup_server_if_needed() # we do this on every server request, # as we don't know what happens when we're not looking. self.reinitialize_server() # Now call the proper command if not options["daemonize"]: call_command("runserver", "%s:%s" % (options["host"], options["port"])) else: call_command( "runcherrypyserver", *["%s=%s" % (key, val) for key, val in options.iteritems()])