Beispiel #1
0
    def addAttachedCoordinator(self, coord):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        if coord not in self.attachedCoords:
            self.attachedCoords.append(coord)
Beispiel #2
0
 def recursiveRename(self, newName):
     if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
         print utils.whoami()
         print utils.whataremyargs()
     
     self.__envAgent.agentName = newName + '_env'
     self.__envAgent.recursiveRename(newName)
Beispiel #3
0
    def addAttachedCoordinatorName(self, coordName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.attachedCoordNames.append(coordName)
        print "ATTACHED %s"%self.attachedCoordNames
Beispiel #4
0
    def recursiveRename(self, suffix):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()
            
        for fa in self.__fileAgentList:
            #fa.agentName += suffix
            nn = self.getNeedName(fa)
            fa.recursiveRename(suffix)

        for fa in self.__folderAgentList:
            nn = self.getNeedName(fa)
            fa.recursiveRename(suffix)

        for pa in self.__processAgentList:
            nn = self.getNeedName(pa)
            #pa.agentName += suffix
            pa.recursiveRename(suffix)
        for co in self.__coordinatorList:
            #if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            #    print "I change name of ", co.agentName
            nn = self.getNeedName(co)
            co.__selfRename(suffix)
            co.recursiveRename("_" + nn + suffix)
            
        #experimental and probably not the good solution : 
        # rename also the destination of the triggers
        for fa in self.__fileAgentList:
            fa.renameTriggers(suffix)

        for fa in self.__folderAgentList:
            fa.renameTriggers(suffix)

        for pa in self.__processAgentList:
            pa.renameTriggers(suffix)
Beispiel #5
0
    def assignNeeds(self, needName, needValue):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()
        
        # if there was already a need, writing on top of the needsAssignmentDic is not enough
        # we need to remove also the object in the process/file/folder/coord list
        print "needsAssignmentDic : %s"%self
        if ( needName in self.__needsAssignmentDic ):
            listFromWhichToDel = None
            agentToDel = self.__needsAssignmentDic[needName]
            print "STEP 1 agent to del : --%s--"%agentToDel
            if self.__needsDic[needName] == "Coordinator":
                listFromWhichToDel = self.__coordinatorList
            elif (self.__needsDic[needName] == "ProcessAgent"):
                listFromWhichToDel = self.__processAgentList
            elif self.__needsDic[needName] == "FileAgent":
                listFromWhichToDel = self.__fileAgentList
            elif self.__needsDic[needName] == "FolderAgent":
                listFromWhichToDel = self.__folderAgentList
            
            listFromWhichToDel.remove(agentToDel)

    
        self.__needsAssignmentDic[needName] = needValue
        if self.__needsDic[needName] == "Coordinator":
            self.__coordinatorList.append(needValue)
            if needValue.totalSet == False:
                needValue.total = self.__needsTotal[needName]    
        elif (self.__needsDic[needName] == "ProcessAgent"):
            self.__processAgentList.append(needValue)
        elif self.__needsDic[needName] == "FileAgent":
            self.__fileAgentList.append(needValue)
        elif self.__needsDic[needName] == "FolderAgent":
            self.__folderAgentList.append(needValue)
Beispiel #6
0
    def setMotherAgent(self, mother, realName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()
        
        self.agentName = realName
        self.__realName = realName
        self.totalSet = True
        #if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
        #    print self.agentName, " inherits from ", mother.agentName
        self.__motherAgent = mother
        mother.__childrenAgents[self.agentName] = self


        #OLD SYSTEM, DOES NOT WORK BUT KEEP FOR RECORD
        #copy of the mother attributes
        #self.__variables = copy.deepcopy(mother.__variables)
        #self.__needsDic = copy.deepcopy(mother.__needsDic)
        
        #self.__needsAssignmentDic = copy.deepcopy(mother.__needsAssignmentDic )
        #self.__fileAgentList = copy.deepcopy(mother.__fileAgentList)
        #self.__processAgentList = copy.deepcopy(mother.__processAgentList)
        #self.__coordinatorList = copy.deepcopy(mother.__coordinatorList)

        #NEW METHOD, NOT SURE IF THIS WILL REALLY WORK...
        #realName = self.agentName
        #self = copy.deepcopy(mother)
        #self.agentName = realName


        self.recursiveRename('_' + self.agentName)
Beispiel #7
0
    def isFullyDefined(self):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            
        if self.__isFullyDefined is None :
            if len(self.__needsDic) == len(self.__needsAssignmentDic):
                self.__isFullyDefined = True
                #Now we have to check if all the tree is defined
                for needAssign in self.__needsAssignmentDic.values():
                    needDefined = needAssign.isFullyDefined()
                    print"I check for %s if fully defined because son %s " % (self.agentName, needAssign.agentName)
                    if not needDefined :
                        print  "%s Not fully defined because son %s not defined" % (self.agentName, needAssign.agentName)
                        self.__isFullyDefined = False
                        break  
            else:
                print "%s Not fully defined because len(self.__needsDic) != len(self.__needsAssignmentDic)" % (self.agentName)
                print self.__needsDic.keys()
                print self.__needsAssignmentDic.keys()
                self.__isFullyDefined = False             
        
            #if we are not fully defined, our children (not inherited classes, but children in teh tree) cannot be defined
            if not self.__isFullyDefined:
                for needAssign in self.__needsAssignmentDic.values():
                    print "I set isFullyDefined to False to %s" % needAssign.agentName
                    needAssign.setIsFullyDefined(False)

        return self.__isFullyDefined
Beispiel #8
0
def parseAction_setEnvDef(token):
    if runtime.DEBUG_MODE & runtime.OBJ_TRIGGER:
        print utils.whoami(), token

    serverName = token[1]
    server = runtime.core.getServer(serverName)
    server.addAttribute(token[2], token[3])
Beispiel #9
0
def parseAction_coordinator_start(token):
    if runtime.DEBUG_MODE & runtime.OBJ_TRIGGER:
        print utils.whoami(), token
    #probably useless test... otherwise the token would not be matched and we would not be here
    if len(token) >= 2: # only "processAgent" and the name of the agent
        ag = Coordinator(token[1])
    
    #if no inheritance
    if len(token) == 2:
        ag.total = runtime.core.getNextTotal()


    if len(token) == 3:
        # If just making a deepcopy, we copy everything, including the __childrenAgents attribute,
        # which is huge and useless (and wrong I think...). The memory grows exponentially,
        # and the parsing is stuck. So we save the __childrenAgents attribute of the mother,
        # empty it, copy the mother, and put it back to her
        motherChildren = runtime.core.getCoordinator(token[2]).getChildrenAgents()
        runtime.core.getCoordinator(token[2]).setChildrenAgents({})
        ag = copy.deepcopy(runtime.core.getCoordinator(token[2]))
        runtime.core.getCoordinator(token[2]).setChildrenAgents(motherChildren)
        
        ag.setMotherAgent(runtime.core.getCoordinator(token[2]), token[1])
        
    runtime.core.addCoordinator(ag)
Beispiel #10
0
    def isFullyDefined(self):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD :
            print utils.whoami()

        if self.isFullyDefinedVal is None:
            self.isFullyDefinedVal = True
            if self.agentName is None:
                print "%s is not defined because agentName is not set" % self.agentName
                self.isFullyDefinedVal = False
            if self.filename is None:
                print "%s is not defined because filename is not set" % self.agentName
                self.isFullyDefinedVal = False
            if self.server is None:
                print "%s is not defined because server is not set" % self.agentName
                self.isFullyDefinedVal = False
                
            if len(self.variables): #if there are variables not assigned
                print "%s is not defined because of variables unassigned %s " % (self.agentName, self.variables)
                self.isFullyDefinedVal = False

            for t in self.triggers :
                if not t.isFullyDefined():
                    self.isFullyDefinedVal = False

        return self.isFullyDefinedVal
Beispiel #11
0
    def setMotherAgent(self, mother, realName):

#        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
#            print utils.whoami()
#            print utils.whataremyargs()
#
#        self.agentName = realName
#        self.__realName = realName
#        #if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
#        #    print self.agentName, " inherits from ", mother.agentName
#        self.__motherAgent = mother
#        mother.__childrenAgents[self.agentName] = self
#
#
#        self.recursiveRename('_' + self.agentName)
#        self.__envAgent.server = self.agentName
#        self.__envAgent.getFstab().server = self.agentName
#

        #More recent system, but with a flaw
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()
        
        self.agentName = realName
        #if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
        #    print self.agentName, " inherits from ", mother.agentName
        self.__motherAgent = mother
        mother.__childrenAgents[self.agentName] = self
        self.recursiveRename(self.agentName)
        self.__envAgent.server = self.agentName
        self.__envAgent.getFstab().server = self.agentName
Beispiel #12
0
def parse_action_process_trigger(token):
    if runtime.DEBUG_MODE & runtime.OBJ_TRIGGER:
        print utils.whoami(), token
    # runtime.core.currentFileAgent.addTrigger((token[0], token[1], token[3], runtime.core.getEntity(token[5])))

    # Replace list by object
    # runtime.core.currentFileAgent.addTrigger([token[0], token[1], token[3], token[5]])
    runtime.core.currentProcessAgent.addTrigger(utils.Trigger(token[0], token[1], token[3], token[5]))
Beispiel #13
0
def parse_action_file_content(token):
    if runtime.DEBUG_MODE & runtime.OBJ_TRIGGER:
        print utils.whoami(), token

    # I don't use runtime.core.currentFileAgent because
    # this function might be called by a folderAgent
    #runtime.core.currentFileAgent.addContent(token[1])
    runtime.core.currentMetaAgent.addContent(token[1])
Beispiel #14
0
    def __selfRename(self, suffix):
#        print "I rename myself (%s, %s) + %s -> %s" % (self.__realName, self.__suffix, suffix, self.__realName + suffix)
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.__suffix = suffix
        self.agentName = self.__realName + suffix
Beispiel #15
0
    def __init__(self, agentName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        fileAgentParser.FileAgent.__init__(self,agentName)
        self.maxDepth = 0
        self.filenameFilters = []
Beispiel #16
0
    def setMotherAgent(self, mother):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD :
            print utils.whoami()
            print utils.whataremyargs()

        self.contents = copy.deepcopy(mother.contents)
        #self.envVarFile.agentName = 'babla'
        MetaAgent.setMotherAgent(self, mother)
Beispiel #17
0
def parseAction_file_start(token):
    if runtime.DEBUG_MODE & runtime.OBJ_TRIGGER:
        print utils.whoami(), token
    if len(token) >= 2: # only "processAgent" and the name of the agent
        ag = FileAgent(token[1])
        runtime.core.addFileAgent(ag)

    if len(token) == 3:
        ag.setMotherAgent(runtime.core.getFileAgent(token[2]))
Beispiel #18
0
    def recursiveRename(self, suffix):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        MetaAgent.recursiveRename(self, suffix)
        if self.__childProcessAgent:
            self.__childProcessAgent.recursiveRename("_c_" + suffix)
        self.envVarFile.recursiveRename(suffix)
Beispiel #19
0
    def removeAttachedCoordinatorName(self, coordName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        try:
            self.attachedCoordNames.remove(coordName)
        except:
            raise 'No Coordinator "%s" attached to server %s'%(coordName, self.agentName)
Beispiel #20
0
    def setMotherAgent(self, mother):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.envVarFile = copy.deepcopy(mother.envVarFile)
        # self.envVarFile.agentName = 'babla'
        self.envVarFile.recursiveRename(self.agentName)
        MetaAgent.setMotherAgent(self, mother)
Beispiel #21
0
    def assignVariable(self, varName, value):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        MetaAgent.assignVariable(self, varName, value)
        if self.__childProcessAgent:
            self.__childProcessAgent.assignVariable(varName, value)
        self.envVarFile.assignVariable(varName, value)
Beispiel #22
0
    def getNonAssignedNeeds(self):
        if runtime.DEBUG_MODE & runtime.OBJ_VERBOSE:
            print utils.whoami()

        needList = self.__needsDic.keys()
        needL=set(needList)
        needAssigned = self.__needsAssignmentDic.keys()
        needA = set(needAssigned)
        print "Non assign needs for %s : %s "%(self.agentName, needL - needA )
        return needL - needA
Beispiel #23
0
 def addNeeds(self, name, typeOfNeed, occurrence, total=None):
     if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
         print utils.whoami()
         print utils.whataremyargs()
         
     self.__needsDic[name] = typeOfNeed
     self.__needsOccurrence[name] = occurrence       
     if total:
         #total should be != None only if we have a coordinator
         self.__needsTotal[name] = total
Beispiel #24
0
    def setClassification(self, classification):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.classification = classification
        cId = 0
        for c in self.__coordinatorList:
            c.setClassification("%s-%s"%(classification,cId))
            cId += 1
Beispiel #25
0
    def __init__(self, agentName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.agentName = agentName
        
        self.__isFullyDefined = None
        self.__childrenAgents = {}
        self.attachedCoords = []
        self.attachedCoordNames = []
Beispiel #26
0
    def addAttribute(self, attribute, value):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        if attribute in self.allowedAttributes:
            setattr(self, attribute, value)
        else:
            self.__envAgent.addAttribute(attribute, value)
        for child in self.__childrenAgents.values():
            child.addAttribute(attribute, value)
Beispiel #27
0
    def __init__(self, agentName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

	self.maxLoad = 2
	self.maxMemory = 100
	self.maxSwap = 99
        self.ignoredFS = Set([])

        self.agentName = agentName
Beispiel #28
0
    def isFullyDefined(self):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD :
            print utils.whoami()

        if self.__isFullyDefined is None:
            self.__isFullyDefined = True
            if self.agentName is None:
                self.__isFullyDefined = False
            if self.server is None:
                self.__isFullyDefined = False

        return self.__isFullyDefined
Beispiel #29
0
    def __init__(self, agentName):
        MetaAgent.__init__(self, agentName)
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        self.__limits = {}
        self.command = ""
        self.service = ""
        self.maxCpu = 100
        self.maxMemory = 100
        self.multiplicity = -1
Beispiel #30
0
    def __init__(self, agentName):
        if runtime.DEBUG_MODE & runtime.OBJ_METHOD:
            print utils.whoami()
            print utils.whataremyargs()

        MetaAgent.__init__(self,agentName)
        self.contents = []
        
        self.owner = ''
        self.grp = ''
        self.attributes = ''
        self.permissions = ''
        self.md5 = ''
Beispiel #31
0
def prod_maintainer(notes, upload):
    cnf = Config()
    changes = upload.changes
    whitelists = [upload.target_suite.mail_whitelist]

    # Here we prepare an editor and get them ready to prod...
    (fd, temp_filename) = utils.temp_filename()
    temp_file = os.fdopen(fd, 'w')
    temp_file.write("\n\n=====\n\n".join([note.comment for note in notes]))
    temp_file.close()
    editor = os.environ.get("EDITOR", "vi")
    answer = 'E'
    while answer == 'E':
        os.system("%s %s" % (editor, temp_filename))
        temp_fh = utils.open_file(temp_filename)
        prod_message = "".join(temp_fh.readlines())
        temp_fh.close()
        print "Prod message:"
        print utils.prefix_multi_line_string(prod_message,
                                             "  ",
                                             include_blank_lines=1)
        prompt = "[P]rod, Edit, Abandon, Quit ?"
        answer = "XXX"
        while prompt.find(answer) == -1:
            answer = utils.our_raw_input(prompt)
            m = re_default_answer.search(prompt)
            if answer == "":
                answer = m.group(1)
            answer = answer[:1].upper()
    os.unlink(temp_filename)
    if answer == 'A':
        return
    elif answer == 'Q':
        return 0
    # Otherwise, do the proding...
    user_email_address = utils.whoami() + " <%s>" % (
        cnf["Dinstall::MyAdminAddress"])

    changed_by = changes.changedby or changes.maintainer
    maintainer = changes.maintainer
    maintainer_to = utils.mail_addresses_for_upload(maintainer, changed_by,
                                                    changes.fingerprint)

    Subst = {
        '__SOURCE__': upload.changes.source,
        '__CHANGES_FILENAME__': upload.changes.changesname,
        '__MAINTAINER_TO__': ", ".join(maintainer_to),
    }

    Subst["__FROM_ADDRESS__"] = user_email_address
    Subst["__PROD_MESSAGE__"] = prod_message
    Subst["__CC__"] = "Cc: " + cnf["Dinstall::MyEmailAddress"]

    prod_mail_message = utils.TemplateSubst(
        Subst, cnf["Dir::Templates"] + "/process-new.prod")

    # Send the prod mail
    utils.send_mail(prod_mail_message, whitelists=whitelists)

    print "Sent prodding message"
Beispiel #32
0
def edit_note(note, upload, session, trainee=False):
    # Write the current data to a temporary file
    (fd, temp_filename) = utils.temp_filename()
    editor = os.environ.get("EDITOR", "vi")
    answer = 'E'
    while answer == 'E':
        os.system("%s %s" % (editor, temp_filename))
        temp_file = utils.open_file(temp_filename)
        newnote = temp_file.read().rstrip()
        temp_file.close()
        print "New Note:"
        print utils.prefix_multi_line_string(newnote, "  ")
        prompt = "[D]one, Edit, Abandon, Quit ?"
        answer = "XXX"
        while prompt.find(answer) == -1:
            answer = utils.our_raw_input(prompt)
            m = re_default_answer.search(prompt)
            if answer == "":
                answer = m.group(1)
            answer = answer[:1].upper()
    os.unlink(temp_filename)
    if answer == 'A':
        return
    elif answer == 'Q':
        return 0

    comment = NewComment()
    comment.policy_queue = upload.policy_queue
    comment.package = upload.changes.source
    comment.version = upload.changes.version
    comment.comment = newnote
    comment.author = utils.whoami()
    comment.trainee = trainee
    session.add(comment)
    session.commit()
Beispiel #33
0
    def dashboard(self):
        whoami = utils.whoami()
        tasks = model.Task.queryAssigned(whoami)
        revs = model.Revision.querySubscribed(whoami)
        projects = model.Project.queryUserProjects(whoami)

        rd = {}
        for r in revs:
            if r.status in rd:
                rd[r.status].append(r)
            else:
                rd[r.status] = [r]

        template = self.templateEnv.get_template("dashboard.md")

        output = template.render(utils=utils,
                                 assigned=tasks,
                                 responsible=rd,
                                 projects=projects)
        print(output)
        return 0
Beispiel #34
0
    def test_homework(self):
        try:
            driver = self.driver
            driver.get(utils.URL)
            homepage = HomePage(driver)

            homepage.navigate_our_jobs()
            time.sleep(2)
            homepage.navigate_our_customers()
            time.sleep(2)
            homepage.scroll_up()
            time.sleep(2)
            homepage.click_whatsapp()
            time.sleep(2)
            homepage.talk_to_us_test()

            # driver = self.driver
            # driver.get(utils.URL)
            #
            # login = LoginPage(driver)
            # homepage = HomePage(driver)
            # eventspage = EventsPage(driver)
            #
            # login.enter_username(utils.USERNAME)
            # login.enter_instance(utils.INSTANCE)
            # login.enter_password(utils.PASSWORD)
            # login.click_login()
            # homepage.navigate_events_screen()
            # eventspage.search_value("NewUser")
            # time.sleep(5)
            # eventspage.value_exists("NewUser")
            # time.sleep(5)
            # eventspage.search_value("Purchase")
            # time.sleep(5)
            # eventspage.value_exists("Purchase")
            # time.sleep(5)

        except AssertionError as error:
            print("Assertion error occurred")
            print(error)
            currTime = moment.now().strftime("%d-%m-%Y_%H-%M-%S")
            testName = utils.whoami()
            screenshotName = testName + "_" + currTime
            allure.attach(self.driver.get_screenshot_as_png(),
                          name=screenshotName,
                          attachment_type=allure.attachment_type.PNG)

            driver.get_screenshot_as_file(
                "C:/Users/Dror/Desktop/Automation/PythonAutomationFramework_1-master/screenshots/"
                + screenshotName + ".png")
            raise

        except:
            print("There was an exception")

            currTime = moment.now().strftime("%d-%m-%Y_%H-%M-%S")
            testName = utils.whoami()
            screenshotName = testName + "_" + currTime
            allure.attach(self.driver.get_screenshot_as_png(),
                          name=screenshotName,
                          attachment_type=allure.attachment_type.PNG)
            driver.get_screenshot_as_file(
                "C:/Users/Dror/Desktop/Automation/PythonAutomationFramework_1-master/screenshots/"
                + screenshotName + ".png")
            raise
Beispiel #35
0
 def projects(self):
     phid = utils.whoami()
     projs = model.Project.queryUserProjects(phid)
     for p in projs:
         print("{} - {}".format(p.name, p.phid))