Пример #1
0
class Scene(object):
	def __init__(self, config, trajectory):
		self.animate(config, trajectory)
		self._monkey = None

	def animate(self, config, trajectory):

		def handler(scene):
			frame = scene.frame_current
			if frame ==  10:
				self._grid = Grid(config.gridData)
				
			elif frame == 20:
				self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])

			n = 0

			for frame in range(40,80,10):
				moveVel = trajectory[n] - self._monkey.pos
				self._monkey.move(moveVel)
				n += 1
				print(n)
				break

			if frame == 250:
				self._monkey.delete(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])

		bpy.app.handlers.frame_change_pre.clear()
		bpy.app.handlers.frame_change_pre.append(handler)
Пример #2
0
 def initialize(self, config):
     self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])
     self._grid = Grid(config.gridData)
     self._kickers = []
     print(self._config.kickersData)
     for kickerData in self._config.kickersData:
         kicker = Kicker(kickerData[0], kickerData[1])
         self._kickers.append(kicker)
     self.createKickers()
Пример #3
0
class MonkeyThread(Thread):
    def __init__(self, logPath, device_id, pkgName):
        Thread.__init__(self)

        self.monkeyInstance = Monkey(logPath, device_id, pkgName)
        self.logPath = logPath

    def run(self):
        self.monkeyInstance.startMonkey()
Пример #4
0
def main():
    # testing base class - Animal
    animal = Animal("Luigi", 10)
    print(animal)

    # testing dereived class - Monkey
    mon = Monkey("Lily", 3)
    print(mon)
    print(mon.getNoise())
Пример #5
0
    def execute(self):
        #currentPath = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

        startTime = time.time()
        print("monkey开始时间:%s" % (datetime.datetime.now())).decode("utf-8")
        monkeyThreadInstance = MonkeyThread(self.logPath, self.deviceId,
                                            self.pkgName)
        utils.forceStop(self.pkgName, self.deviceId)
        #workPath = self.monkeyLogPath#os.path.join(self.monkeyLogPath, "logs", self.pkgName+getCurrentTime())
        #os.mkdir(workPath)
        if not os.path.exists(self.logPath):
            os.makedirs(self.logPath)

        try:
            monkeyThreadInstance.start()

            while True:
                endTime = time.time()
                # 清除之前的日志
                #                 utils.clearLog(self.deviceId)

                if (endTime - startTime) < self.minutes * 60:
                    if monkeyThreadInstance.is_alive():
                        time.sleep(10)
                    else:
                        #self.collect()
                        #self.analyse()

                        utils.forceStop(self.pkgName, self.deviceId)

                        #workPath = self.monkeyLogPath#os.path.join(currentPath, "logs", self.pkgName+getCurrentTime())
                        #os.mkdir(workPath)
                        if not os.path.exists(self.logPath):
                            os.makedirs(self.logPath)

                        monkeyThreadInstance = MonkeyThread(
                            self.deviceId, self.pkgName)
                        monkeyThreadInstance.start()
                else:
                    print("monkey结束时间:%s" %
                          (datetime.datetime.now())).decode("utf-8")
                    Monkey.terminateMonkey(self.deviceId)

                    self.collect()
                    self.analyse()
                    break
        except Exception, e:
            print("Monkey Exception:" % (e))
            print("Monkey traceback:" % (traceback.print_exc()))
            traceback.print_exc()
            Monkey.terminateMonkey(self.deviceId)
            self.collect()
            self.analyse()
Пример #6
0
def runMonkey():
    mk = Monkey()
    print mk.get_conf()
    print mk.get_command()
    mk.run(mk.get_command())

    return static_file(
        'monkey.html',
        root='/Users/dongqingqing/PycharmProjects/ApkPerforTools/static/html')
