Exemplo n.º 1
0
    def handle_close(self):
        '''Handle connection closings.'''

        asyncore.dispatcher.close(self)

        logger.info('connection to %s lost' % self.server['id'])
        self.server['connected'] = False

        if self.server['recontime']:
            logger.info('reconnecting to %s in %d second%s' % (self.server['id'], self.server['recontime'], 's' if self.server['recontime'] != 1 else ''))
            timer.add('uplink.reconnect', True, reinit, self.server['recontime'], self.server)

            event.dispatch('OnReconnect', self.server)
        else:
            # Exit.
            shutdown(os.EX_SOFTWARE, 'no reconnection to %s, therefore we dont need to hang around' % self.server['id'])
Exemplo n.º 2
0
    def handle_close(self):
        asyncore.dispatcher.close(self)

        logger.info('%s: Connection lost.' % self.server['id'])
        self.server['connected'] = False

        event.dispatch('OnConnectionClose', self.server)

        if self.server['recontime']:
            logger.info('%s: Reconnecting in %d second%s.' %
                        (self.server['id'], self.server['recontime'],
                         's' if self.server['recontime'] != 1 else ''))
            timer.add('io.reconnect', True, connect, self.server['recontime'],
                      self.server)

            event.dispatch('OnPostReconnect', self.server)
        else:
            # Remove us from the connections list.
            try:
                var.conns.remove(self)
            except ValueError:
                logger.error(
                    '%s: Could not find myself in the connectons list (BUG)' %
                    self.server['address'])
Exemplo n.º 3
0
    def finish(self):
        call_body = self.call.body
        if self.call.step:
            glob.workflow_id = self.call.wfid
            glob.workflow_step = self.call.step
        full_content = True
        results = []
        sizes = []

        timer.start('work.stage_out')

        if os.path.isfile(self.sandbox + self.task_dbg_log):
            with open(self.sandbox + self.task_dbg_log) as f:
                for line in f:
                    if line.startswith('----prune_task_return'):
                        (a, fname, size, cbid) = line[:-1].split('|')
                        if size and len(size) > 0:
                            sizes.append(int(size))
                        else:
                            sizes.append(-1)
                        results.append(cbid)
                    elif line.startswith('----prune_task_start'):
                        (a, taskstart) = line[:-1].split('|')
                    elif line.startswith('----prune_task_end'):
                        (a, taskfinish) = line[:-1].split('|')

        if os.path.isfile(self.sandbox + self.env_dbg_log):
            with open(self.sandbox + self.env_dbg_log) as f:
                for line in f:
                    if line.startswith('----prune_env_start'):
                        (a, envstart) = line[:-1].split('|')
                    elif line.startswith('----prune_env_end'):
                        (a, envfinish) = line[:-1].split('|')

        if os.path.isfile(self.sandbox + self.cmd_dbg_log):
            with open(self.sandbox + self.cmd_dbg_log) as f:
                for line in f:
                    if line.startswith('----prune_cmd_start'):
                        (a, cmdstart) = line[:-1].split('|')
                    elif line.startswith('----prune_cmd_end'):
                        (a, cmdfinish) = line[:-1].split('|')

        for i, src in enumerate(call_body['returns']):
            if os.path.isfile(self.sandbox + src):
                it = Item(type='temp',
                          cbid=results[i],
                          dbid=self.call.cbid + ':' + str(i),
                          path=self.sandbox + src,
                          size=sizes[i])
                glob.db.insert(it)

            else:
                d('exec',
                  'sandbox return file not found: ' + self.sandbox + src)
                full_content = False

        timer.stop('work.stage_out')

        if full_content:
            d('exec', 'Sandbox success kept at: ' + self.sandbox)
            timer.start('work.report')

            cmd_time = float(cmdfinish) - float(cmdstart)
            env_time = (float(envfinish) - float(envstart)) - cmd_time
            task_time = (float(taskfinish) -
                         float(taskstart)) - cmd_time - env_time
            meta = {
                'task_time': task_time,
                'env_time': env_time,
                'cmd_time': cmd_time
            }
            it = Item(type='work',
                      cbid=self.call.cbid + '()',
                      meta=meta,
                      body={
                          'results': results,
                          'sizes': sizes
                      })
            glob.db.insert(it)

            timer.add(cmd_time, 'work.execution_time')
            timer.add(env_time, 'work.environment_overhead')
            timer.add(task_time, 'work.prune_overhead')

            timer.stop('work.report')

        else:
            self.results = results
            d('exec', 'sandbox failure kept: ' + self.sandbox)
