当前位置: 首页>>代码示例>>Python>>正文


Python Interface.run方法代码示例

本文整理汇总了Python中interface.Interface.run方法的典型用法代码示例。如果您正苦于以下问题:Python Interface.run方法的具体用法?Python Interface.run怎么用?Python Interface.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在interface.Interface的用法示例。


在下文中一共展示了Interface.run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from interface import Interface [as 别名]
# 或者: from interface.Interface import run [as 别名]
def main(args):
    if len(args) == 3:
        if args[1].startswith("--user=") and args[2].startswith("--pw="):
            username = args[1].split("=")[1]
            password = args[2].split("=")[1]
            backend = Databaser(u=username, pw=password)
        elif args[1].startswith("--pw=") and args[2].startswith("--user="):
            username = args[2].split("=")[1]
            password = args[1].split("=")[1]
            backend = Databaser(u=username, pw=password)
        else:
            err = "The arguments you passed are not valid!"
            raise TypeError, err
    elif len(args) == 2 or len(args) > 3:
        err = "You passed timeclash.py %s argument(s), but it requires 0 or 2."
        raise TypeError, err % (len(args) - 1)
    else:
        backend = Databaser()
    methods = backend.render_functions()
    frontend = Interface(methods)
    frontend.run()
开发者ID:aaronjgreenberg,项目名称:timeclash,代码行数:23,代码来源:timeclash.py

示例2: Collector

# 需要导入模块: from interface import Interface [as 别名]
# 或者: from interface.Interface import run [as 别名]
class Collector(DatagramServer):
    x = 0
    def __init__(self,args):

        # create logger
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        
        # create console handler and set level to debug
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        
        # create formatter
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        
        # add formatter to ch
        ch.setFormatter(formatter)
        
        # add ch to logger
        self.logger.addHandler(ch)        
        self.logger.debug( "Starting Collector process in %s"%os.getcwd())
        #self.logger.debug( "Gevent Version %s"%gevent.__version__)
        
        #TODO: move output file name to config
        fname = "./NetFlow.%d.bin"%int(time.time())
        
        #WARN: might want to remove this after testing
        self.out = open(fname,"wb")
        
        #create tool instances
        self.interface = Interface()
        self.parse = Parse()
        self.context = Context()
        self.describe = Describe()
        self.standardize = Standardize()
        self.transform = Transform()
        self.partition = Partition()
        
        self.q = Queue()
        
        self.inWindow = settings.SETTINGS.get("collector","inWindow")
        
        self.score = Score()
        #TODO: move csv name to config
        #self.csv = CSV("output.csv")
        
        self.output = Output()
        
        return super(Collector,self).__init__(args)
    
    def done(self):
        #pass
        self.out.close()
        #really important to call del on the csv obj to ensure it closes correctly
        #del self.csv
    
    def handle(self, rawData, address):
        Collector.x += 1
        #print '%s %s: got %r' % (Collector.x, address[0], rawData)  
        self.out.write(rawData)
        
        interfacedData = self.interface.run(rawData)
        #self.logger.debug("Interface: %s"%(repr(interfacedData)))
        #once the rawData is "interfaced" we are passing it around by reference
        # interfaced data must be iterable
        try:
            for record in interfacedData:
                self.parse.run(record)
                #self.logger.debug("Parse: %s"%(repr(record)))
                self.context.run(record)
                #self.logger.debug("Context: %s"%(repr(record)))
                self.describe.run(record)
                #self.logger.debug("Describe: %s"%(repr(record)))
                #push the record onto the queue until window 
                if not (self.inWindow):
                    self.q.put(record)
                    #self.logger.debug("adding record to queue %s"%(repr(record)))
                    if (self.q.qsize() == int(settings.SETTINGS.get("collector","describeWindow"))):
                        #self.logger.debug("Describe Window of %s records met, Begin Processing queue"%settings.SETTINGS.get("collector","describeWindow"))
                        self.inWindow = True
                        
                        while not self.q.empty():
                            item = self.q.get()
                            #self.logger.debug("processing record from queue %s"%(repr(item)))
                            self.standardize.run(item)
                            self.transform.run(item)
                            self.partition.run(item)
                            #self.csv.writeRow(self.csv.format(item))
                            self.output.run(item)
                            self.q.task_done()
                else:
                    self.standardize.run(record)
                    #self.logger.debug("Standardize: %s"%(repr(record)))
                    self.transform.run(record)
                    #self.logger.debug("Transform: %s"%(repr(record)))
                    self.partition.run(record)
                    #self.logger.debug("Partition: %s"%(repr(record)))
                    #self.csv.writeRow(self.csv.format(record))
                    self.output.run(record)
                    
#.........这里部分代码省略.........
开发者ID:Foxeh,项目名称:NetFlow-Collector,代码行数:103,代码来源:main.py

示例3: Interface

# 需要导入模块: from interface import Interface [as 别名]
# 或者: from interface.Interface import run [as 别名]
from interface import Interface


if __name__ == '__main__':
    interface = Interface()
    interface.run()
开发者ID:crappyoats,项目名称:eclipse_vision,代码行数:8,代码来源:main.py

示例4: Controller

# 需要导入模块: from interface import Interface [as 别名]
# 或者: from interface.Interface import run [as 别名]
class Controller(object):
    """Manages/controls one or more elevators that work together, assuming they both can access the same floors"""

    def __init__(self, elevators, floors, use_gui=True):
        """Creates a controller with `elevators` (positive int) elevators that can access `floors` (positive int)"""
        self.floors = floors
        self.elevators = list()
        for x in range(elevators):
            self.elevators.append(Elevator(self.floors, name="Elevator " + str(x+1)))
        self.called = dict()  # {1: {"up": False, "down": False}, 2: {"up": False, "down": False}}
        for x in range(floors):
            self.called[x+1] = {"up": False, "down": False}
        if use_gui:
            self.interface = Interface(self)
        else:
            self.interface = None

    def monitor_calls(self):
        """Monitors elevator calls"""
        while True:
            for floor in range(1, self.floors+1):
                for direction in ["up", "down"]:
                    if self.called[floor][direction]:
                        self.assign_elevator(floor, direction)

    def assign_elevator(self, floor, direction):
        """Assigns an elevator that is either not busy or is able to service the call"""
        assigned = None
        elevators = sorted(self.elevators, key=lambda e: abs(e.current_floor - floor))
        for elevator in elevators:
            if elevator.busy:
                # called to go up and elevator going up from lower floor
                if (direction == "up") and elevator.going_up and (elevator.current_floor < floor):
                    elevator.go_to[floor] = True
                    self.called[floor][direction] = False
                    break
                # called to go down and elevator going down from higher floor
                elif (direction == "down") and not elevator.going_up and (elevator.current_floor > floor):
                    elevator.go_to[floor] = True
                    self.called[floor][direction] = False
                    break
            else:
                # elevator has nothing to do, so give it something to do
                elevator.busy = True
                elevator.go_to[floor] = True
                self.called[floor][direction] = False
                break

    def call_elevator(self, floor, direction):
        """Calls an elevator from floor `floor` to the given direction ("up"/"down")"""
        self.called[floor][direction] = True

    def run(self):
        # Start the elevators
        for elevator in self.elevators:
            Thread(target=elevator.run).start()
        # Start the elevator assigner
        Thread(target=self.monitor_calls).start()
        if self.interface:
            self.interface.run()
            self.interface.window.mainloop()
开发者ID:StephenOrJames,项目名称:ElevatorSimulator,代码行数:63,代码来源:controller.py


注:本文中的interface.Interface.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。