Пример #7
0
    def test_get_single_monkey_by_id(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        a_monkey = Monkey(guid=str(uuid.uuid4()))
        a_monkey.save()

        # Act + assert
        # Find the existing one
        self.assertIsNotNone(Monkey.get_single_monkey_by_id(a_monkey.id))
        # Raise on non-existent monkey
        self.assertRaises(MonkeyNotFoundError, Monkey.get_single_monkey_by_id,
                          "abcdefabcdefabcdefabcdef")
Пример #8
0
		def handler(scene):
			frame = scene.frame_current
			if frame ==  10:
				self._grid = Grid(config.gridData)
				
			elif frame == 20:
				self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])

			n = 0

			for frame in range(40,80,10):
				moveVel = trajectory[n] - self._monkey.pos
				self._monkey.move(moveVel)
				n += 1
				print(n)
				break

			if frame == 250:
				self._monkey.delete(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])
Пример #9
0
    def test_ttl_renewal(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        monkey = Monkey(guid=str(uuid.uuid4()))
        monkey.save()
        self.assertIsNone(monkey.ttl_ref)

        # act + assert
        monkey.renew_ttl()
        self.assertIsNotNone(monkey.ttl_ref)
Пример #10
0
    def test_get_label_by_id(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        hostname_example = "a_hostname"
        ip_example = "1.1.1.1"
        linux_monkey = Monkey(guid=str(uuid.uuid4()),
                              description="Linux shay-Virtual-Machine",
                              hostname=hostname_example,
                              ip_addresses=[ip_example])
        linux_monkey.save()

        cache_info_before_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        self.assertEquals(cache_info_before_query.hits, 0)

        # not cached
        label = Monkey.get_label_by_id(linux_monkey.id)

        self.assertIsNotNone(label)
        self.assertIn(hostname_example, label)
        self.assertIn(ip_example, label)

        # should be cached
        _ = Monkey.get_label_by_id(linux_monkey.id)
        cache_info_after_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        self.assertEquals(cache_info_after_query.hits, 1)

        linux_monkey.set_hostname("Another hostname")

        # should be a miss
        label = Monkey.get_label_by_id(linux_monkey.id)
        cache_info_after_second_query = Monkey.get_label_by_id.storage.backend.cache_info(
        )
        # still 1 hit only
        self.assertEquals(cache_info_after_second_query.hits, 1)
        self.assertEquals(cache_info_after_second_query.misses, 2)
Пример #11
0
    def connect(self):
        if self.needStop:
            return
        if self.url is None:
            print('need url for connect')
            return

        ecall('adb forward tcp:50001 tcp:50001')
        try:
            monkey = Monkey(self.url)
        except OSError:
            self.tryTimer = None
            self.tryTimer = Timer(1, self.connect)
            self.tryTimer.start()
            return
        self.monkey = monkey
        self.tryTimer = Timer(0.2, self._processConnectResult)
        self.tryTimer.start()
Пример #12
0
    def test_is_monkey(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        a_monkey = Monkey(guid=str(uuid.uuid4()))
        a_monkey.save()

        cache_info_before_query = Monkey.is_monkey.storage.backend.cache_info()
        self.assertEquals(cache_info_before_query.hits, 0)

        # not cached
        self.assertTrue(Monkey.is_monkey(a_monkey.id))
        fake_id = "123456789012"
        self.assertFalse(Monkey.is_monkey(fake_id))

        # should be cached
        self.assertTrue(Monkey.is_monkey(a_monkey.id))
        self.assertFalse(Monkey.is_monkey(fake_id))

        cache_info_after_query = Monkey.is_monkey.storage.backend.cache_info()
        self.assertEquals(cache_info_after_query.hits, 2)
Пример #13
0
    def __init__(self, logPath, device_id, pkgName):
        Thread.__init__(self)

        self.monkeyInstance = Monkey(logPath, device_id, pkgName)
        self.logPath = logPath
Пример #14
0
                        type=int,
                        help="Radio channel")

    parser.add_argument("--debug", action="store_true", default=False)

    args = parser.parse_args()

    if args.debug:
        import simplelogging.logsetup
        simplelogging.logsetup.setup_console()

    def closed():
        print("closed")
        reactor.callFromThread(reactor.stop)

    con = Monkey(args.connection, args.address, callback_reactor=reactor)
    con.set_closed_callback(closed)

    if args.channel is not None:
        reactor.callFromThread(con.set_channel, args.channel)

    pinger = PingSender(con, args)

    con.open()
    pinger.start()

    # Run the system
    reactor.run()

    con.close()
Пример #15
0
class World(object):
    def __init__(self, config):
        self._config = config
        self.initialize(self._config)
        self.evolve(self._config.modeData)  

    @property
    def kickers(self):
        return self._kickers
    @property
    def monkey(self):
        return self._monkey
    @property
    def grid(self):
        return self._grid

    def initialize(self, config):
        self._monkey = Monkey(config.monkeyData[0], config.monkeyData[1], config.monkeyData[2])
        self._grid = Grid(config.gridData)
        self._kickers = []
        print(self._config.kickersData)
        for kickerData in self._config.kickersData:
            kicker = Kicker(kickerData[0], kickerData[1])
            self._kickers.append(kicker)
        self.createKickers()

    def createKickers(self):
        for kicker in self._kickers:
            kicker.create()

    def evolve(self, isCustom):

        def handler(scene):
            frame = scene.frame_current
            if frame in range(0, 250, 10):
                metKicker = False          
                for kicker in self._kickers:
                    if kicker.pos == self._monkey.pos:
                        self._monkey.move(kicker.strenght)
                        metKicker = True
                        break
                if metKicker == False:
                    if isCustom:
                        self._monkey.evolveCustom()
                    else:
                        self._monkey.evolve()
            elif frame == 250:
                self.delete()
                bpy.app.handlers.frame_change_pre.clear()

        bpy.app.handlers.frame_change_pre.clear()
        bpy.app.handlers.frame_change_pre.append(handler)

    def delete(self):
        self._monkey.delete(self._config.monkeyData[0], self._config.monkeyData[1], self._config.monkeyData[2])
        self._monkey = None
        for kicker in self._kickers:
            kicker.delete()
        self._kickers = None
        self._grid.delete()
        self._grid = None
Пример #16
0
from dog import Dog
from monkey import Monkey

d = Dog('Bob')
m = Monkey('Rolf')

d.walk()
m.eat()
Пример #17
0
    def test_is_dead(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        # Arrange
        alive_monkey_ttl = MonkeyTtl.create_ttl_expire_in(30)
        alive_monkey_ttl.save()
        alive_monkey = Monkey(guid=str(uuid.uuid4()),
                              dead=False,
                              ttl_ref=alive_monkey_ttl.id)
        alive_monkey.save()

        # MIA stands for Missing In Action
        mia_monkey_ttl = MonkeyTtl.create_ttl_expire_in(30)
        mia_monkey_ttl.save()
        mia_monkey = Monkey(guid=str(uuid.uuid4()),
                            dead=False,
                            ttl_ref=mia_monkey_ttl)
        mia_monkey.save()
        # Emulate timeout - ttl is manually deleted here, since we're using mongomock and not a real mongo instance.
        sleep(1)
        mia_monkey_ttl.delete()

        dead_monkey = Monkey(guid=str(uuid.uuid4()), dead=True)
        dead_monkey.save()

        # act + assert
        self.assertTrue(dead_monkey.is_dead())
        self.assertTrue(mia_monkey.is_dead())
        self.assertFalse(alive_monkey.is_dead())
Пример #18
0
    def test_get_os(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        linux_monkey = Monkey(
            guid=str(uuid.uuid4()),
            description=
            "Linux shay-Virtual-Machine 4.15.0-50-generic #54-Ubuntu SMP Mon May 6 18:46:08 UTC 2019 x86_64 x86_64"
        )
        windows_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="Windows bla bla bla")
        unknown_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="bla bla bla")
        linux_monkey.save()
        windows_monkey.save()
        unknown_monkey.save()

        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "windows",
                          Monkey.objects())))
        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "linux", Monkey.objects())))
        self.assertEquals(
            1, len(filter(lambda m: m.get_os() == "unknown",
                          Monkey.objects())))
