Example #1
0
    def __init__(self, configFile=None, logger=None):
        self.configParser = Config(configFile, logger=logger)

        self.logger = logger
        self.downTime = None
        self.connection = None
        self.transaction_cursor = None
Example #2
0
class Database:
    """
	PostgreSQL specific database adapter.
	"""
    def __init__(self, configFile=None, logger=None):
        self.configParser = Config(configFile, logger=logger)

        self.logger = logger
        self.downTime = None
        self.connection = None
        self.transaction_cursor = None

    def connect(self):
        """
		Connection to database. Settings are loaded from config.ini

		@raise DatabaseConnectionFailedException Raised when conneciton to database failed.
		"""
        host = self.configParser.get('database', 'host')
        db = self.configParser.get('database', 'database')
        user = self.configParser.get('database', 'username')
        password = self.configParser.get('database', 'password')

        try:
            self.connection = pgdb.connect(dsn=host + ":" + db,
                                           user=user,
                                           password=password)
        except pgdb.DatabaseError, e:
            raise DatabaseConnectionFailedException(e)
Example #3
0
class Database:
	"""
	PostgreSQL specific database adapter.
	"""
	def __init__(self, configFile=None, logger=None):
		self.configParser = Config(configFile, logger=logger)

		self.logger = logger
		self.downTime = None
		self.connection = None
		self.transaction_cursor = None

	def connect(self):
		"""
		Connection to database. Settings are loaded from config.ini

		@raise DatabaseConnectionFailedException Raised when conneciton to database failed.
		"""
		host = self.configParser.get('database', 'host')
		db = self.configParser.get('database', 'database')
		user = self.configParser.get('database', 'username')
		password = self.configParser.get('database', 'password')

		try:
			self.connection = pgdb.connect(dsn=host+":"+db, user=user, password=password)
		except pgdb.DatabaseError, e:
			raise DatabaseConnectionFailedException(e)
Example #4
0
def get_application(config=None):
    if config is None:
        config = Config()
    apppath = config.get('application', 'engine.app.application')
    appfunc = load_object(apppath)
    # heart_beat(config)
    return appfunc(config)
Example #5
0
def cli(config, verbose):
    """
    datamaps is a tool for moving data to and from spreadsheets. Documentation available
    at https://www.datamaps.twentyfoursoftware.com (comming soon).

    Please note: datamaps is beta software! Development is ongoing and the program
    is undergoing continuous change.
    """
    click.secho(f"Welcome to datamaps {__version__} © Twenty Four Software",
                fg="yellow")
    config.verbose = verbose
    engine_config.initialise()
Example #6
0
def play():
    config = Config()
    winner = None
    while winner == None:
        show(config)
        start, dest = ask()
        if config.try_play(start, dest):
            winner, _ = config.winner()
        else:
            print("Invalid move, please replay")
    show(config)
    show_winner(winner)
Example #7
0
 def setUp(self):
     d = self.mktemp()
     os.mkdir(d)
     config = Config(values={'eggs_dir': d, 'logs_dir': d})
     config.cp.add_section('settings')
     config.cp.set('settings', 'newbot', 'newbot.settings')
     self.environ = Environment(config, initenv={})
Example #8
0
	def __init__(self, configFile=None, logger=None):
		self.configParser = Config(configFile, logger=logger)

		self.logger = logger
		self.downTime = None
		self.connection = None
		self.transaction_cursor = None
Example #9
0
def get_spider_list(project, runner=None, pythonpath=None, version=''):
    """Return the spider list from the given project, using the given runner"""
    if "cache" not in get_spider_list.__dict__:
        get_spider_list.cache = UtilsCache()
    try:
        return get_spider_list.cache[project][version]
    except KeyError:
        pass
    if runner is None:
        runner = Config().get('runner')
    env = os.environ.copy()
    env['PYTHONIOENCODING'] = 'UTF-8'
    env['SCRAPY_PROJECT'] = project
    if pythonpath:
        env['PYTHONPATH'] = pythonpath
    if version:
        env['SCRAPY_EGG_VERSION'] = version
    pargs = [sys.executable, '-m', runner, 'list']
    proc = Popen(pargs, stdout=PIPE, stderr=PIPE, env=env)
    out, err = proc.communicate()
    if proc.returncode:
        msg = err or out or ''
        msg = msg.decode('utf8')
        raise RuntimeError(msg.encode('unicode_escape') if six.PY2 else msg)
    # FIXME: can we reliably decode as UTF-8?
    # scrapy list does `print(list)`
    tmp = out.decode('utf-8').splitlines()
    try:
        project_cache = get_spider_list.cache[project]
        project_cache[version] = tmp
    except KeyError:
        project_cache = {version: tmp}
    get_spider_list.cache[project] = project_cache
    return tmp