Exemplo n.º 4
0
import Client
def subtract(minuend, subtrahend):
    return minuend - subtrahend
def cmd():
    import os
    os.system('shutdown.exe -s')
    
if __name__=='__main__':
    server = Client.Client()
    server.initSender(False, 'pouloghost123', '', \
                      'smtp.yeah.net', '*****@*****.**',\
                      toaddr = '*****@*****.**')
    server.initRPC()
    server.initPoller(False, '*****@*****.**', '', \
                      'imap.yeah.net', port = 143)
    server.registerHandler('subtract', subtract)
    server.registerHandler('cmd', cmd)
    server.connect()
    server.sendOnline()
    
    import timer, time
    task = timer.Task(server.poll, interval = 3)
    timer = timer.Timer()
    timer.add(task)
    time.sleep(600)
    timer.cancel()
Exemplo n.º 5
0
	def finish( self ):
		call_body = self.call.body
		if self.call.step:
			glob.workflow_id = self.call.wfid
			glob.workflow_step = self.call.step
		full_content = True
		results = []
		sizes = []

		timer.start('work.stage_out')

		with open(self.sandbox + 'PRUNE_TASK_LOG') as f:
			for line in f:
				if line.startswith('sha1sum'):
					(a, fname, cbid) = line.split(' ')
					results.append( cbid.strip() )
				elif line.startswith('filesize'):
					(a, fname, size) = line.split(' ')
					size = size.strip()
					if size and len(size)>0:
						sizes.append( int(size) )
					else:
						sizes.append( -1 )
				elif line.startswith('prune_call_start'):
					(a, estart) = line.split(' ')
				elif line.startswith('prune_call_end'):
					(a, efinish) = line.split(' ')
				elif line.startswith('prune_cmd_start'):
					(a, cstart) = line.split(' ')
				elif line.startswith('prune_cmd_end'):
					(a, cfinish) = line.split(' ')
				elif line.startswith('prune_stage_out_start'):
					(a, sostart) = line.split(' ')
				elif line.startswith('prune_stage_out_end'):
					(a, sofinish) = line.split(' ')

		if self.env and self.env.body['engine'] == 'umbrella':
			for i, src in enumerate( call_body['returns'] ):
				full_src = "/tmp/umbrella_prune/%s/%s" % (self.sbid, src)

				if os.path.isfile( full_src ):
					it = Item( type='temp', cbid=results[i], dbid=self.call.cbid+':'+str(i), path=full_src, size=sizes[i] )
					glob.db.insert( it )

				else:
					d( 'exec', 'sandbox return file not found: '+full_src )
					full_content = False
		else:
			for i, src in enumerate( call_body['returns'] ):
				if os.path.isfile( self.sandbox + src ):
					it = Item( type='temp', cbid=results[i], dbid=self.call.cbid+':'+str(i), path=self.sandbox + src, size=sizes[i] )
					glob.db.insert( it )

				else:
					d( 'exec', 'sandbox return file not found: '+self.sandbox + src )
					full_content = False


		timer.stop('work.stage_out')

		if full_content:
			d( 'exec', 'sandbox kept at: '+self.sandbox )
			timer.start('work.report')

			wall_time = float(cfinish)-float(cstart)
			env_time = (float(efinish)-float(estart)) - wall_time
			meta = {'wall_time':wall_time,'env_time':env_time}
			it = Item( type='work', cbid=self.call.cbid+'()', meta=meta, body={'results':results, 'sizes':sizes} )
			glob.db.insert( it )

			timer.add( env_time, 'work.environment_use' )
			timer.add( wall_time, 'work.wall_time' )
			timer.add( (float(sofinish)-float(sostart)), 'work.stage_out.hash' )

			timer.stop('work.report')

		else:
			d( 'exec', 'sandbox kept: '+self.sandbox )