Пример #19
0
import threading
import time

import monkey_global
from mongo.monkey_job import MonkeyJob
from monkey import Monkey

monkey_global.QUIET_ANSIBLE = True
monkey = Monkey(start_loop=False)

print("Starting test_instance")
aws_provider = monkey.providers[0]
print(aws_provider)
print(aws_provider.list_instances())
instance = list(aws_provider.instances.values())[0]
print(instance)

job = MonkeyJob.objects()[0]
job_yml = job.job_yml
print(job_yml)

print(instance.get_json())


def run(run_number):
    time.sleep(5)
    print("Starting install.....")
    for install_item in job_yml.get("install", []):
        print("Installing item: ", install_item)
        success = instance.install_dependency(install_item)
        if success == False:
Пример #20
0
    g = Giraffe(4)
    g.say_hello()
    g.get_number_of_legs()
    g.how_do_i_move()
    g.how_much_do_i_weigh()
    g.am_i_extinct()

if What_animal == "Hippo":
    h = Hippo(4)
    h.say_hello()
    h.get_number_of_legs()
    h.how_do_i_move()
    h.how_much_do_i_weigh()
    h.am_i_extinct()

if What_animal == "Monkey":
    m = Monkey(2)
    m.say_hello()
    m.get_number_of_legs()
    m.how_do_i_move()
    m.how_much_do_i_weigh()
    m.am_i_extinct()

