Esempio n. 1
0
 def calcnewpos(self, rect, swarm_bots, nearby_bots, dest_vector):
     accel = flock(swarm_bots, nearby_bots, dest_vector, self.velocity)
     self.velocity = self.velocity.add(accel)
     MAX_SPEED = self.velocity.MAX_SPEED
     self.velocity = self.velocity.limit(
         MAX_SPEED) if self.velocity.speed > MAX_SPEED else self.velocity
     self.pos = self.pos.add(self.velocity)
     self.pos.speed = 0  # Keep Speed 0 cuz why not
     rect.x, rect.y = self.pos.x, self.pos.y
     return rect
Esempio n. 2
0

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_params_checker.lock', True).acquire()

if lock:
    # Задать переменные для внесения статистики
    numServers = 0
    numSlots = 0
    numPlayers = 0
    numErrors = 0
    numVoice = 0
    fmt = '%Y-%m-%d %H:%M:%S'  # Формат даты в БД
    crashedServers = []

    rrdDb = '/var/lib/systemgraph/gameLoad.rrd'
    userRrdDbPath = '/images/stat/bases/'

    # RRD - убрать после того, как сделаю новую статистику
Esempio n. 3
0
else:
    lastLogPos = 0

if lastLogSize:
    lastLogSize = int(lastLogSize)
else:
    lastLogSize = 0


lastAttackerIp = ''
lastAttackedIp = ''
lastAttackedPort = 0
lastAttackRule = ''

# Blocking the process
lock = flock('iptables_log_checker.lock', True).acquire()

if lock:
    if os.path.exists(logPath):
        log = open(logPath, 'r')

        if os.path.getsize(logPath) > lastLogSize:
            if lastLogPos > 0:
                log.seek(lastLogPos)

        elif os.path.getsize(logPath) == lastLogSize:
            print "Новых записей нет."
            sys.exit(0)

        j = 0
        pipe = r.pipeline()
Esempio n. 4
0
from Tkinter import *
import sys, os
import random
import flock

num_birds       =  100
cw              = 1000
ch              =  600
cycle           =   50

cohesion_rate   =  1.0
alignment_rate  =  2.3
separation_rate =  0.2
		
fl = flock.flock(cw, ch, num_birds, cohesion_rate, alignment_rate, separation_rate)
root = Tk()
root.title("flocking alogithm")

cnv = Canvas(root, width=cw, height=ch, background="black")
cnv.grid(row=0, column=0)
posn_x = 0.0
posn_y = 0.0

while 1 :
	
	fl.fream()
	for i in range(0, num_birds):
		posn_x = fl.birds[i].location[0]
		posn_y = fl.birds[i].location[1]
		x = fl.birds[i].valocity[0]
Esempio n. 5
0
    lastLogPos = int(lastLogPos)
else:
    lastLogPos = 0

if lastLogSize:
    lastLogSize = int(lastLogSize)
else:
    lastLogSize = 0

lastAttackerIp = ''
lastAttackedIp = ''
lastAttackedPort = 0
lastAttackRule = ''

# Blocking the process
lock = flock('iptables_log_checker.lock', True).acquire()

if lock:
    if os.path.exists(logPath):
        log = open(logPath, 'r')

        if os.path.getsize(logPath) > lastLogSize:
            if lastLogPos > 0:
                log.seek(lastLogPos)

        elif os.path.getsize(logPath) == lastLogSize:
            print "Новых записей нет."
            sys.exit(0)

        j = 0
        pipe = r.pipeline()
Esempio n. 6
0
import distutils.dir_util
import os
import pwd
import cgi
import cgitb
import shlex
import sys
import ConfigParser
import string
from shutil import *
from subprocess import *
from random import choice
from datetime import datetime
from optparse import OptionParser

lock = flock('radio_istall.lock', True).acquire()

