Example #1
0
    def __init__(self):
        default_config_path = path.preauthChild(
            os.path.join('config', 'config.json.default'))
        self.config_path = path.preauthChild(
            os.path.join('config', 'config.json'))
        if default_config_path.exists():
            try:
                with default_config_path.open() as default_config:
                    default = json.load(default_config)
            except ValueError as e:
                print 'Error: %s' % e
                self.logger.critical(
                    'The configuration defaults file (config.json.default) '
                    'contains invalid JSON. Please run it against a JSON '
                    'linter, such as http://jsonlint.com. Shutting down.')
                sys.exit()
        else:
            self.logger.critical(
                'The configuration defaults file (config.json.default)'
                ' doesn\'t exist! Shutting down.')
            sys.exit()

        if self.config_path.exists():
            try:
                with self.config_path.open() as c:
                    config = json.load(c)
                    self.config = recursive_dictionary_update(default, config)
            except ValueError as e:
                print 'Error: %s' % e
                self.logger.critical(
                    'The configuration file (config.json) contains invalid '
                    'JSON. Please run it against a JSON linter, such as '
                    'http://jsonlint.com. Shutting down.')
                sys.exit()
        else:
            self.logger.warning('The configuration file (config.json)'
                                ' doesn\'t exist! Creating one from defaults.')
            try:
                with self.config_path.open('w') as f:
                    json.dump(default,
                              f,
                              indent=4,
                              separators=(',', ': '),
                              sort_keys=True,
                              ensure_ascii=False)
            except IOError:
                self.logger.critical(
                    'Couldn\'t write a default configuration file. '
                    'Please check that StarryPy has write access in the '
                    'config/ directory.')
                self.logger.critical('Exiting...')
                sys.exit()
            self.logger.warning(
                'StarryPy will now exit. Please examine config.json '
                'and adjust the variables appropriately.')
            sys.exit()

        self.logger.debug('Created configuration manager.')
        self.save()
Example #2
0
    def __init__(self):
        default_config_path = path.preauthChild("config/config.json.default")
        self.config_path = path.preauthChild("config/config.json")
        if default_config_path.exists():
            try:
                with default_config_path.open() as default_config:
                    default = json.load(default_config)
            except ValueError:
                self.logger.critical(
                    "The configuration defaults file (config.json.default) contains invalid JSON. Please run it against a JSON linter, such as http://jsonlint.com. Shutting down."
                )
                sys.exit()
        else:
            self.logger.critical(
                "The configuration defaults file (config.json.default) doesn't exist! Shutting down."
            )
            sys.exit()

        if self.config_path.exists():
            try:
                with self.config_path.open() as c:
                    config = json.load(c)
                    self.config = recursive_dictionary_update(default, config)
            except ValueError:
                self.logger.critical(
                    "The configuration file (config.json) contains invalid JSON. Please run it against a JSON linter, such as http://jsonlint.com. Shutting down."
                )
                sys.exit()
        else:
            self.logger.warning(
                "The configuration file (config.json) doesn't exist! Creating one from defaults."
            )
            try:
                with self.config_path.open("w") as f:
                    json.dump(default,
                              f,
                              indent=4,
                              separators=(',', ': '),
                              sort_keys=True,
                              ensure_ascii=False)
            except IOError:
                self.logger.critical(
                    "Couldn't write a default configuration file. Please check that StarryPy has write access in the config/ directory."
                )
                self.logger.critical("Exiting...")
                sys.exit()
            self.logger.warning(
                "StarryPy will now exit. Please examine config.json and adjust the variables appropriately."
            )
            sys.exit()

        self.logger.debug("Created configuration manager.")
        self.save()
Example #3
0
 def __init__(self, config):
     self.config = config
     self.engine = create_engine('sqlite:///%s' % path.preauthChild(self.config.player_db).path)
     Base.metadata.create_all(self.engine)
     self.sessionmaker = sessionmaker(bind=self.engine, autoflush=True)
     with _autoclosing_session(self.sessionmaker) as session:
         for player in session.query(Player).all():
             player.logged_in = False
             player.protocol = None
             session.commit()
Example #4
0
 def __init__(self, config):
     self.config = config
     self.engine = create_engine(
         'sqlite:///%s' % path.preauthChild(self.config.player_db).path)
     Base.metadata.create_all(self.engine)
     self.sessionmaker = sessionmaker(bind=self.engine, autoflush=True)
     with _autoclosing_session(self.sessionmaker) as session:
         for player in session.query(Player).all():
             player.logged_in = False
             player.protocol = None
             session.commit()
Example #5
0
def migrate_db(config):
    dbcon = sqlite3.connect(path.preauthChild(config.player_db).path)
    dbcur = dbcon.cursor()

    try:
        dbcur.execute('SELECT org_name FROM players;')
    except sqlite3.OperationalError, e:
        if "column" in str(e):
            dbcur.execute('ALTER TABLE `players` ADD COLUMN `org_name`;')
            dbcur.execute('UPDATE `players` SET `org_name`=`name`;')
            dbcon.commit()