if What_animal == "Bee":
    be = Bee(0)
    be.say_hello()
    be.get_number_of_legs()
    be.how_do_i_move()
    be.how_much_do_i_weigh()
    be.am_i_extinct()
Пример #21
0
    def test_get_tunneled_monkeys(self):
        self.fail_if_not_testing_env()
        self.clean_monkey_db()

        linux_monkey = Monkey(guid=str(uuid.uuid4()),
                              description="Linux shay-Virtual-Machine")
        windows_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="Windows bla bla bla",
                                tunnel=linux_monkey)
        unknown_monkey = Monkey(guid=str(uuid.uuid4()),
                                description="bla bla bla",
                                tunnel=windows_monkey)
        linux_monkey.save()
        windows_monkey.save()
        unknown_monkey.save()
        tunneled_monkeys = Monkey.get_tunneled_monkeys()
        test = bool(windows_monkey in tunneled_monkeys
                    and unknown_monkey in tunneled_monkeys
                    and linux_monkey not in tunneled_monkeys
                    and len(tunneled_monkeys) == 2)
        self.assertTrue(test, "Tunneling test")
Пример #22
0
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
hdlr = logging.FileHandler(monkey_global.LOG_FILE)
formatter = logging.Formatter(log_format, log_date_format)
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)

date_format = "monkey-%y-%m-%d-"
instance_number = 0
last_date = datetime.now().strftime(date_format)

lock = threading.Lock()
monkey = Monkey()

UNIQUE_UIDS = True

MONKEYFS_LOCAL_PATH = "ansible/monkeyfs"


def get_local_filesystem_for_provider(provider_name):
    found_provider = None
    for provider in monkey.providers:
        if provider.name == provider_name:
            found_provider = provider

    if found_provider is None:
        logger.info("Failed to find provider with specified name for job")
        return None
Пример #23
0
    parser.add_argument("--channel", default=None, type=int, help="Radio channel")

    parser.add_argument("--debug", action="store_true", default=False)

    args = parser.parse_args()

    if args.debug:
        import simplelogging.logsetup
        simplelogging.logsetup.setup_console()

    def closed():
        print("closed")
        reactor.callFromThread(reactor.stop)

    con = Monkey(args.connection, args.address, callback_reactor=reactor)
    con.set_closed_callback(closed)

    if args.channel is not None:
        reactor.callFromThread(con.set_channel, args.channel)

    pinger = PingSender(con, args)

    con.open()
    pinger.start()

    # Run the system
    reactor.run()

    con.close()
Пример #24
0
    do_human = False

    args = sys.argv[1:]
    if len(args) < 1:
        usage()
    if args[0] == "--human":
        do_human = True
    elif args[0] == "--test":
        in_file = open(args[1], "r") if len(args) >= 2 else usage()
    elif args[0] == "--engine":
        in_file = sys.stdin
    else:
        usage()

    # create players
    p1 = Monkey(1) if do_human else Player(1)
    p2 = Monkey(2)  # AI - can do play_move() and gen_move()
    p1.logger = logger
    p2.logger = logger

    # create engine
    engine = Engine()

    # create board of default size 19
    board = Board(19)

    # attach everything
    engine.board = board
    engine.set_players(p1, p2)
    engine.logger = logger
    p1.engine = engine