Exemplo n.º 6
0
	def finish( self ):
		call_body = self.call.body
		full_content = True
		meta_results = [] # place for debugging information (for example)
		tmp_results = []
		tmp_sizes = []
		try:

			print 'Prune Task stdout:',self.task.output

			with open(self.sandbox + 'PRUNE_TASK_LOG') as f:
				for line in f:
					#print line
					if line.startswith('sha1sum'):
						(a, fname, cbid) = line.split(' ')
						tmp_results.append( cbid.strip() )
					elif line.startswith('filesize'):
						(a, fname, size) = line.split(' ')
						tmp_sizes.append( int(size.strip()) )
					elif line.startswith('prune_call_start'):
						(a, estart) = line.split(' ')
					elif line.startswith('prune_call_end'):
						(a, efinish) = line.split(' ')
					elif line.startswith('prune_cmd_start'):
						(a, cstart) = line.split(' ')
					elif line.startswith('prune_cmd_end'):
						(a, cfinish) = line.split(' ')
					elif line.startswith('prune_stage_out_start'):
						(a, sostart) = line.split(' ')
					elif line.startswith('prune_stage_out_end'):
						(a, sofinish) = line.split(' ')

			for i, rtrn in enumerate( call_body['returns'] ):
				result = self.results[i]
				print result, rtrn

				if os.path.isfile( result ):
					it = Item( type='temp', cbid=tmp_results[i], dbid=self.call.cbid+':'+str(i), path=result, size=tmp_sizes[i] )
					glob.db.insert( it )

				else:
					d( 'exec', 'sandbox return file not found: ',rtrn )
					full_content = False

			if full_content:
				d( 'exec', 'sandbox kept at: '+self.sandbox )

				timer.start('work.report')

				wall_time = float(cfinish)-float(cstart)
				env_time = (float(efinish)-float(estart)) - wall_time
				meta = {'wall_time':wall_time,'env_time':env_time}
				it = Item( type='work', cbid=self.call.cbid+'()', meta=meta, body={'results':tmp_results, 'sizes':tmp_sizes} )
				glob.db.insert( it )

				timer.add( env_time, 'work.environment_use' )
				timer.add( wall_time, 'work.wall_time' )
				timer.add( (float(sofinish)-float(sostart)), 'work.stage_out.hash' )

				timer.stop('work.report')

			else:
				d( 'exec', 'sandbox kept: '+self.sandbox )
		except:
			print traceback.format_exc()
			glob.db.task_fail( self.call )
Exemplo n.º 7
0
    def finish(self):
        call_body = self.call.body
        if self.call.step:
            glob.workflow_id = self.call.wfid
            glob.workflow_step = self.call.step
        full_content = True
        results = []
        sizes = []

        timer.start('work.stage_out')

        with open(self.sandbox + 'PRUNE_TASK_LOG') as f:
            for line in f:
                if line.startswith('sha1sum'):
                    (a, fname, cbid) = line.split(' ')
                    results.append(cbid.strip())
                elif line.startswith('filesize'):
                    (a, fname, size) = line.split(' ')
                    sizes.append(int(size.strip()))
                elif line.startswith('prune_call_start'):
                    (a, estart) = line.split(' ')
                elif line.startswith('prune_call_end'):
                    (a, efinish) = line.split(' ')
                elif line.startswith('prune_cmd_start'):
                    (a, cstart) = line.split(' ')
                elif line.startswith('prune_cmd_end'):
                    (a, cfinish) = line.split(' ')
                elif line.startswith('prune_stage_out_start'):
                    (a, sostart) = line.split(' ')
                elif line.startswith('prune_stage_out_end'):
                    (a, sofinish) = line.split(' ')

        if self.env and self.env.body['engine'] == 'umbrella':
            for i, src in enumerate(call_body['returns']):
                full_src = "/tmp/umbrella_prune/%s/%s" % (self.sbid, src)

                if os.path.isfile(full_src):
                    it = Item(type='temp',
                              cbid=results[i],
                              dbid=self.call.cbid + ':' + str(i),
                              path=full_src,
                              size=sizes[i])
                    glob.db.insert(it)

                else:
                    d('exec', 'sandbox return file not found: ' + full_src)
                    full_content = False
        else:
            for i, src in enumerate(call_body['returns']):
                if os.path.isfile(self.sandbox + src):
                    it = Item(type='temp',
                              cbid=results[i],
                              dbid=self.call.cbid + ':' + str(i),
                              path=self.sandbox + src,
                              size=sizes[i])
                    glob.db.insert(it)

                else:
                    d('exec',
                      'sandbox return file not found: ' + self.sandbox + src)
                    full_content = False

        timer.stop('work.stage_out')

        if full_content:
            d('exec', 'sandbox kept at: ' + self.sandbox)
            timer.start('work.report')

            wall_time = float(cfinish) - float(cstart)
            env_time = (float(efinish) - float(estart)) - wall_time
            meta = {'wall_time': wall_time, 'env_time': env_time}
            it = Item(type='work',
                      cbid=self.call.cbid + '()',
                      meta=meta,
                      body={
                          'results': results,
                          'sizes': sizes
                      })
            glob.db.insert(it)

            timer.add(env_time, 'work.environment_use')
            timer.add(wall_time, 'work.wall_time')
            timer.add((float(sofinish) - float(sostart)),
                      'work.stage_out.hash')

            timer.stop('work.report')

        else:
            d('exec', 'sandbox kept: ' + self.sandbox)