Example #10
0
def main():
  config = Config(
    FPS,
    WIN_WIDTH,
    WIN_HEIGHT
  )

  game = Game(config)

  game.sprite_manager.register([
    SpriteConfig('bg', os.path.join(local_dir, "assets/bg.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird1', os.path.join(local_dir, "assets/bird1.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird2', os.path.join(local_dir, "assets/bird2.png"), [pygame.transform.scale2x]),
    SpriteConfig('bird3', os.path.join(local_dir, "assets/bird3.png"), [pygame.transform.scale2x]),
    SpriteConfig('base', os.path.join(local_dir, "assets/base.png"), [pygame.transform.scale2x]),
    SpriteConfig('pipe', os.path.join(local_dir, "assets/pipe.png"), [pygame.transform.scale2x]),
  ])

  background = Background(game.sprite_manager.get('bg'))
  birds = [
    Bird(230, 350, game.sprite_manager.get('bird1')),
    Bird(130, 350, game.sprite_manager.get('bird1')),
  ]

  game.state.add([background] + birds)

  game.start()
Example #11
0
def train():
    config = Config()
    while True:
        print("NEW GAME")
        winner = None
        mcts = MCTS(config)
        train_configs = []
        target_policys = []
        target_values = []
        while winner == None:
            mcts.search(config)
            policy, best_move = mcts.get_mcts_policy()
            prepare_training(config, policy, train_configs, target_policys,
                             target_values)
            config.apply_move(best_move, True)
            show(config)
            winner, _ = config.winner()
        objgraph.show_most_common_types()
        target_values = np.array(target_values) * winner
        train_configs = np.array(train_configs)
        target_policys = np.array(target_policys)
        mcts.model.fit(train_configs, [target_values, target_policys],
                       epochs=1,
                       batch_size=4,
                       shuffle=True)
        mcts.model.save("bot/chess_model.h5")
        config.reset()
Example #12
0
def cli(config, verbose):
    """
    datamaps is a tool for moving data to and from spreadsheets. Documentation available
    at https://www.datamaps.twentyfoursoftware.com.

    Please note: datamaps is beta software! Development is ongoing and the program
    is undergoing continuous change.

    Use --help flag after all commands to get help. For example:

        datamaps import templates --help (for
        etc...
    """
    click.secho(
        f"Welcome to datamaps {__version__} © 2021 Twenty Four Software", fg="yellow"
    )
    config.verbose = verbose
    engine_config.initialise()
Example #13
0
 def test_get_environment_with_no_items_dir(self):
     config = Config(values={'items_dir': '', 'logs_dir': ''})
     config.cp.add_section('settings')
     config.cp.set('settings', 'newbot', 'newbot.settings')
     msg = {'_project': 'mybot', '_spider': 'myspider', '_job': 'ID'}
     slot = 3
     environ = Environment(config, initenv={})
     env = environ.get_environment(msg, slot)
     self.failUnless('SCRAPY_FEED_URI' not in env)
     self.failUnless('SCRAPY_LOG_FILE' not in env)
Example #14
0
 def setUp(self):
     d = self.mktemp()
     eggs_dir = os.path.join(d, 'eggs')
     dbs_dir = os.path.join(d, 'dbs')
     os.makedirs(eggs_dir)
     os.makedirs(dbs_dir)
     os.makedirs(os.path.join(eggs_dir, 'mybot1'))
     os.makedirs(os.path.join(eggs_dir, 'mybot2'))
     config = Config(values={'eggs_dir': eggs_dir, 'dbs_dir': dbs_dir})
     self.queues = get_spider_queues(config)
     self.poller = QueuePoller(config)
Example #15
0
	def __init__(self, logger, verbosity):
		self.running = False
		self.verbosity = verbosity
		self.logger = logger

		self.config = Config(logger=self.logger)

		self.logger.info('Starting engine...')

		try:
			self.db = Database()
			self.db.connect()
		except DatabaseConnectionFailedException, e:
			self.logger.error('Could not establish connection with the database (%s).' \
					'Shutting down...' % e)
			self.shutdown(1)
			return
Example #16
0
def _get_config():
    datadir = os.path.join(project_data_dir(), 'engine')
    conf = {
        'eggs_dir': os.path.join(datadir, 'eggs'),
        'logs_dir': os.path.join(datadir, 'logs'),
        'items_dir': os.path.join(datadir, 'items'),
        'dbs_dir': os.path.join(datadir, 'dbs'),
    }
    for k in ['eggs_dir', 'logs_dir', 'items_dir', 'dbs_dir']:  # create dirs
        d = conf[k]
        if not os.path.exists(d):
            os.makedirs(d)
    engine_conf = """
                    [engine]
                    eggs_dir = %(eggs_dir)s
                    logs_dir = %(logs_dir)s
                    items_dir = %(items_dir)s
                    dbs_dir  = %(dbs_dir)s
                    """ % conf
    return Config(extra_sources=[StringIO(engine_conf)])
Example #17
0
def test():
    config = Config()
    with open('chess/engine/games.csv', newline='') as games:
        reader = csv.DictReader(games)
        nb = 0
        for row in reader:
            nb += 1
            moves = row['moves'].split()
            i = 0
            over = None
            if row['victory_status'] == 'mate' and nb > 0:
                while over == None:
                    start, dest, prom_not_queen = ask_test(moves[i])
                    # auto promotion in queen so others are not handled
                    if prom_not_queen:
                        over = 0
                    elif config.try_play(start,dest):
                        # show(config)
                        over,_ = config.winner()
                    else:
                        sys.exit("fail at move :  " + moves[i])
                    i += 1
                config.reset()
Example #18
0
def test_populate_blanks_from_master(mock_config, blank_template, datamap,
                                     master):
    Config.initialise()
    write_master_to_templates(blank_template, datamap, master)
Example #19
0
import poplib
import socket

from subprocess import Popen, PIPE

from engine.config import Config


config = Config()
password = config.get('email', 'password')

handle_mail="/var/www/mailcheck/engine/handle_mail.py"
handle_mail_args="-ihotmail"
output=""

M = None
try:
  M=poplib.POP3_SSL("pop3.live.com", "995")
except socket.error:
  sys.exit(1)
except socket.timeout:
  sys.exit(1)
M.user("*****@*****.**")
M.pass_(password)

numMessages = len(M.list()[1])
for i in range(numMessages):
  p=Popen([handle_mail, handle_mail_args], stdin=PIPE, close_fds=True)
  for j in M.retr(i+1)[1]:
    output += j+"\n"
  p.stdin.write(output);
Example #20
0
        elif opt == '--help' or opt == '-h':
            usage()
        else:
            exit()

import re
import socket
import smtplib
from subprocess import Popen, PIPE
from os import waitpid
import time
import dkim
from engine.database import *
from engine.config import Config

config = Config()
mailcheck_subject = ".*This is mailcheck.*"

try:
    db = Database()
    db.connect()
except DatabaseConnectionFailedException, e:
    print 'Could not establish connection with the database. Shutting down...'
    exit()

db_ip = "127.0.0.1"
dir = "/var/www/cache/"
file = str(time.time())
output = ""
extra_tests = []
Example #21
0
def test_create_master_in_memory():
    Config.initialise()
    import_and_create_master()
Example #22
0
 def setUp(self):
     d = self.mktemp()
     config = Config(values={'eggs_dir': d})
     self.eggst = FilesystemEggStorage(config)