コード例 #1
0
def imp_controls_from_json(json_filepath=CONTROLS_FILE):
    try:
        with open(json_filepath, 'r') as f:
            contrs = json.load(f)

        query = Control.select()
        cursor = db.execute(query)

        control_fnames = [x[0] for x in cursor.fetchall()]

        for uid in contrs:
            if contrs.get("filename") not in control_fnames:
                Control.create(
                    uid=uid,
                    filename=contrs.get(uid).get("filename"),
                    title=contrs.get(uid).get("title"),
                    requirements=contrs.get(uid).get("requirements"),
                    description=contrs.get(uid).get("description"))

    except (ValueError, FileNotFoundError):
        print(
            "[{FAIL}ERR{END}] {CONTROLS_FILE} file error! Test the project (doc tests/README.md)"
            .format(FAIL=C_FAIL, END=C_END, CONTROLS_FILE=CONTROLS_FILE))
        close_program()
    else:
        print("[{OK}OK{END}]  Imported data from {CONTROLS_FILE}".format(
            OK=C_OKGREEN, END=C_END, CONTROLS_FILE=CONTROLS_FILE))
コード例 #2
0
def has_changed(usr):
    e=db.session.query(Control).filter_by(user_id = usr).count()
    if e==0:
        n = Control()
        n.user_id = usr
        n.name = "Predict count"
        n.total = 0
        db.session.add(n)
        try:
            db.session.commit()
            return True
        except Exception as e:
            log.error('Control creation error: %s', e)
            db.session.rollback()
            return False
            exit(1)
    else:
        total = db.session.execute('SELECT total from control WHERE user_id='+str(usr)).fetchone()
        now = db.session.execute('SELECT sum(goal1+goal2) as now from predict WHERE user_id='+str(usr)).fetchone()
        add=now['now']
        if add==None:
            add=0
        if total['total'] !=  add:
            calc_usr_stand(usr)
            db.session.execute('UPDATE control set total='+str(add)+' WHERE user_id='+str(usr))
            db.session.commit()
コード例 #3
0
def add_control(filename, status, time_sec):
    contrs = Control.filter(filename=filename)
    if not contrs:
        contr = Control.create(filename=filename)
        print("[{WARN}WR{END}]  Control info about {SCRIPT} not found!".format(
            WARN=C_WARNING, END=C_END, SCRIPT=filename))
    else:
        contr = contrs[0]

    Scandata.create(control=contr, status=status, lead_time_sec=time_sec)
コード例 #4
0
ファイル: views.py プロジェクト: jpardobl/django-haweb
def control(request, protocol=None, did=None):

    if protocol is not None and did is not None:
        obj = get_object_or_404(Control, protocol=protocol, did=did)
        form = ControlForm(request.GET, obj)
    else:

        obj = Control()

    if request.method == "GET":
        form = ControlForm(instance=obj)
        try:
            screen = get_object_or_404(Screen, slug=request.GET["screen"])
        except KeyError:
            return HttpResponseBadRequest("Falta el screen")
        return render_to_response(
            "edit_control.html",
            {"form": form,
             "screen": screen}
        )
    if request.method == "POST":
        print "estamos en POST"
        form = ControlForm(request.POST, obj)
        if form.is_valid():
            print "erstamos en valid"
            screen = request.POST["screen"]
            print screen
            screen = get_object_or_404(Screen, slug=screen)
            obj = form.save(commit=False)
            try:
                obj.save()
            except IntegrityError:
                return HttpResponseBadRequest("Protocol and did already in use")
            except haclient.RestApiException, err:

                return HttpResponseBadRequest("Error at: %s" % err)
            ScreenControls(screen=screen, control=obj).save()
            return HttpResponse("OK")
        print "no es valida"
        return render_to_response(
            "edit_control.html",
            {"form": form}
        )
コード例 #5
0
ファイル: views.py プロジェクト: jpardobl/django-haweb
def control(request, protocol=None, did=None):

    if protocol is not None and did is not None:
        obj = get_object_or_404(Control, protocol=protocol, did=did)
        form = ControlForm(request.GET, obj)
    else:

        obj = Control()

    if request.method == "GET":
        form = ControlForm(instance=obj)
        try:
            screen = get_object_or_404(Screen, slug=request.GET["screen"])
        except KeyError:
            return HttpResponseBadRequest("Falta el screen")
        return render_to_response("edit_control.html", {
            "form": form,
            "screen": screen
        })
    if request.method == "POST":
        print "estamos en POST"
        form = ControlForm(request.POST, obj)
        if form.is_valid():
            print "erstamos en valid"
            screen = request.POST["screen"]
            print screen
            screen = get_object_or_404(Screen, slug=screen)
            obj = form.save(commit=False)
            try:
                obj.save()
            except IntegrityError:
                return HttpResponseBadRequest(
                    "Protocol and did already in use")
            except haclient.RestApiException, err:

                return HttpResponseBadRequest("Error at: %s" % err)
            ScreenControls(screen=screen, control=obj).save()
            return HttpResponse("OK")
        print "no es valida"
        return render_to_response("edit_control.html", {"form": form})
コード例 #6
0
ファイル: views.py プロジェクト: antonigno/dms
    def save(self):
        '''Save entry in DB'''
        data = self.cleaned_data
        LOGGER.debug(data)
        name = data['name']
        script = data['script']
        match = re.match(r'(?P<start>\d{2}:\d{2}:\d{2}) - (?P<end>\d{2}:\d{2}:\d{2})', data['time_slot'])
        time_slot = TimeSlot.objects.filter(\
start_time=match.group('start'), end_time=match.group('end'))
        control = Control(name=name, script=script, time_slot=time_slot[0])
        control.save()
        if self.dest == 'host':
            for host in data['host']:
                # match = re.match(r'(?P<pe_name>\w+) .*', h)
                # pe_name = match.group('pe_name')
                pes = ProductionEnvironment.objects.filter(name=host)
        elif self.dest == 'area':
            for area in data['host']:
                LOGGER.debug("salvo area %s" % area)
                pes = [area.productionEnvironment \
for area in Area.objects.filter(name=area)]
        for prod_env in pes:
            prod_env.control_set.add(control)
コード例 #7
0
 def get_control_register(self):
     "Returns the current run state of a particular channel"
     return Control(
         self.charger.modbus_read_registers(
             0x8000, "7H", function_code=cst.READ_HOLDING_REGISTERS))