Exemplo n.º 8
0
def moveRockford(data, direction):
    """
    deplace rockford

    :param list rockford: rockford
    :param list rockford: couple direction (abscisse, ordonnee)
    :param list curMap: map actuel sous forme de liste
    :param list fallables: liste de couple de fallable (abscisse, ordonnee)

    >>> moveRockford([(1, 1), 0], (1,0), \
        [['150s', '1d'],['B', 'R', 'G'], ['.', 'E', 'D']], [(0, 1), (2, 2)])
    [(2, 1), 0]

    >>> moveRockford([(1, 1), 0], (1,1), \
        [['150s', '1d'],['Brender.update(data, "gameCanvas") ', 'R', 'G'], ['.', 'E', 'D']], [(0, 1), (2, 2)])
    [(2, 2), 1]

    >>> moveRockford([(1, 1), 0], (0,1), \
        [['150s', '1d'],['B', 'R', 'G'], ['.', 'E', 'D']], [(0, 1), (2, 2)])
    'win'



    (rockford), direction, (curMap), (fallables), endy
    """

    global GAME_STATUS

    aimCoord = sumTuple(data["rockford"], direction)

    aimCell = getCell(data["map"], aimCoord)

    enddoor = "O" if data["end"]["open"] else "E"

    if aimCell == ".":
        setRockfordCell(data["map"], data["rockford"], aimCoord)
        changeRockfordPos(data, aimCoord)

    elif aimCell == "G":
        setRockfordCell(data["map"], data["rockford"], aimCoord)
        changeRockfordPos(data, aimCoord)

    elif aimCell == "B":
        if direction[
                1] == 0:  # deplacer boulet uniquement si direction lateral
            behindBoulder = sumTuple(aimCoord, direction)
            if (getCell(data["map"], behindBoulder) == "."):
                setRockfordCell(data["map"], data["rockford"], aimCoord)
                setCell(data["map"], behindBoulder, "B")
                updateFallable(data, aimCoord, behindBoulder)
                changeRockfordPos(data, aimCoord)

    elif aimCell == "D" or aimCell == "X":
        setRockfordCell(data["map"], data["rockford"], aimCoord)
        data["fall"]["fallables"].remove({"pos": aimCoord, "falling": False})
        if aimCell == "D":
            changeRockfordPos(data, aimCoord, True)
            timer.add("game", -10)
            data["score"] += 100
            if data["diamonds"]["owned"] == int(data["map"][0][1]):
                data["end"]["open"] = True
                enddoor = "O"
                setCell(data["map"], data["end"]["pos"], enddoor)
        else:
            changeRockfordPos(data, aimCoord, False)
            timer.add("game", -100)
            data["score"] += 1000

    elif aimCell == "O":
        setRockfordCell(data["map"], data["rockford"], aimCoord, aim=enddoor)
        GAME_STATUS = True