if lock:
    parser = OptionParser()

    parser.add_option("-m",
                      "--server",
                      action="store",
                      type="int",
                      dest="serverID")
    parser.add_option("-u",
                      "--user",
                      action="store",
                      type="string",
                      dest="userID")
    parser.add_option("-t",
Esempio n. 7
0
        return '7709'

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('server_init.lock', True).acquire()

if lock:

    # print 'Получение данных из БД:'
    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost, user=mysqlUser, passwd=mysqlPass, db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    userCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    modCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    rootServerCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    rootServerIpCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Esempio n. 8
0

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('server_init.lock', True).acquire()

if lock:

    # print 'Получение данных из БД:'
    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost,
                         user=mysqlUser,
                         passwd=mysqlPass,
                         db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    userCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Esempio n. 9
0
    def __del__(self):
        """Magic method to clean up lock when program exits"""
        self.release()


## ========

## Test programs: run test1.py then test2.py (in the same dir)
## from another teminal -- test2.py should print
## a message that there is a lock in place and exit.

if __name__ == "__main__":
    # test1.py
    from time import sleep

    # from flock import flock
    lock = flock("tmp.lock", True).acquire()
    if lock:
        sleep(30)
    else:
        print "locked!"

    # test2.py
    from flock import flock

    lock = flock("tmp.lock", True).acquire()
    if lock:
        print "doing stuff"
    else:
        print "locked!"
Esempio n. 10
0
import distutils.dir_util
import os
import pwd
import cgi
import cgitb
import shlex
import sys
import ConfigParser
import string
from shutil import *
from subprocess import *
from random import choice
from datetime import datetime
from optparse import OptionParser

lock = flock('voice_istall.lock', True).acquire()

if lock:
    parser = OptionParser()

    parser.add_option("-m", "--server", action="store", type="int", dest="serverID")
    parser.add_option("-u", "--user", action="store", type="string", dest="userID")
    parser.add_option("-t", "--tmp", action="store", type="string", dest="template")
    parser.add_option("-i", "--ip", action="store", type="string", dest="ip")
    parser.add_option("-p", "--port", action="store", type="string", dest="port")
    parser.add_option("-s", "--slots", action="store", type="string", dest="slots")

    (options, args) = parser.parse_args(args=None, values=None)

    serverID = str(options.serverID)
    userID = str(options.userID)
Esempio n. 11
0
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_checker.lock', True).acquire()

if lock:

    print datetime.now().strftime("%A, %d. %B %Y %H:%M:%S")
    print 'Запрос данных из БД:'

    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost,
                         user=mysqlUser,
                         passwd=mysqlPass,
                         db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Esempio n. 12
0
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_rebooter.lock', True).acquire()

if lock:

    print datetime.now().strftime("%A, %d. %B %Y %H:%M:%S")
    # print 'Запрос данных из БД:'
    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost,
                         user=mysqlUser,
                         passwd=mysqlPass,
                         db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Esempio n. 13
0
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_gen_graphs.lock', True).acquire()

if lock:
    # host, user, pass, db
    db = MySQLdb.connect(host=mysqlHost, user=mysqlUser, passwd=mysqlPass, db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)

    servers = getRootServerPayedServers(cursor, thisServerId)

    numrows = int(servers.rowcount)

    logPrint('OK', 'Получены данные на %s серверов' % numrows)
Esempio n. 14
0
        '''Check if we own the lock'''
        lock = self._readlock()
        return (self.fddr() == self.pddr(lock))

    def __del__(self):
        '''Magic method to clean up lock when program exits'''
        self.release()

## ========

## Test programs: run test1.py then test2.py (in the same dir)
## from another teminal -- test2.py should print
## a message that there is a lock in place and exit.

# test1.py
from time import sleep
from flock import flock
lock = flock('tmp.lock', True).acquire()
if lock:
    sleep(30)
else:
    print 'locked!'

# test2.py
from flock import flock
lock = flock('tmp.lock', True).acquire()
if lock:
    print 'doing stuff'
else:
    print 'locked!'
Esempio n. 15
0
import distutils.dir_util
import os
import pwd
import cgi
import cgitb
import shlex
import sys
import ConfigParser
import string
from shutil import *
from subprocess import *
from random import choice
from datetime import datetime
from optparse import OptionParser

lock = flock('radio_istall.lock', True).acquire()

if lock:
    parser = OptionParser()

    parser.add_option("-m", "--server", action="store", type="int", dest="serverID")
    parser.add_option("-u", "--user", action="store", type="string", dest="userID")
    parser.add_option("-t", "--tmp", action="store", type="string", dest="template")
    parser.add_option("-i", "--ip", action="store", type="string", dest="ip")
    parser.add_option("-p", "--port", action="store", type="string", dest="port")
    parser.add_option("-s", "--slots", action="store", type="string", dest="slots")
   # parser.add_option("-b", "--bitrate", action="store", type="string", dest="bitrate")

    (options, args) = parser.parse_args(args=None, values=None)

    serverID = str(options.serverID)
Esempio n. 16
0
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_cleaner.lock', True).acquire()

if lock:

    presentTime = datetime.now().strftime("%A, %d. %B %Y %H:%M:%S")
    print presentTime
    print 'Запрос данных из БД:'

    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost,
                         user=mysqlUser,
                         passwd=mysqlPass,
                         db=mysqlDb)

    # Create cursor with row names as array arguments
