Exemplo n.º 1
0
def checkIfRewrittenAlready( rid, cursor ) :
  cursor.execute( "SELECT rewritten FROM Rule WHERE rid == '" + rid + "'" )
  flag = cursor.fetchone()

  #print "checkIfRewrittenAlready : rid = " + rid
  if flag == None :
    cursor.execute( "SELECT * FROM Rule WHERE rid=='" + rid + "'" )
    info = cursor.fetchall()
    info = toAscii_multiList( info )
    print "info = \n" + str(info)
    tools.bp( __name__, inspect.stack()[0][3], "flag is none" )

  #print "flag = " + str(flag)
  if flag[0] == "False" :
    return False
  else :
    if TOOLS_DEBUG :
      print "RULE PREVIOUSLY REWRITTEN: " + str( dumpers.reconstructRule( rid, cursor ) )
    return True
Exemplo n.º 2
0
def addClockSubgoal_async(rid, firstSubgoalAtts, secondAtt, timeAtt_snd,
                          timeAtt_deliv, cursor):
    baseAtt = firstSubgoalAtts[0]

    if CLOCKTOOLS_DEBUG:
        print "CLOCKTOOLS_DEBUG: For rule : " + str(
            dumpers.reconstructRule(rid, cursor) +
            "\n    firstSubgoalAtts = " + str(firstSubgoalAtts))

    for c in firstSubgoalAtts:
        if not c == baseAtt:
            if isNotSubgoal(cursor, rid, c) or isDMSubgoal(
                    cursor, rid, c) or isNOTRule(cursor, rid):
                pass
            else:
                sys.exit(
                    "Syntax error:\n   Offending rule:\n      " +
                    dumpers.reconstructRule(rid, cursor) +
                    "\n   The first attribute of all positive subgoals in async rules must be identical. Semantically, the first attribute is expected to represent the message sender.\n    First att list for positive subgoals: "
                    + str(firstSubgoalAtts))

    # get first att in first subgoal, assume specifies 'sender' node
    firstAtt = baseAtt

    # get first att of goal, assume specifies 'reciever' node
    # while we're here, collect the first attribute of this goal
    cursor.execute("SELECT attName FROM GoalAtt WHERE GoalAtt.rid == '" + rid +
                   "' AND GoalAtt.attID == '" + str(0) + "'")
    firstGoalAtt = cursor.fetchone()
    firstGoalAtt = tools.toAscii_str(firstGoalAtt)

    # add clock subgoal
    # clock(Node1, Node2, SndTime)
    subgoalName = "clock"
    subgoalAttList = [firstAtt, secondAtt, timeAtt_snd, timeAtt_deliv]
    subgoalTimeArg = ""
    subgoalAddArgs = [""]

    # generate random ID for subgoal
    sid = tools.getID()

    # save name and time arg
    cursor.execute("INSERT INTO Subgoals VALUES ('" + rid + "','" + sid +
                   "','" + subgoalName + "','" + subgoalTimeArg + "')")

    # save subgoal attributes
    cursor.execute(
        '''SELECT MAX(attID) FROM GoalAtt WHERE GoalAtt.rid == "''' + rid +
        '''"''')
    rawMaxID = cursor.fetchone()
    #newAttID = int(rawMaxID[0]) + 1
    newAttID = 0
    for attName in subgoalAttList:
        if CLOCKTOOLS_DEBUG:
            print rid, sid, subgoalName, subgoalTimeArg, str(newAttID), attName
        #cursor.execute("INSERT INTO SubgoalAtt VALUES ('" + rid + "','" + sid + "','" + str(newAttID) + "','" + attName + "','UNDEFINEDTYPE')")
        if newAttID < 2:
            cursor.execute("INSERT INTO SubgoalAtt VALUES ('" + rid + "','" +
                           sid + "','" + str(newAttID) + "','" + attName +
                           "','string')")
        else:
            cursor.execute("INSERT INTO SubgoalAtt VALUES ('" + rid + "','" +
                           sid + "','" + str(newAttID) + "','" + attName +
                           "','int')")
        newAttID += 1

    # save subgoal additional args
    for addArg in subgoalAddArgs:
        cursor.execute("INSERT INTO SubgoalAddArgs VALUES ('" + rid + "','" +
                       sid + "','" + addArg + "')")

    # reset variables for next async rule
    firstSubgoalAtts = []
    firstGoalAtt = ""