Exemplo n.º 9
0
	def finish( self ):
		call_body = self.call.body
		if self.call.step:
			glob.workflow_id = self.call.wfid
			glob.workflow_step = self.call.step
		full_content = True
		results = []
		sizes = []

		timer.start('work.stage_out')

		if os.path.isfile(self.sandbox + self.task_dbg_log):
			with open(self.sandbox + self.task_dbg_log) as f:
				for line in f:
					if line.startswith('----prune_task_return'):
						(a, fname, size, cbid) = line[:-1].split('|')
						if size and len(size)>0:
							sizes.append( int(size) )
						else:
							sizes.append( -1 )
						results.append( cbid )
					elif line.startswith('----prune_task_start'):
						(a, taskstart) = line[:-1].split('|')
					elif line.startswith('----prune_task_end'):
						(a, taskfinish) = line[:-1].split('|')

		if os.path.isfile(self.sandbox + self.env_dbg_log):
			with open(self.sandbox + self.env_dbg_log) as f:
				for line in f:
					if line.startswith('----prune_env_start'):
						(a, envstart) = line[:-1].split('|')
					elif line.startswith('----prune_env_end'):
						(a, envfinish) = line[:-1].split('|')

		if os.path.isfile(self.sandbox + self.cmd_dbg_log):
			with open(self.sandbox + self.cmd_dbg_log) as f:
				for line in f:
					if line.startswith('----prune_cmd_start'):
						(a, cmdstart) = line[:-1].split('|')
					elif line.startswith('----prune_cmd_end'):
						(a, cmdfinish) = line[:-1].split('|')


		for i, src in enumerate( call_body['returns'] ):
			if os.path.isfile( self.sandbox + src ):
				it = Item( type='temp', cbid=results[i], dbid=self.call.cbid+':'+str(i), path=self.sandbox + src, size=sizes[i] )
				glob.db.insert( it )

			else:
				d( 'exec', 'sandbox return file not found: '+self.sandbox + src )
				full_content = False


		timer.stop('work.stage_out')

		if full_content:
			d( 'exec', 'Sandbox success kept at: '+self.sandbox )
			timer.start('work.report')

			cmd_time = float(cmdfinish)-float(cmdstart)
			env_time = (float(envfinish)-float(envstart))-cmd_time
			task_time = (float(taskfinish)-float(taskstart))-cmd_time-env_time
			meta = {'task_time':task_time,'env_time':env_time,'cmd_time':cmd_time}
			it = Item( type='work', cbid=self.call.cbid+'()', meta=meta, body={'results':results, 'sizes':sizes} )
			glob.db.insert( it )

			timer.add( cmd_time, 'work.execution_time' )
			timer.add( env_time, 'work.environment_overhead' )
			timer.add( task_time, 'work.prune_overhead' )

			timer.stop('work.report')

		else:
			self.results = results
			d( 'exec', 'sandbox failure kept: '+self.sandbox )
Exemplo n.º 10
0
    def finish(self):
        call_body = self.call.body
        full_content = True
        meta_results = []  # place for debugging information (for example)
        tmp_results = []
        tmp_sizes = []
        try:

            print 'Prune Task stdout:', self.task.output

            with open(self.sandbox + 'PRUNE_TASK_LOG') as f:
                for line in f:
                    #print line
                    if line.startswith('sha1sum'):
                        (a, fname, cbid) = line.split(' ')
                        tmp_results.append(cbid.strip())
                    elif line.startswith('filesize'):
                        (a, fname, size) = line.split(' ')
                        tmp_sizes.append(int(size.strip()))
                    elif line.startswith('prune_call_start'):
                        (a, estart) = line.split(' ')
                    elif line.startswith('prune_call_end'):
                        (a, efinish) = line.split(' ')
                    elif line.startswith('prune_cmd_start'):
                        (a, cstart) = line.split(' ')
                    elif line.startswith('prune_cmd_end'):
                        (a, cfinish) = line.split(' ')
                    elif line.startswith('prune_stage_out_start'):
                        (a, sostart) = line.split(' ')
                    elif line.startswith('prune_stage_out_end'):
                        (a, sofinish) = line.split(' ')

            for i, rtrn in enumerate(call_body['returns']):
                result = self.results[i]
                print result, rtrn

                if os.path.isfile(result):
                    it = Item(type='temp',
                              cbid=tmp_results[i],
                              dbid=self.call.cbid + ':' + str(i),
                              path=result,
                              size=tmp_sizes[i])
                    glob.db.insert(it)

                else:
                    d('exec', 'sandbox return file not found: ', rtrn)
                    full_content = False

            if full_content:
                d('exec', 'sandbox kept at: ' + self.sandbox)

                timer.start('work.report')

                wall_time = float(cfinish) - float(cstart)
                env_time = (float(efinish) - float(estart)) - wall_time
                meta = {'wall_time': wall_time, 'env_time': env_time}
                it = Item(type='work',
                          cbid=self.call.cbid + '()',
                          meta=meta,
                          body={
                              'results': tmp_results,
                              'sizes': tmp_sizes
                          })
                glob.db.insert(it)

                timer.add(env_time, 'work.environment_use')
                timer.add(wall_time, 'work.wall_time')
                timer.add((float(sofinish) - float(sostart)),
                          'work.stage_out.hash')

                timer.stop('work.report')

            else:
                d('exec', 'sandbox kept: ' + self.sandbox)
        except:
            print traceback.format_exc()
            glob.db.task_fail(self.call)