Esempio n. 17
0
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_gen_graphs.lock', True).acquire()

if lock:
    # host, user, pass, db
    db = MySQLdb.connect(host=mysqlHost,
                         user=mysqlUser,
                         passwd=mysqlPass,
                         db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)

    servers = getRootServerPayedServers(cursor, thisServerId)

    numrows = int(servers.rowcount)
Esempio n. 18
0

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_checker.lock', True).acquire()

if lock:

    print datetime.now().strftime("%A, %d. %B %Y %H:%M:%S")
    print 'Запрос данных из БД:'

    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost, user=mysqlUser, passwd=mysqlPass, db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)

    servers = getRootServerPrivateServers(cursor, thisServerId)
Esempio n. 19
0
        return (self.fddr() == self.pddr(lock))

    def __del__(self):
        '''Magic method to clean up lock when program exits'''
        self.release()


## ========

## Test programs: run test1.py then test2.py (in the same dir)
## from another teminal -- test2.py should print
## a message that there is a lock in place and exit.

if __name__ == "__main__":
    # test1.py
    from time import sleep
    #from flock import flock
    lock = flock('tmp.lock', True).acquire()
    if lock:
        sleep(30)
    else:
        print 'locked!'

    # test2.py
    from flock import flock
    lock = flock('tmp.lock', True).acquire()
    if lock:
        print 'doing stuff'
    else:
        print 'locked!'
Esempio n. 20
0

config = ConfigParser.RawConfigParser()
config.read('/etc/hosting/scripts.cfg')

# ID сервера, на котором пускается скрипт
# Брать его из поля id в админке

thisServerId = config.getint('server', 'serverID')
mysqlHost = config.get('db', 'host')
mysqlUser = config.get('db', 'user')
mysqlPass = config.get('db', 'pass')
mysqlDb = config.get('db', 'db')

# Blocking the process
lock = flock('servers_rebooter.lock', True).acquire()

if lock:

    print datetime.now().strftime("%A, %d. %B %Y %H:%M:%S")
    # print 'Запрос данных из БД:'
    # host, user, pass, db

    db = MySQLdb.connect(host=mysqlHost, user=mysqlUser, passwd=mysqlPass, db=mysqlDb)

    # Create cursor with row names as array arguments
    cursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
    commonCursor = db.cursor(cursorclass=MySQLdb.cursors.DictCursor)

    servers = getRootServerExecutedServersToReboot(cursor, thisServerId)