Example #6
0
def migrate_db(config):
    dbcon = sqlite3.connect(path.preauthChild(config.player_db).path)
    dbcur = dbcon.cursor()

    res = dbcur.execute("PRAGMA user_version;")
    db_version = res.fetchone()[0]
    try:
        if db_version is 0:
            dbcur.execute('DROP TABLE `ips`;')
            dbcur.execute("PRAGMA user_version = 1;")
            logger.info("Migrating DB from version 0 to version 1.")
    except sqlite3.OperationalError, e:
        logger.info("No DB exists. Will create a new one.")
Example #7
0
def migrate_db(config):
    dbcon = sqlite3.connect(path.preauthChild(config.player_db).path)
    dbcur = dbcon.cursor()

    res = dbcur.execute('PRAGMA user_version;')
    db_version = res.fetchone()[0]
    try:
        if db_version is 0:
            dbcur.execute('DROP TABLE `ips`;')
            dbcur.execute('PRAGMA user_version = 1;')
            logger.info('Migrating DB from version 0 to version 1.')
    except sqlite3.OperationalError, e:
        logger.info('No DB exists. Will create a new one.')
Example #8
0
    def __init__(self):
        default_config_path = path.preauthChild("config/config.json.default")
        self.config_path = path.preauthChild("config/config.json")
        if default_config_path.exists():
            try:
                with default_config_path.open() as default_config:
                    default = json.load(default_config)
            except ValueError as e:
                print "Error: %s" % e
                self.logger.critical("The configuration defaults file (config.json.default) contains invalid JSON. Please run it against a JSON linter, such as http://jsonlint.com. Shutting down." )
                sys.exit()
        else:
            self.logger.critical("The configuration defaults file (config.json.default) doesn't exist! Shutting down.")
            sys.exit()

        if self.config_path.exists():
            try:
                with self.config_path.open() as c:
                    config = json.load(c)
                    self.config = recursive_dictionary_update(default, config)
            except ValueError as e:
                print "Error: %s" % e
                self.logger.critical("The configuration file (config.json) contains invalid JSON. Please run it against a JSON linter, such as http://jsonlint.com. Shutting down.")
                sys.exit()
        else:
            self.logger.warning("The configuration file (config.json) doesn't exist! Creating one from defaults.")
            try:
                with self.config_path.open("w") as f:
                    json.dump(default, f, indent=4, separators=(',', ': '), sort_keys=True, ensure_ascii = False)
            except IOError:
                self.logger.critical("Couldn't write a default configuration file. Please check that StarryPy has write access in the config/ directory.")
                self.logger.critical("Exiting...")
                sys.exit()
            self.logger.warning("StarryPy will now exit. Please examine config.json and adjust the variables appropriately.")
            sys.exit()

        self.logger.debug("Created configuration manager.")
        self.save()
Example #9
0
 def __init__(self, config):
     self.config = config
     logger.info("Loading player database.")
     try:
         self.engine = create_engine('sqlite:///%s' % path.preauthChild(self.config.player_db).path)
     except exc.SQLAlchemyError as e:
         logger.warning("SQL Errror: %s", e)
     Base.metadata.create_all(self.engine)
     self.sessionmaker = sessionmaker(bind=self.engine, autoflush=True)
     with _autoclosing_session(self.sessionmaker) as session:
         for player in session.query(Player).filter_by(logged_in=True).all():
             player.logged_in = False
             player.admin_logged_in = False
             player.protocol = None
             session.commit()
Example #10
0
 def __init__(self, config):
     self.config = config
     migrate_db(self.config)
     logger.info('Loading player database.')
     try:
         self.engine = create_engine('sqlite:///{}'.format(
             path.preauthChild(self.config.player_db).path))
     except exc.SQLAlchemyError as e:
         logger.warning('SQL Errror: %s', e)
     Base.metadata.create_all(self.engine)
     self.sessionmaker = sessionmaker(bind=self.engine, autoflush=True)
     with _autoclosing_session(self.sessionmaker) as session:
         query = session.query(Player).filter_by(logged_in=True).all()
         for player in query:
             player.logged_in = False
             player.admin_logged_in = False
             player.party_id = ''
             player.protocol = None
             session.commit()
Example #11
0
 def __init__(self, config):
     self.config = config
     migrate_db(self.config)
     logger.info('Loading player database.')
     try:
         self.engine = create_engine(
             'sqlite:///{}'.format(
                 path.preauthChild(self.config.player_db).path
             )
         )
     except exc.SQLAlchemyError as e:
         logger.warning('SQL Errror: %s', e)
     Base.metadata.create_all(self.engine)
     self.sessionmaker = sessionmaker(bind=self.engine, autoflush=True)
     with _autoclosing_session(self.sessionmaker) as session:
         query = session.query(Player).filter_by(logged_in=True).all()
         for player in query:
             player.logged_in = False
             player.admin_logged_in = False
             player.party_id = ''
             player.protocol = None
             session.commit()