<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
#  Copyright 2019 The FATE Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

from fate_flow.entity.metric import Metric
from fate_flow.entity.metric import MetricMeta
from federatedml.model_base import ModelBase
from federatedml.model_selection import start_cross_validation
from federatedml.model_selection.stepwise import start_stepwise
from federatedml.optim.convergence import converge_func_factory
from federatedml.optim.initialize import Initializer
from federatedml.optim.optimizer import optimizer_factory
from federatedml.statistic import data_overview
from federatedml.util import abnormal_detection
from federatedml.util.validation_strategy import ValidationStrategy

class BaseLinearModel(ModelBase):
    def __init__(self):
        super(BaseLinearModel, self).__init__()
        # attribute:
        self.n_iter_ = 0
        self.classes_ = None
        self.feature_shape = None
        self.gradient_operator = None
        self.initializer = Initializer()
        self.transfer_variable = None
        self.loss_history = []
        self.is_converged = False
        self.header = None
        self.model_name = 'toSet'
        self.model_param_name = 'toSet'
        self.model_meta_name = 'toSet'
        self.role = ''
        self.mode = ''
        self.schema = {}
        self.cipher_operator = None
        self.model_weights = None
        self.validation_freqs = None
        self.need_one_vs_rest = False
        self.in_one_vs_rest = False
        self.init_param_obj = None

    def _init_model(self, params):
        self.model_param = params
        self.alpha = params.alpha
        self.init_param_obj = params.init_param
        # self.fit_intercept = self.init_param_obj.fit_intercept
        self.batch_size = params.batch_size
        self.max_iter = params.max_iter
        self.optimizer = optimizer_factory(params)
        self.converge_func = converge_func_factory(params.early_stop, params.tol)
        self.encrypted_calculator = None
        self.validation_freqs = params.validation_freqs

    def get_features_shape(self, data_instances):
        if self.feature_shape is not None:
            return self.feature_shape
        return data_overview.get_features_shape(data_instances)

    def set_header(self, header):
        self.header = header

    def get_header(self, data_instances):
        if self.header is not None:
            return self.header
        return data_instances.schema.get("header")

    @property
    def fit_intercept(self):
        return self.init_param_obj.fit_intercept

    def _get_meta(self):
        raise NotImplementedError("This method should be be called here")

    def _get_param(self):
        raise NotImplementedError("This method should be be called here")

    def export_model(self):
        meta_obj = self._get_meta()
        param_obj = self._get_param()
        result = {
            self.model_meta_name: meta_obj,
            self.model_param_name: param_obj
        }
        return result

    def callback_loss(self, iter_num, loss):
        metric_meta = MetricMeta(name='train',
                                 metric_type="LOSS",
                                 extra_metas={
                                     "unit_name": "iters",
                                 })

        self.callback_meta(metric_name='loss', metric_namespace='train', metric_meta=metric_meta)
        self.callback_metric(metric_name='loss',
                             metric_namespace='train',
                             metric_data=[Metric(iter_num, loss)])

    def _abnormal_detection(self, data_instances):
        """
        Make sure input data_instances is valid.
        """
        abnormal_detection.empty_table_detection(data_instances)
        abnormal_detection.empty_feature_detection(data_instances)

    def init_validation_strategy(self, train_data=None, validate_data=None):
        validation_strategy = ValidationStrategy(self.role, self.mode, self.validation_freqs)
        validation_strategy.set_train_data(train_data)
        validation_strategy.set_validate_data(validate_data)
        return validation_strategy

    def cross_validation(self, data_instances):
        return start_cross_validation.run(self, data_instances)

    def stepwise(self, data_instances):
        self.disable_callback_loss()
        return start_stepwise.run(self, data_instances)

    def _get_cv_param(self):
        self.model_param.cv_param.role = self.role
        self.model_param.cv_param.mode = self.mode
        return self.model_param.cv_param

    def _get_stepwise_param(self):
        self.model_param.stepwise_param.role = self.role
        self.model_param.stepwise_param.mode = self.mode
        return self.model_param.stepwise_param

    def set_schema(self, data_instance, header=None):
        if header is None:
            self.schema["header"] = self.header
        else:
            self.schema["header"] = header
        data_instance.schema = self.schema
        return data_instance

    def init_schema(self, data_instance):
        if data_instance is None:
            return
        self.schema = data_instance.schema
        self.header = self.schema.get('header')
<commit_msg>add disable callback loss<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
#  Copyright 2019 The FATE Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

from fate_flow.entity.metric import Metric
from fate_flow.entity.metric import MetricMeta
from federatedml.model_base import ModelBase
from federatedml.model_selection import start_cross_validation
from federatedml.model_selection.stepwise import start_stepwise
from federatedml.optim.convergence import converge_func_factory
from federatedml.optim.initialize import Initializer
from federatedml.optim.optimizer import optimizer_factory
from federatedml.statistic import data_overview
from federatedml.util import abnormal_detection
from federatedml.util.validation_strategy import ValidationStrategy

class BaseLinearModel(ModelBase):
    def __init__(self):
        super(BaseLinearModel, self).__init__()
        # attribute:
        self.n_iter_ = 0
        self.classes_ = None
        self.feature_shape = None
        self.gradient_operator = None
        self.initializer = Initializer()
        self.transfer_variable = None
        self.loss_history = []
        self.is_converged = False
        self.header = None
        self.model_name = 'toSet'
        self.model_param_name = 'toSet'
        self.model_meta_name = 'toSet'
        self.role = ''
        self.mode = ''
        self.schema = {}
        self.cipher_operator = None
        self.model_weights = None
        self.validation_freqs = None
        self.need_one_vs_rest = False
        self.in_one_vs_rest = False
        self.init_param_obj = None

    def _init_model(self, params):
        self.model_param = params
        self.alpha = params.alpha
        self.init_param_obj = params.init_param
        # self.fit_intercept = self.init_param_obj.fit_intercept
        self.batch_size = params.batch_size
        self.max_iter = params.max_iter
        self.optimizer = optimizer_factory(params)
        self.converge_func = converge_func_factory(params.early_stop, params.tol)
        self.encrypted_calculator = None
        self.validation_freqs = params.validation_freqs

    def get_features_shape(self, data_instances):
        if self.feature_shape is not None:
            return self.feature_shape
        return data_overview.get_features_shape(data_instances)

    def set_header(self, header):
        self.header = header

    def get_header(self, data_instances):
        if self.header is not None:
            return self.header
        return data_instances.schema.get("header")

    @property
    def fit_intercept(self):
        return self.init_param_obj.fit_intercept

    def _get_meta(self):
        raise NotImplementedError("This method should be be called here")

    def _get_param(self):
        raise NotImplementedError("This method should be be called here")

    def export_model(self):
        meta_obj = self._get_meta()
        param_obj = self._get_param()
        result = {
            self.model_meta_name: meta_obj,
            self.model_param_name: param_obj
        }
        return result

    def disable_callback_loss(self):
        self.need_call_back_loss = False

    def enable_callback_loss(self):
        self.need_call_back_loss = True

    def callback_loss(self, iter_num, loss):
        metric_meta = MetricMeta(name='train',
                                 metric_type="LOSS",
                                 extra_metas={
                                     "unit_name": "iters",
                                 })

        self.callback_meta(metric_name='loss', metric_namespace='train', metric_meta=metric_meta)
        self.callback_metric(metric_name='loss',
                             metric_namespace='train',
                             metric_data=[Metric(iter_num, loss)])

    def _abnormal_detection(self, data_instances):
        """
        Make sure input data_instances is valid.
        """
        abnormal_detection.empty_table_detection(data_instances)
        abnormal_detection.empty_feature_detection(data_instances)

    def init_validation_strategy(self, train_data=None, validate_data=None):
        validation_strategy = ValidationStrategy(self.role, self.mode, self.validation_freqs)
        validation_strategy.set_train_data(train_data)
        validation_strategy.set_validate_data(validate_data)
        return validation_strategy

    def cross_validation(self, data_instances):
        return start_cross_validation.run(self, data_instances)

    def stepwise(self, data_instances):
        self.disable_callback_loss()
        return start_stepwise.run(self, data_instances)

    def _get_cv_param(self):
        self.model_param.cv_param.role = self.role
        self.model_param.cv_param.mode = self.mode
        return self.model_param.cv_param

    def _get_stepwise_param(self):
        self.model_param.stepwise_param.role = self.role
        self.model_param.stepwise_param.mode = self.mode
        return self.model_param.stepwise_param

    def set_schema(self, data_instance, header=None):
        if header is None:
            self.schema["header"] = self.header
        else:
            self.schema["header"] = header
        data_instance.schema = self.schema
        return data_instance

    def init_schema(self, data_instance):
        if data_instance is None:
            return
        self.schema = data_instance.schema
        self.header = self.schema.get('header')
<|endoftext|>


<commit_before>import dj_database_url

from feelings.settings import *

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = [
    'localhost',
    '127.0.0.1',
    '.herokuapp.com',
]

INSTALLED_APPS += (
    'gunicorn',
)

db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

SECRET_KEY = get_env_variable("SECRET_KEY")

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'<commit_msg>get_env_variable function<commit_after>import dj_database_url

from feelings.settings import *

def get_env_variable(var_name):
    try:
        return os.environ[var_name]
    except KeyError:
        error_msg = "Set the {} env variable".format(var_name)
        if DEBUG:
            warnings.war(error_msg)
        else:
            raise ImproperlyConfigured(error_msg)

DEBUG = False
TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = [
    'localhost',
    '127.0.0.1',
    '.herokuapp.com',
]

INSTALLED_APPS += (
    'gunicorn',
)

db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)

SECRET_KEY = get_env_variable("SECRET_KEY")

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'<|endoftext|>


<commit_before>from flask import Flask, render_template
from xml.etree import ElementTree
import requests

FTB_URL_PREFIX = 'http://ftb.cursecdn.com/FTB2/'
STATIC_URL_PREFIX = FTB_URL_PREFIX + 'static/'
MODPACK_URL_PREFIX = FTB_URL_PREFIX + 'modpacks/'
MODPACKS_XML_URL = STATIC_URL_PREFIX + 'modpacks.xml'
THIRDPARTY_XML_URL = STATIC_URL_PREFIX + 'thirdparty.xml'

app = Flask(__name__)

def get_modpacks_from_url(xml_url):
    r = requests.get(xml_url)
    modpacks_xml = ElementTree.fromstring(r.text)
    modpacks_list = []
    for modpack in modpacks_xml:
        attrib = modpack.attrib
        if attrib.get('repoVersion'):
            modpacks_list.append(attrib)
    return render_template('modpacks.html', modpacks_list=modpacks_list, static_url_prefix=STATIC_URL_PREFIX,
                           modpack_url_prefix=MODPACK_URL_PREFIX)

@app.route('/')
def homepage():
    return 'Hello Minecraft Player!'

@app.route('/modpacks')
def modpacks():
    return get_modpacks_from_url(MODPACKS_XML_URL)

@app.route('/thirdparty')
def thirdparty():
    return get_modpacks_from_url(THIRDPARTY_XML_URL)

@app.route('/packcode/<code>')
def packcode(code):
    return get_modpacks_from_url(STATIC_URL_PREFIX + code + '.xml')

if __name__ == '__main__':
    app.run(debug=True,
            host='0.0.0.0',
            port=8090)
<commit_msg>cache and deploy via proxy<commit_after>import requests_cache
from flask import Flask, render_template
from xml.etree import ElementTree
import requests

FTB_URL_PREFIX = 'http://ftb.cursecdn.com/FTB2/'
STATIC_URL_PREFIX = FTB_URL_PREFIX + 'static/'
MODPACK_URL_PREFIX = FTB_URL_PREFIX + 'modpacks/'
MODPACKS_XML_URL = STATIC_URL_PREFIX + 'modpacks.xml'
THIRDPARTY_XML_URL = STATIC_URL_PREFIX + 'thirdparty.xml'

app = Flask(__name__)
requests_cache.install_cache(backend='memory', expire_after=300)

def get_modpacks_from_url(xml_url):
    r = requests.get(xml_url)
    modpacks_xml = ElementTree.fromstring(r.text)
    modpacks_list = []
    for modpack in modpacks_xml:
        attrib = modpack.attrib
        if attrib.get('repoVersion'):
            modpacks_list.append(attrib)
    return render_template('modpacks.html', modpacks_list=modpacks_list, static_url_prefix=STATIC_URL_PREFIX,
                           modpack_url_prefix=MODPACK_URL_PREFIX)

@app.route('/')
def homepage():
    return 'Hello Minecraft Player!'

@app.route('/modpacks')
def modpacks():
    return get_modpacks_from_url(MODPACKS_XML_URL)

@app.route('/thirdparty')
def thirdparty():
    return get_modpacks_from_url(THIRDPARTY_XML_URL)

@app.route('/packcode/<code>')
def packcode(code):
    return get_modpacks_from_url(STATIC_URL_PREFIX + code + '.xml')

if __name__ == '__main__':
    app.run(
        # debug=True,
        # host='0.0.0.0',
        port=8090)
<|endoftext|>


<commit_before>from imports.protein_data import active_driver_gene_lists as load_active_driver_gene_lists, ListData
from database_testing import DatabaseTest
from miscellaneous import make_named_temp_file
from database import db
from models import TCGAMutation

# merged:
# head ActiveDriver1_result_pvalue_less_0.01_CancerMutation-2017-02-16.txt -n 4
# head ActiveDriver1_result_pvalue_less_0.01_CancerMutation-2017-02-16.txt -n 500 | tail

raw_gene_list = """\
gene	p	fdr
CTNNB1	7.29868558025906e-65	8.70368255445893e-61
IDH1	5.94998080805889e-63	3.54767605680511e-59
PTEN	1.82282073049743e-51	7.2457124037273e-48
HSPA4	0.000408236641023006	0.00991696688939805
SHC1	0.000408768573301514	0.00991696688939805
TERF2	0.000409152847763844	0.00991696688939805
XPO1	0.000412399692346554	0.00995819609074201
PNPT1	0.000412524014157363	0.00995819609074201
TMEM131	0.000424693241746104	0.0102312462784289
KRT75	0.000429521905278659	0.0103267111299355
ALDH2	0.000431112122924959	0.0103440886637427
ADGRL1	0.000433144270973498	0.0103710604881763
LRMP	0.000433975612880499	0.0103710604881763\
"""

class TestImport(DatabaseTest):

    def test_gene_lists(self):

        filename = make_named_temp_file(raw_gene_list)

        with self.app.app_context():
            gene_lists = load_active_driver_gene_lists(lists=(
                ListData(
                    name='TCGA list', path=filename, mutations_source=TCGAMutation,
                    site_type_name='all'
                ),
            ))

        # one gene list returned (TCGA)
        assert len(gene_lists) == 1

        gene_list = gene_lists[0]

        # correct name of gene list
        assert gene_list.name == 'TCGA list'

        assert gene_list.mutation_source_name == 'TCGA'

        # let's take some entry
        an_entry = gene_list.entries[0]

        assert type(an_entry.p) is float
        assert type(an_entry.fdr) is float

        genes = [entry.gene.name for entry in gene_list.entries]

        assert 'TMEM131' not in genes
        assert 'PNPT1' in genes

        db.session.add_all(gene_lists)

        with self.app.app_context():
            gene_lists = load_active_driver_gene_lists(lists=(
                ListData(
                    name='TCGA list', path=filename, mutations_source=TCGAMutation,
                    site_type_name='all'
                ),
            ))

        # no duplicate lists should be created
        assert not gene_lists
<commit_msg>Restore FDR cutoff to gene lists test<commit_after>from imports.protein_data import active_driver_gene_lists as load_active_driver_gene_lists, ListData
from database_testing import DatabaseTest
from miscellaneous import make_named_temp_file
from database import db
from models import TCGAMutation

# merged:
# head ActiveDriver1_result_pvalue_less_0.01_CancerMutation-2017-02-16.txt -n 4
# head ActiveDriver1_result_pvalue_less_0.01_CancerMutation-2017-02-16.txt -n 500 | tail

raw_gene_list = """\
gene	p	fdr
CTNNB1	7.29868558025906e-65	8.70368255445893e-61
IDH1	5.94998080805889e-63	3.54767605680511e-59
PTEN	1.82282073049743e-51	7.2457124037273e-48
HSPA4	0.000408236641023006	0.00991696688939805
SHC1	0.000408768573301514	0.00991696688939805
TERF2	0.000409152847763844	0.00991696688939805
XPO1	0.000412399692346554	0.00995819609074201
PNPT1	0.000412524014157363	0.00995819609074201
TMEM131	0.000424693241746104	0.0102312462784289
KRT75	0.000429521905278659	0.0103267111299355
ALDH2	0.000431112122924959	0.0103440886637427
ADGRL1	0.000433144270973498	0.0103710604881763
LRMP	0.000433975612880499	0.0103710604881763\
"""

class TestImport(DatabaseTest):

    def test_gene_lists(self):

        filename = make_named_temp_file(raw_gene_list)

        with self.app.app_context():
            gene_lists = load_active_driver_gene_lists(
                lists=(
                    ListData(
                        name='TCGA list', path=filename, mutations_source=TCGAMutation,
                        site_type_name='all'
                    ),
                ),
                fdr_cutoff=0.01
            )

        # one gene list returned (TCGA)
        assert len(gene_lists) == 1

        gene_list = gene_lists[0]

        # correct name of gene list
        assert gene_list.name == 'TCGA list'

        assert gene_list.mutation_source_name == 'TCGA'

        # let's take some entry
        an_entry = gene_list.entries[0]

        assert type(an_entry.p) is float
        assert type(an_entry.fdr) is float

        genes = [entry.gene.name for entry in gene_list.entries]

        assert 'TMEM131' not in genes
        assert 'PNPT1' in genes

        db.session.add_all(gene_lists)

        with self.app.app_context():
            gene_lists = load_active_driver_gene_lists(lists=(
                ListData(
                    name='TCGA list', path=filename, mutations_source=TCGAMutation,
                    site_type_name='all'
                ),
            ))

        # no duplicate lists should be created
        assert not gene_lists
<|endoftext|>


<commit_before>#!/usr/bin/env python
# encoding: utf-8
# Ali Sabil, 2007
# Radosław Szkodziński, 2010

"""
At this point, vala is still unstable, so do not expect
this tool to be too stable either (apis, etc)
"""

import re
from waflib import Context, Task, Utils, Logs, Options, Errors, Node
from waflib.TaskGen import extension, taskgen_method
from waflib.Configure import conf

class valac(Task.Task):
	"""
	Task to compile vala files.
	"""
	#run_str = "${VALAC} ${VALAFLAGS}" # ideally
	#vars = ['VALAC_VERSION']
	vars = ["VALAC", "VALAC_VERSION", "VALAFLAGS"]
	ext_out = ['.h']

	def run(self):
		cmd = self.env.VALAC + self.env.VALAFLAGS
		resources = getattr(self, 'vala_exclude', [])
		cmd.extend([a.abspath() for a in self.inputs if a not in resources])
		ret = self.exec_command(cmd, cwd=self.vala_dir_node.abspath())

		if ret:
			return ret

		if self.generator.dump_deps_node:
			self.generator.dump_deps_node.write('\n'.join(self.generator.packages))

		return ret

valac = Task.update_outputs(valac) # no decorators for python2 classes

@taskgen_method
def init_vala_task(self):
	"""
	Initializes the vala task with the relevant data (acts as a constructor)
	"""
	self.profile = getattr(self, 'profile', 'gobject')

	if self.profile == 'gobject':
		self.uselib = Utils.to_list(getattr(self, 'uselib', []))
		if not 'GOBJECT' in self.uselib:
			self.uselib.append('GOBJECT')

	def addflags(flags):
		self.env.append_value('VALAFLAGS', flags)

	if self.profile:
		addflags('--profile=%s' % self.profile)

	valatask = self.valatask

	# output directory
	if hasattr(self, 'vala_dir'):
		if isinstance(self.vala_dir, str):
			valatask.vala_dir_node = self.path.get_bld().make_node(self.vala_dir)
			try:
				valatask.vala_dir_node.mkdir()
			except OSError:
				raise self.bld.fatal('Cannot create the vala dir %r' % valatask.vala_dir_node)
		else:
			valatask.vala_dir_node = self.vala_dir
	else:
		valatask.vala_dir_node = self.path.get_bld()
	addflags('--directory=%s' % valatask.vala_dir_node.abspath())

	if hasattr(self, 'thread'):
		if self.profile == 'gobject':
			if not 'GTHREAD' in self.uselib:
				self.uselib.append('GTHREAD')
		else:
			#Vala doesn't have threading support for dova nor posix
			Logs.warn("Profile %s means no threading support" % self.profile)
			self.thread = False

		if self.thread:
			addflags('--thread')

	self.is_lib = 'cprogram' not in self.features
	if self.is_lib:
		addflags('--library=%s' % self.target)

		h_node = valatask.vala_dir_node.find_or_declare('%s.h' % self.target)
		valatask.outputs.append(h_node)
		addflags('--header=%s' % h_node.name)

		valatask.outputs.append(valatask.vala_dir_node.find_or_declare('%s.vapi' % self.target))

		if getattr(self, 'gir', None):
			gir_node = valatask.vala_dir_node.find_or_declare('%s.gir' % self.gir)
			addflags('--gir=%s' % gir_node.name)
			valatask.outputs.append(gir_node)

	self.vala_target_glib = getattr(self, 'vala_target_glib', getattr(Options.options, 'vala_target_glib', None))
	if self.vala_target_glib:
		addflags('--target-glib=%s' % self.vala_target_glib)

	addflags(['--define=%s' % x for x in Utils.to_list(getattr(self, 'vala_defines', []))])

	packages_private = Utils.to_list(getattr(self, 'packages_private', []))
	addflags(['--pkg=%s' % x for x in packages_private])

	def _get_api_version():
		api_version = '1.0'
		if hasattr(Context.g_module, 'API_VERSION'):
			version = Context.g_module.API_VERSION.split(".")
			if version[0] == "0":
				api_version = "0." + version[1]
			else:
				api_version = version[0] + ".0"
		return api_version

	self.includes = Utils.to_list(getattr(self, 'includes', []))
	self.uselib = self.to_list(getattr(self, 'uselib', []))
	valatask.install_path = getattr(self, 'install_path', '')

	valatask.vapi_path = getattr(self, 'vapi_path', '${DATAROOTDIR}/vala/vapi')
	valatask.pkg_name = getattr(self, 'pkg_name', self.env['PACKAGE'])
	valatask.header_path = getattr(self, 'header_path', '${INCLUDEDIR}/%s-%s' % (valatask.pkg_name, _get_api_version()))
	valatask.install_binding = getattr(self, 'install_binding', True)

	self.packages = packages = Utils.to_list(getattr(self, 'packages', []))
	self.vapi_dirs = vapi_dirs = Utils.to_list(getattr(self, 'vapi_dirs', []))
	#includes =  []

	if hasattr(self, 'use'):
		local_packages = Utils.to_list(self.use)[:] # make sure to have a copy
		seen = []
		while len(local_packages) > 0:
			package = local_packages.pop()
			if package in seen:
				continue
			seen.append(package)

			# check if the package exists
			try:
				package_obj = self.bld.get_tgen_by_name(package)
			except Errors.WafError:
				continue
			package_name = package_obj.target
			for task in package_obj.tasks:
				for output in task.outputs:
					if output.name == package_name + ".vapi":
						valatask.set_run_after(task)
						if package_name not in packages:
							packages.append(package_name)
						if output.parent not in vapi_dirs:
							vapi_dirs.append(output.parent)
						if output.parent not in self.includes:
							self.includes.append(output.parent)

			if hasattr(package_obj, 'use'):
				lst = self.to_list(package_obj.use)
				lst.reverse()
				local_packages = [pkg for pkg in lst if pkg not in seen] + local_packages

	addflags(['--pkg=%s' % p for p in packages])

	for vapi_dir in vapi_dirs:
		if isinstance(vapi_dir, Node.Node):
			v_node = vapi_dir
		else:
			v_node = self.path.find_dir(vapi_dir)
		if not v_node:
			Logs.warn('Unable to locate Vala API directory: %r' % vapi_dir)
		else:
			addflags('--vapidir=%s' % v_node.abspath())

	self.dump_deps_node = None
	if self.is_lib and self.packages:
		self.dump_deps_node = valatask.vala_dir_node.find_or_declare('%s.deps' % self.target)
		valatask.outputs.append(self.dump_deps_node)

	if self.is_lib and valatask.install_binding:
		headers_list = [o for o in valatask.outputs if o.suffix() == ".h"]
		try:
			self.install_vheader.source = headers_list
		except AttributeError:
			self.install_vheader = self.bld.install_files(valatask.header_path, headers_list, self.env)

		vapi_list = [o for o in valatask.outputs if (o.suffix() in (".vapi", ".deps"))]
		try:
			self.install_vapi.source = vapi_list
		except AttributeError:
			self.install_vapi = self.bld.install_files(valatask.vapi_path, vapi_list, self.env)

		gir_list = [o for o in valatask.outputs if o.suffix() == '.gir']
		try:
			self.install_gir.source = gir_list
		except AttributeError:
			self.install_gir = self.bld.install_files(getattr(self, 'gir_path', '${DATAROOTDIR}/gir-1.0'), gir_list, self.env)

	if hasattr(self, 'vala_resources'):
		nodes = self.to_nodes(self.vala_resources)
		valatask.vala_exclude = getattr(valatask, 'vala_exclude', []) + nodes
		valatask.inputs.extend(nodes)
		for x in nodes:
			addflags(['--gresources', x.abspath()])

@extension('.vala', '.gs')
def vala_file(self, node):
	"""
	Compile a vala file and bind the task to *self.valatask*. If an existing vala task is already set, add the node
	to its inputs. The typical example is::

		def build(bld):
			bld.program(
				packages      = 'gtk+-2.0',
				target        = 'vala-gtk-example',
				uselib        = 'GTK GLIB',
				source        = 'vala-gtk-example.vala foo.vala',
				vala_defines  = ['DEBUG'] # adds --define=<xyz> values to the command-line

				# the following arguments are for libraries
				#gir          = 'hello-1.0',
				#gir_path     = '/tmp',
				#vapi_path = '/tmp',
				#pkg_name = 'hello'
				# disable installing of gir, vapi and header
				#install_binding = False

				# profile     = 'xyz' # adds --profile=<xyz> to enable profiling
				# thread      = True, # adds --thread, except if profile is on or not on 'gobject'
				# vala_target_glib = 'xyz' # adds --target-glib=<xyz>, can be given through the command-line option --vala-target-glib=<xyz>
			)

	:param node: vala file
	:type node: :py:class:`waflib.Node.Node`
	"""

	try:
		valatask = self.valatask
	except AttributeError:
		valatask = self.valatask = self.create_task('valac')
		self.init_vala_task()

	valatask.inputs.append(node)
	name = node.name[:node.name.rfind('.')] + '.c'
	c_node = valatask.vala_dir_node.find_or_declare(name)
	valatask.outputs.append(c_node)
	self.source.append(c_node)

@conf
def find_valac(self, valac_name, min_version):
	"""
	Find the valac program, and execute it to store the version
	number in *conf.env.VALAC_VERSION*

	:param valac_name: program name
	:type valac_name: string or list of string
	:param min_version: minimum version acceptable
	:type min_version: tuple of int
	"""
	valac = self.find_program(valac_name, var='VALAC')
	try:
		output = self.cmd_and_log(valac + ['--version'])
	except Exception:
		valac_version = None
	else:
		ver = re.search(r'\d+.\d+.\d+', output).group(0).split('.')
		valac_version = tuple([int(x) for x in ver])

	self.msg('Checking for %s version >= %r' % (valac_name, min_version),
	         valac_version, valac_version and valac_version >= min_version)
	if valac and valac_version < min_version:
		self.fatal("%s version %r is too old, need >= %r" % (valac_name, valac_version, min_version))

	self.env['VALAC_VERSION'] = valac_version
	return valac

@conf
def check_vala(self, min_version=(0,8,0), branch=None):
	"""
	Check if vala compiler from a given branch exists of at least a given
	version.

	:param min_version: minimum version acceptable (0.8.0)
	:type min_version: tuple
	:param branch: first part of the version number, in case a snapshot is used (0, 8)
	:type branch: tuple of int
	"""
	if self.env.VALA_MINVER:
		min_version = self.env.VALA_MINVER
	if self.env.VALA_MINVER_BRANCH:
		branch = self.env.VALA_MINVER_BRANCH
	if not branch:
		branch = min_version[:2]
	try:
		find_valac(self, 'valac-%d.%d' % (branch[0], branch[1]), min_version)
	except self.errors.ConfigurationError:
		find_valac(self, 'valac', min_version)

@conf
def check_vala_deps(self):
	"""
	Load the gobject and gthread packages if they are missing.
	"""
	if not self.env['HAVE_GOBJECT']:
		pkg_args = {'package':      'gobject-2.0',
		            'uselib_store': 'GOBJECT',
		            'args':         '--cflags --libs'}
		if getattr(Options.options, 'vala_target_glib', None):
			pkg_args['atleast_version'] = Options.options.vala_target_glib
		self.check_cfg(**pkg_args)

	if not self.env['HAVE_GTHREAD']:
		pkg_args = {'package':      'gthread-2.0',
		            'uselib_store': 'GTHREAD',
		            'args':         '--cflags --libs'}
		if getattr(Options.options, 'vala_target_glib', None):
			pkg_args['atleast_version'] = Options.options.vala_target_glib
		self.check_cfg(**pkg_args)

def configure(self):
	"""
	Use the following to enforce minimum vala version::

		def configure(conf):
			conf.env.VALA_MINVER = (0, 10, 0)
			conf.load('vala')
	"""
	self.load('gnu_dirs')
	self.check_vala_deps()
	self.check_vala()
	self.add_os_flags('VALAFLAGS')
	self.env.append_unique('VALAFLAGS', ['-C'])

def options(opt):
	"""
	Load the :py:mod:`waflib.Tools.gnu_dirs` tool and add the ``--vala-target-glib`` command-line option
	"""
	opt.load('gnu_dirs')
	valaopts = opt.add_option_group('Vala Compiler Options')
	valaopts.add_option('--vala-target-glib', default=None,
		dest='vala_target_glib', metavar='MAJOR.MINOR',
		help='Target version of glib for Vala GObject code generation')

<commit_msg>Issue 1632<commit_after>#!/usr/bin/env python
# encoding: utf-8
# Ali Sabil, 2007
# Radosław Szkodziński, 2010

"""
At this point, vala is still unstable, so do not expect
this tool to be too stable either (apis, etc)
"""

import re
from waflib import Context, Task, Utils, Logs, Options, Errors, Node
from waflib.TaskGen import extension, taskgen_method
from waflib.Configure import conf

class valac(Task.Task):
	"""
	Task to compile vala files.
	"""
	#run_str = "${VALAC} ${VALAFLAGS}" # ideally
	#vars = ['VALAC_VERSION']
	vars = ["VALAC", "VALAC_VERSION", "VALAFLAGS"]
	ext_out = ['.h']

	def run(self):
		cmd = self.env.VALAC + self.env.VALAFLAGS
		resources = getattr(self, 'vala_exclude', [])
		cmd.extend([a.abspath() for a in self.inputs if a not in resources])
		ret = self.exec_command(cmd, cwd=self.vala_dir_node.abspath())

		if ret:
			return ret

		if self.generator.dump_deps_node:
			self.generator.dump_deps_node.write('\n'.join(self.generator.packages))

		return ret

valac = Task.update_outputs(valac) # no decorators for python2 classes

@taskgen_method
def init_vala_task(self):
	"""
	Initializes the vala task with the relevant data (acts as a constructor)
	"""
	self.profile = getattr(self, 'profile', 'gobject')

	self.packages = packages = Utils.to_list(getattr(self, 'packages', []))
	self.use = Utils.to_list(getattr(self, 'use', []))
	if packages and not self.use:
		self.use = packages[:] # copy

	if self.profile == 'gobject':
		if not 'GOBJECT' in self.use:
			self.use.append('GOBJECT')

	def addflags(flags):
		self.env.append_value('VALAFLAGS', flags)

	if self.profile:
		addflags('--profile=%s' % self.profile)

	valatask = self.valatask

	# output directory
	if hasattr(self, 'vala_dir'):
		if isinstance(self.vala_dir, str):
			valatask.vala_dir_node = self.path.get_bld().make_node(self.vala_dir)
			try:
				valatask.vala_dir_node.mkdir()
			except OSError:
				raise self.bld.fatal('Cannot create the vala dir %r' % valatask.vala_dir_node)
		else:
			valatask.vala_dir_node = self.vala_dir
	else:
		valatask.vala_dir_node = self.path.get_bld()
	addflags('--directory=%s' % valatask.vala_dir_node.abspath())

	if hasattr(self, 'thread'):
		if self.profile == 'gobject':
			if not 'GTHREAD' in self.use:
				self.use.append('GTHREAD')
		else:
			#Vala doesn't have threading support for dova nor posix
			Logs.warn("Profile %s means no threading support" % self.profile)
			self.thread = False

		if self.thread:
			addflags('--thread')

	self.is_lib = 'cprogram' not in self.features
	if self.is_lib:
		addflags('--library=%s' % self.target)

		h_node = valatask.vala_dir_node.find_or_declare('%s.h' % self.target)
		valatask.outputs.append(h_node)
		addflags('--header=%s' % h_node.name)

		valatask.outputs.append(valatask.vala_dir_node.find_or_declare('%s.vapi' % self.target))

		if getattr(self, 'gir', None):
			gir_node = valatask.vala_dir_node.find_or_declare('%s.gir' % self.gir)
			addflags('--gir=%s' % gir_node.name)
			valatask.outputs.append(gir_node)

	self.vala_target_glib = getattr(self, 'vala_target_glib', getattr(Options.options, 'vala_target_glib', None))
	if self.vala_target_glib:
		addflags('--target-glib=%s' % self.vala_target_glib)

	addflags(['--define=%s' % x for x in Utils.to_list(getattr(self, 'vala_defines', []))])

	packages_private = Utils.to_list(getattr(self, 'packages_private', []))
	addflags(['--pkg=%s' % x for x in packages_private])

	def _get_api_version():
		api_version = '1.0'
		if hasattr(Context.g_module, 'API_VERSION'):
			version = Context.g_module.API_VERSION.split(".")
			if version[0] == "0":
				api_version = "0." + version[1]
			else:
				api_version = version[0] + ".0"
		return api_version

	self.includes = Utils.to_list(getattr(self, 'includes', []))
	valatask.install_path = getattr(self, 'install_path', '')

	valatask.vapi_path = getattr(self, 'vapi_path', '${DATAROOTDIR}/vala/vapi')
	valatask.pkg_name = getattr(self, 'pkg_name', self.env['PACKAGE'])
	valatask.header_path = getattr(self, 'header_path', '${INCLUDEDIR}/%s-%s' % (valatask.pkg_name, _get_api_version()))
	valatask.install_binding = getattr(self, 'install_binding', True)

	self.vapi_dirs = vapi_dirs = Utils.to_list(getattr(self, 'vapi_dirs', []))
	#includes =  []

	if hasattr(self, 'use'):
		local_packages = Utils.to_list(self.use)[:] # make sure to have a copy
		seen = []
		while len(local_packages) > 0:
			package = local_packages.pop()
			if package in seen:
				continue
			seen.append(package)

			# check if the package exists
			try:
				package_obj = self.bld.get_tgen_by_name(package)
			except Errors.WafError:
				continue
			package_name = package_obj.target
			for task in package_obj.tasks:
				for output in task.outputs:
					if output.name == package_name + ".vapi":
						valatask.set_run_after(task)
						if package_name not in packages:
							packages.append(package_name)
						if output.parent not in vapi_dirs:
							vapi_dirs.append(output.parent)
						if output.parent not in self.includes:
							self.includes.append(output.parent)

			if hasattr(package_obj, 'use'):
				lst = self.to_list(package_obj.use)
				lst.reverse()
				local_packages = [pkg for pkg in lst if pkg not in seen] + local_packages

	addflags(['--pkg=%s' % p for p in packages])

	for vapi_dir in vapi_dirs:
		if isinstance(vapi_dir, Node.Node):
			v_node = vapi_dir
		else:
			v_node = self.path.find_dir(vapi_dir)
		if not v_node:
			Logs.warn('Unable to locate Vala API directory: %r' % vapi_dir)
		else:
			addflags('--vapidir=%s' % v_node.abspath())

	self.dump_deps_node = None
	if self.is_lib and self.packages:
		self.dump_deps_node = valatask.vala_dir_node.find_or_declare('%s.deps' % self.target)
		valatask.outputs.append(self.dump_deps_node)

	if self.is_lib and valatask.install_binding:
		headers_list = [o for o in valatask.outputs if o.suffix() == ".h"]
		try:
			self.install_vheader.source = headers_list
		except AttributeError:
			self.install_vheader = self.bld.install_files(valatask.header_path, headers_list, self.env)

		vapi_list = [o for o in valatask.outputs if (o.suffix() in (".vapi", ".deps"))]
		try:
			self.install_vapi.source = vapi_list
		except AttributeError:
			self.install_vapi = self.bld.install_files(valatask.vapi_path, vapi_list, self.env)

		gir_list = [o for o in valatask.outputs if o.suffix() == '.gir']
		try:
			self.install_gir.source = gir_list
		except AttributeError:
			self.install_gir = self.bld.install_files(getattr(self, 'gir_path', '${DATAROOTDIR}/gir-1.0'), gir_list, self.env)

	if hasattr(self, 'vala_resources'):
		nodes = self.to_nodes(self.vala_resources)
		valatask.vala_exclude = getattr(valatask, 'vala_exclude', []) + nodes
		valatask.inputs.extend(nodes)
		for x in nodes:
			addflags(['--gresources', x.abspath()])

@extension('.vala', '.gs')
def vala_file(self, node):
	"""
	Compile a vala file and bind the task to *self.valatask*. If an existing vala task is already set, add the node
	to its inputs. The typical example is::

		def build(bld):
			bld.program(
				packages      = 'gtk+-2.0',
				target        = 'vala-gtk-example',
				use           = 'GTK GLIB',
				source        = 'vala-gtk-example.vala foo.vala',
				vala_defines  = ['DEBUG'] # adds --define=<xyz> values to the command-line

				# the following arguments are for libraries
				#gir          = 'hello-1.0',
				#gir_path     = '/tmp',
				#vapi_path = '/tmp',
				#pkg_name = 'hello'
				# disable installing of gir, vapi and header
				#install_binding = False

				# profile     = 'xyz' # adds --profile=<xyz> to enable profiling
				# thread      = True, # adds --thread, except if profile is on or not on 'gobject'
				# vala_target_glib = 'xyz' # adds --target-glib=<xyz>, can be given through the command-line option --vala-target-glib=<xyz>
			)

	:param node: vala file
	:type node: :py:class:`waflib.Node.Node`
	"""

	try:
		valatask = self.valatask
	except AttributeError:
		valatask = self.valatask = self.create_task('valac')
		self.init_vala_task()

	valatask.inputs.append(node)
	name = node.name[:node.name.rfind('.')] + '.c'
	c_node = valatask.vala_dir_node.find_or_declare(name)
	valatask.outputs.append(c_node)
	self.source.append(c_node)

@conf
def find_valac(self, valac_name, min_version):
	"""
	Find the valac program, and execute it to store the version
	number in *conf.env.VALAC_VERSION*

	:param valac_name: program name
	:type valac_name: string or list of string
	:param min_version: minimum version acceptable
	:type min_version: tuple of int
	"""
	valac = self.find_program(valac_name, var='VALAC')
	try:
		output = self.cmd_and_log(valac + ['--version'])
	except Exception:
		valac_version = None
	else:
		ver = re.search(r'\d+.\d+.\d+', output).group(0).split('.')
		valac_version = tuple([int(x) for x in ver])

	self.msg('Checking for %s version >= %r' % (valac_name, min_version),
	         valac_version, valac_version and valac_version >= min_version)
	if valac and valac_version < min_version:
		self.fatal("%s version %r is too old, need >= %r" % (valac_name, valac_version, min_version))

	self.env['VALAC_VERSION'] = valac_version
	return valac

@conf
def check_vala(self, min_version=(0,8,0), branch=None):
	"""
	Check if vala compiler from a given branch exists of at least a given
	version.

	:param min_version: minimum version acceptable (0.8.0)
	:type min_version: tuple
	:param branch: first part of the version number, in case a snapshot is used (0, 8)
	:type branch: tuple of int
	"""
	if self.env.VALA_MINVER:
		min_version = self.env.VALA_MINVER
	if self.env.VALA_MINVER_BRANCH:
		branch = self.env.VALA_MINVER_BRANCH
	if not branch:
		branch = min_version[:2]
	try:
		find_valac(self, 'valac-%d.%d' % (branch[0], branch[1]), min_version)
	except self.errors.ConfigurationError:
		find_valac(self, 'valac', min_version)

@conf
def check_vala_deps(self):
	"""
	Load the gobject and gthread packages if they are missing.
	"""
	if not self.env['HAVE_GOBJECT']:
		pkg_args = {'package':      'gobject-2.0',
		            'uselib_store': 'GOBJECT',
		            'args':         '--cflags --libs'}
		if getattr(Options.options, 'vala_target_glib', None):
			pkg_args['atleast_version'] = Options.options.vala_target_glib
		self.check_cfg(**pkg_args)

	if not self.env['HAVE_GTHREAD']:
		pkg_args = {'package':      'gthread-2.0',
		            'uselib_store': 'GTHREAD',
		            'args':         '--cflags --libs'}
		if getattr(Options.options, 'vala_target_glib', None):
			pkg_args['atleast_version'] = Options.options.vala_target_glib
		self.check_cfg(**pkg_args)

def configure(self):
	"""
	Use the following to enforce minimum vala version::

		def configure(conf):
			conf.env.VALA_MINVER = (0, 10, 0)
			conf.load('vala')
	"""
	self.load('gnu_dirs')
	self.check_vala_deps()
	self.check_vala()
	self.add_os_flags('VALAFLAGS')
	self.env.append_unique('VALAFLAGS', ['-C'])

def options(opt):
	"""
	Load the :py:mod:`waflib.Tools.gnu_dirs` tool and add the ``--vala-target-glib`` command-line option
	"""
	opt.load('gnu_dirs')
	valaopts = opt.add_option_group('Vala Compiler Options')
	valaopts.add_option('--vala-target-glib', default=None,
		dest='vala_target_glib', metavar='MAJOR.MINOR',
		help='Target version of glib for Vala GObject code generation')

<|endoftext|>


<commit_before>from typing import Optional, TYPE_CHECKING

from kivy.uix.effectwidget import EffectWidget
from kivy.uix.relativelayout import RelativeLayout

from mpfmc.uix.widget import Widget
from mpfmc.uix.display import DisplayOutput

if TYPE_CHECKING:
    from mpfmc.core.mc import MpfMc
    from mpfmc.uix.slide import Slide

class DisplayWidget(Widget, RelativeLayout):
    widget_type_name = 'Display'
    animation_properties = ('x', 'y')

    def __init__(self, mc: "MpfMc", config: dict, key: Optional[str]=None, **kwargs) -> None:
        del kwargs
        self.display = None

        super().__init__(mc=mc, config=config, key=key)

        self.display = self.mc.displays[self.config['source_display']]
        self.effects = EffectWidget(pos=self.pos, size_hint=(1, 1))

        if 'effects' in self.config:
            self._add_effects(self.config['effects'])

        # Establish link between display and this display widget
        self.add_widget(self.effects)
        self.display_output = DisplayOutput(self.effects, self.display)

    def __repr__(self) -> str:  # pragma: no cover
        try:
            return '<DisplayWidget size={}, pos={}, source={}>'.format(
                    self.size, self.pos, self.display.name)
        except AttributeError:
            return '<DisplayWidget size={}, source=(none)>'.format(
                    self.size)

    def on_pos(self, instance, pos):
        del instance
        self.effects.pos = pos

    def _add_effects(self, config: Optional[list]) -> None:
        """Adds any effects specified in the config for this display widget."""
        if config:
            effects_list = list()
            for effect_config in config:
                effect_config['width'] = self.width
                effect_config['height'] = self.height
                effects_list.extend(self.mc.effects_manager.get_effect(effect_config))

            self.effects.effects = effects_list

    @property
    def current_slide(self) -> Optional["Slide"]:
        """The current slide shown on the linked display."""
        if self.display:
            return self.display.current_slide
        else:
            return None

    @property
    def current_slide_name(self) -> Optional[str]:
        """The name of the current slide shown on the linked display."""
        if self.display:
            return self.display.current_slide_name
        else:
            return None

widget_classes = [DisplayWidget]
<commit_msg>Added pos to display widget animation properties<commit_after>from typing import Optional, TYPE_CHECKING

from kivy.uix.effectwidget import EffectWidget
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import NumericProperty

from mpfmc.uix.widget import Widget
from mpfmc.uix.display import DisplayOutput

if TYPE_CHECKING:
    from mpfmc.core.mc import MpfMc
    from mpfmc.uix.slide import Slide

class DisplayWidget(Widget, RelativeLayout):
    widget_type_name = 'Display'
    animation_properties = ('x', 'y', 'pos')

    def __init__(self, mc: "MpfMc", config: dict, key: Optional[str]=None, **kwargs) -> None:
        del kwargs
        self.display = None

        super().__init__(mc=mc, config=config, key=key)

        self.display = self.mc.displays[self.config['source_display']]
        self.effects = EffectWidget(pos=self.pos, size_hint=(1, 1))

        if 'effects' in self.config:
            self._add_effects(self.config['effects'])

        # Establish link between display and this display widget
        self.add_widget(self.effects)
        self.display_output = DisplayOutput(self.effects, self.display)

    def __repr__(self) -> str:  # pragma: no cover
        try:
            return '<DisplayWidget size={}, pos={}, source={}>'.format(
                    self.size, self.pos, self.display.name)
        except AttributeError:
            return '<DisplayWidget size={}, source=(none)>'.format(
                    self.size)

    def on_pos(self, instance, pos):
        del instance
        self.effects.pos = pos

    def _add_effects(self, config: Optional[list]) -> None:
        """Adds any effects specified in the config for this display widget."""
        if config:
            effects_list = list()
            for effect_config in config:
                effect_config['width'] = self.width
                effect_config['height'] = self.height
                effects_list.extend(self.mc.effects_manager.get_effect(effect_config))

            self.effects.effects = effects_list

    @property
    def current_slide(self) -> Optional["Slide"]:
        """The current slide shown on the linked display."""
        if self.display:
            return self.display.current_slide
        else:
            return None

    @property
    def current_slide_name(self) -> Optional[str]:
        """The name of the current slide shown on the linked display."""
        if self.display:
            return self.display.current_slide_name
        else:
            return None

widget_classes = [DisplayWidget]
<|endoftext|>


<commit_before>#!/usr/bin/env python
import os

#### CONFIGURATION AND PRE-PROCESSING
# The script has to run from the location on disk that it lives.
#os.chdir(os.path.dirname(__file__))

# Activate the virtualenv
#activate_this = '../bin/activate_this.py' % ENV
#execfile(activate_this, dict(__file__=activate_this))

# Now we can load in whatever libaries we need as we are not inside the
# virtualenv.
from sqlalchemy import (Table, Column, Integer, String, DateTime, Date,
                        ForeignKey, Text, Boolean, MetaData,
                        and_, desc)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, joinedload, subqueryload
from BeautifulSoup import BeautifulSoup as bsoup
from urllib import urlopen
from zipfile import ZipFile
from StringIO import StringIO
from bottle import (run, debug, template, request, response, abort, redirect,
                    static_file, Bottle)
from ConfigParser import ConfigParser
import datetime
import yaml
import json
import time
import re

app = Bottle()
jdict = []
config = ConfigParser()

sql_string = 'sqlite:///database.db'
engine = create_engine(sql_string)
Session = sessionmaker(bind=engine)
Base = declarative_base()

class Plugin(Base):
    __tablename__ = 'plugin'
    id = Column(Integer(8), primary_key=True)
    name = Column(String(128), unique=True)
    categories = Column(Text)
    authors = Column(Text)
    status = Column(String(32))
    link = Column(Text)
    versions = relationship('Version', backref='plugin')

    def __init__(self, name, authors, categories, link, status):
        self.name = name
        self.link = link
        self.update(authors=authors, categories=categories, status=status)

    def _list_parser(self, slist):
        if isinstance(slist, unicode):
            data = slist.split(',')
        else:
            data = slist
        vals = []
        for item in data:
            vals.append(item.strip())
        return vals

    def update(self, authors=None, categories=None, status=None):
        if authors is not None:
            self.authors = ', '.join(self._list_parser(authors))
        if categories is not None:
            self.categories = ', '.join(self._list_parser(categories))
        if status is not None:
            self.status = status

    def get(self, item):
        if item == 'authors':
            return self._list_parser(self.authors)
        if item == 'categories':
            return self._list_parser(self.categories)
        return None
Plugin.metadata.create_all(engine)

class Version(Base):
    __tablename__ = 'version'
    id = Column(Integer(8), primary_key=True)
    name = Column(String(32))
    link = Column(Text)
    date = Column(DateTime)
    cb_versions = Column(Text)
    filename = Column(String(32))
    md5 = Column(String(32))
    hard_dependencies = Column(Text)
    soft_dependencies = Column(Text)
    plugin_id = Column(Integer(8), ForeignKey('plugin.id'))

    def __init__(self, name, date, link, cb_versions, filename, md5,
                 soft_deps, hard_deps, plugin_id):
        self.name = name
        self.link = link
        self.date = date
        self.cb_versions = ', '.join(self._list_parser(cb_versions))
        self.filename = filename
        self.md5 = md5
        self.hard_dependencies = ', '.join(self._list_parser(hard_deps))
        self.soft_dependencies = ', '.join(self._list_parser(soft_deps))
        self.plugin_id = plugin_id

    def _list_parser(self, slist):
        if isinstance(slist, unicode):
            data = slist.split(',')
        else:
            data = slist
        vals = []
        for item in data:
            if len(item) > 0:
                vals.append(item.strip())
        return vals

    def get(self, item):
        if item == 'cb_versions':
            return self._list_parser(self.cb_versions)
        if item == 'soft_dependencies':
            return self._list_parser(self.soft_dependencies)
        if item == 'hard_dependencies':
            return self._list_parser(self.hard_dependencies)
Version.metadata.create_all(engine)

def get(delay=2, host='http://dev.bukkit.org', debug=False, speedy=False):
    s = Session()
    url = '%s/server-mods' % host
    plugins = []

    curl = url
    phase1 = True
    while phase1:
        count = 0
        if debug:
            print 'Opening %s' % curl
        page = bsoup(urlopen(curl))

        # First thing we need to pull all of the row items in the page that
        # contain the data that we are looking for.
        projects = page.findAll(attrs={'class': ['even row-joined-to-next',
                                                 'odd row-joined-to-next']})

        # Next, we parse through each row to get the desired data.
        for project in projects:
            # First we need to pull out the info from the fields in the row.
            proj_raw = project.findNext(attrs={'class': 'col-project'})\
                               .findNext('a')
            cat_raw = project.findNext(attrs={'class': 'category-list'})\
                             .findAll('li')
            user_raw = project.findAll(attrs={'class': 'user user-author'})
            status = project.findNext(attrs={'class': 'col-status'}).text
            link = '%s%s' % (host, proj_raw.get('href'))

            # Now to parse through the category list and parse out the items.
            categories = []
            for cat in cat_raw:
                categories.append(cat.findNext('a').text)

            # Next to pull all of the authors of the plugin.
            authors = []
            for user in user_raw:
                authors.append(user.text)

            # Lastly we will parse out the plugin name.
            name = link.split('/')[-2]

            # Now to check to see if the plugin already exists in the
            # database.  if it does, then we will simply run the update
            # function to update any of the items to current.
            try:
                plugin = s.query(Plugin).filter_by(name=name).one()
            except:
                plugin = Plugin(name, authors, categories, link, status)
                s.add(plugin)
            plugin.update(authors=authors, categories=categories,
                          status=status)
            s.merge(plugin)
            s.commit()

            # Now we need to parse through all of the versions on the first
            # page of the files section.  We will do this because it decreases
            # the number of pages that we will need to parse.
            time.sleep(delay)
            purl = '%sfiles' % (link)
            if debug:
                print 'Opening %s' % purl
            ppage = bsoup(urlopen(purl))
            try:
                rows = ppage.findChild('tbody').findAll('tr')
            except:
                continue

            for row in rows:

                # Yay row parsing, yay!
                filelink = row.findNext(attrs={'class': 'col-file'})\
                              .findNext('a')
                rtype = row.findNext(attrs={'class': 'col-type'})\
                           .findNext('span').text
                fstatus = row.findNext(attrs={'class': 'col-status'})\
                             .findNext('span').text
                sdate = row.findNext(attrs={'class': 'col-date'})\
                           .findNext('span').get('data-epoch')
                vlist_raw = row.findNext(attrs={'class': 'col-game-version'})\
                           .findAll('li')
                fname = row.findNext(attrs={'class': 'col-filename'}).text
                md5sum = row.findNext(attrs={'class': 'col-md5'}).text

                # Now to break down the filelink variable to version name &
                # the link to the page that has the slug to the file.
                version_name = filelink.text
                version_link = '%s%s' % (host, filelink.get('href'))

                # Now to generate a proper datetime object based on this epoch
                version_date = datetime.datetime.fromtimestamp(float(sdate))

                # and now we parse out the CB Build numbers that this version
                # will work with.
                vlist = []
                for item in vlist_raw:
                    dset = item.text.split(' ')
                    if len(dset) > 1:
                        vlist.append(dset[1])

                # If the file isnt a Zipfile or a Jar file, then we can't
                # parse it, so lets just skip it.
                if len(fname.split('.')) > 1:
                    if fname.split('.')[-1].lower() not in ['zip','jar']:
                        continue

                try:
                    version = s.query(Version).filter_by(md5=md5sum).one()
                except:
                    count += 1
                    time.sleep(delay)
                    if debug:
                        print 'Opening %s' % version_link

                    # Now we parse out the real file location
                    dlpage = bsoup(urlopen(version_link))
                    dl_link = dlpage.findChild(attrs={
                                'class': 'user-action user-action-download'})\
                                .findNext('a').get('href')
                    soft_deps = []
                    hard_deps = []

                    # Here we will try to figure out the hard and soft
                    # dependencies.  This is in a try block as I can only
                    # assume that it will fail from time to time. and I would
                    # rather have a empty dependency set than the whole script
                    # fail out.
                    try:
                        dl_data = StringIO()
                        dl_data.write(urlopen(dl_link).read())
                        jar = ZipFile(dl_data)
                        if 'plugin.yml' in jar.namelist():
                            plugin_yaml = yaml.load(jar.read('plugin.yml'))
                            if 'depend' in plugin_yaml:
                                if plugin_yaml['depend'] is not None:
                                    hard_deps = plugin_yaml['depend']
                            if 'softdepend' in plugin_yaml:
                                if plugin_yaml['softdepend'] is not None:
                                    soft_deps = plugin_yaml['softdepend']
                        if debug:
                            print 'Soft: %s / Hard: %s' % (soft_deps, hard_deps)
                        jar.close()
                        dl_data.close()
                    except:
                        pass

                    # Now we add this shiney new version to the database and
                    # commit it up so we don't loose it.
                    version = Version(version_name, version_date,
                                      dl_link, vlist, fname, md5sum,
                                      soft_deps, hard_deps, plugin.id)
                    s.add(version)
                    s.commit()
        next = page.findAll(attrs={'class': 'listing-pagination-pages-next'})
        if count == 0 and speedy:
            phase1 = False
        elif len(next) > 0:
            link = next[0].findNext('a')
            curl = '%s%s' % (host, link.get('href'))
            time.sleep(delay)
        else:
            phase1 = False
    s.close()

def dump(debug=False):
    s = Session()
    plugins = s.query(Plugin).all()
    jdata = []
    for plugin in plugins:
        versions = []
        for version in plugin.versions:
            versions.append({
                'name': version.name,
                'dl_link': version.link,
                'date': int(time.mktime(version.date.timetuple())),
                'filename': version.filename,
                'md5': version.md5,
                'game_builds': [int(i) for i in version.get('cb_versions')],
                'soft_dependencies': version.get('soft_dependencies'),
                'hard_dependencies': version.get('hard_dependencies')
            })
        jdata.append({
            'name': plugin.name,
            'bukkitdev_link': plugin.link,
            'status': plugin.status,
            'authors': plugin.get('authors'),
            'categories': plugin.get('categories'),
            'versions': versions
        })
    return json.dumps(jdata, sort_keys=True, indent=4)

def update():
    global jdict
    jdict = json.loads(dump())

def reload_config():
    config.read('bukget.ini')

@app.route('/')
@app.route('/index.html')
def home_page():
    return template('home_page')

@app.route('/api/update')
def update_json():
    if request['REMOTE_ADDR'] == '127.0.0.1':
        reload_config()
        get(delay=config.getint('Settings', 'delay'),
            debug=config.getboolean('Settings', 'debug'),
            speedy=config.getboolean('Settings', 'speed_load'))
        update()

@app.route('/api/json')
def raw_json():
    response.headers['Content-Type'] = 'application/json'
    return json.dumps(jdict, sort_keys=True, indent=4)

@app.route('/api/plugins')
def plugin_list():
    response.headers['Content-Type'] = 'application/json'
    items = []
    for item in jdict:
        items.append(item['name'])
    return json.dumps(sorted(items), sort_keys=True, indent=4)

@app.route('/api/plugin/:name')
def plugin_info(name):
    response.headers['Content-Type'] = 'application/json'
    for item in jdict:
        if item['name'] == name:
            return json.dumps(item, sort_keys=True, indent=4)
    return ''

@app.route('/ai/categories')
def cat_list():
    response.headers['Content-Type'] = 'application/json'
    cats = []
    for item in jdict:
        for cat in item['categories']:
            if cat not in cats:
                cats.append(cat)
    return json.dumps(cats, sort_keys=True, indent=4)

@app.route('/api/category/:name')
def cat_info(name):
    cat_name = name.replace('_', ' ')
    items = []
    for item in jdict:
        if cat_name in item['categories']:
            items.append(item['name'])
    return json.dumps(items, sort_keys=True, indent=4)

@app.route('/api/search', method='POST')
def api_search():
    field_name = request.forms.get('field_name')
    action = request.forms.get('action')
    value = request.forms.get('action')

    if field_name[:1] == 'v_':
        in_versions = True
        field_name = field_name[2:]
    else:
        in_versions = False

    items = []
    for item in jdict:
        match = False
        if in_versions:
            for version in item['versions']:
                match = seval(version, field_name, action, value)
        else:
            match = seval(item, field_name, action, value)
        if match:
            items.append(item)
    return json.dumps(items, sort_keys=True, indent=4)

def seval(item, name, action, value):
    if name in item:
        try:
            if action == '=':
                if value == item[name]:
                    return True
            if action == '<':
                if value < item[name]:
                    return True
            if action == '<=':
                if value <= item[name]:
                    return True
            if action == '>':
                if value > item[name]:
                    return True
            if action == '>=':
                if value >= item[name]:
                    return True
            if action == 'in':
                if value in item[name]:
                    return True
            if action == 'like':
                if len(re.findall(value, item[name])) > 0:
                    return True
        except:
            return False
    return False

if __name__ == '__main__':
    reload_config()
    update()
    debug(config.getboolean('Settings', 'debug'))
    run(app=app,
        port=config.getint('Settings','port'),
        host=config.get('Settings', 'host'))<commit_msg>Bug Fixes<commit_after>#!/usr/bin/env python
import os

#### CONFIGURATION AND PRE-PROCESSING
# The script has to run from the location on disk that it lives.
#os.chdir(os.path.dirname(__file__))

# Activate the virtualenv
#activate_this = '../bin/activate_this.py' % ENV
#execfile(activate_this, dict(__file__=activate_this))

# Now we can load in whatever libaries we need as we are not inside the
# virtualenv.
from sqlalchemy import (Table, Column, Integer, String, DateTime, Date,
                        ForeignKey, Text, Boolean, MetaData,
                        and_, desc)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, joinedload, subqueryload
from BeautifulSoup import BeautifulSoup as bsoup
from urllib import urlopen
from zipfile import ZipFile
from StringIO import StringIO
from bottle import (run, debug, template, request, response, abort, redirect,
                    static_file, Bottle)
from ConfigParser import ConfigParser
import datetime
import yaml
import json
import time
import re

app = Bottle()
jdict = []
config = ConfigParser()

sql_string = 'sqlite:///database.db'
engine = create_engine(sql_string)
Session = sessionmaker(bind=engine)
Base = declarative_base()

class Plugin(Base):
    __tablename__ = 'plugin'
    id = Column(Integer(8), primary_key=True)
    name = Column(String(128), unique=True)
    categories = Column(Text)
    authors = Column(Text)
    status = Column(String(32))
    link = Column(Text)
    versions = relationship('Version', backref='plugin')

    def __init__(self, name, authors, categories, link, status):
        self.name = name
        self.link = link
        self.update(authors=authors, categories=categories, status=status)

    def _list_parser(self, slist):
        if isinstance(slist, unicode):
            data = slist.split(',')
        else:
            data = slist
        vals = []
        for item in data:
            vals.append(item.strip())
        return vals

    def update(self, authors=None, categories=None, status=None):
        if authors is not None:
            self.authors = ', '.join(self._list_parser(authors))
        if categories is not None:
            self.categories = ', '.join(self._list_parser(categories))
        if status is not None:
            self.status = status

    def get(self, item):
        if item == 'authors':
            return self._list_parser(self.authors)
        if item == 'categories':
            return self._list_parser(self.categories)
        return None
Plugin.metadata.create_all(engine)

class Version(Base):
    __tablename__ = 'version'
    id = Column(Integer(8), primary_key=True)
    name = Column(String(32))
    link = Column(Text)
    date = Column(DateTime)
    cb_versions = Column(Text)
    filename = Column(String(32))
    md5 = Column(String(32))
    hard_dependencies = Column(Text)
    soft_dependencies = Column(Text)
    plugin_id = Column(Integer(8), ForeignKey('plugin.id'))

    def __init__(self, name, date, link, cb_versions, filename, md5,
                 soft_deps, hard_deps, plugin_id):
        self.name = name
        self.link = link
        self.date = date
        self.cb_versions = ', '.join(self._list_parser(cb_versions))
        self.filename = filename
        self.md5 = md5
        self.hard_dependencies = ', '.join(self._list_parser(hard_deps))
        self.soft_dependencies = ', '.join(self._list_parser(soft_deps))
        self.plugin_id = plugin_id

    def _list_parser(self, slist):
        if isinstance(slist, unicode):
            data = slist.split(',')
        else:
            data = slist
        vals = []
        for item in data:
            if len(item) > 0:
                vals.append(item.strip())
        return vals

    def get(self, item):
        if item == 'cb_versions':
            return self._list_parser(self.cb_versions)
        if item == 'soft_dependencies':
            return self._list_parser(self.soft_dependencies)
        if item == 'hard_dependencies':
            return self._list_parser(self.hard_dependencies)
Version.metadata.create_all(engine)

def get(delay=2, host='http://dev.bukkit.org', debug=False, speedy=False):
    s = Session()
    url = '%s/server-mods' % host
    plugins = []

    curl = url
    phase1 = True
    while phase1:
        count = 0
        if debug:
            print 'Opening %s' % curl
        page = bsoup(urlopen(curl))

        # First thing we need to pull all of the row items in the page that
        # contain the data that we are looking for.
        projects = page.findAll(attrs={'class': ['even row-joined-to-next',
                                                 'odd row-joined-to-next']})

        # Next, we parse through each row to get the desired data.
        for project in projects:
            # First we need to pull out the info from the fields in the row.
            proj_raw = project.findNext(attrs={'class': 'col-project'})\
                               .findNext('a')
            cat_raw = project.findNext(attrs={'class': 'category-list'})\
                             .findAll('li')
            user_raw = project.findAll(attrs={'class': 'user user-author'})
            status = project.findNext(attrs={'class': 'col-status'}).text
            link = '%s%s' % (host, proj_raw.get('href'))

            # Now to parse through the category list and parse out the items.
            categories = []
            for cat in cat_raw:
                categories.append(cat.findNext('a').text)

            # Next to pull all of the authors of the plugin.
            authors = []
            for user in user_raw:
                authors.append(user.text)

            # Lastly we will parse out the plugin name.
            name = link.split('/')[-2]

            # Now to check to see if the plugin already exists in the
            # database.  if it does, then we will simply run the update
            # function to update any of the items to current.
            try:
                plugin = s.query(Plugin).filter_by(name=name).one()
            except:
                plugin = Plugin(name, authors, categories, link, status)
                s.add(plugin)
            plugin.update(authors=authors, categories=categories,
                          status=status)
            s.merge(plugin)
            s.commit()

            # Now we need to parse through all of the versions on the first
            # page of the files section.  We will do this because it decreases
            # the number of pages that we will need to parse.
            time.sleep(delay)
            purl = '%sfiles' % (link)
            if debug:
                print 'Opening %s' % purl
            ppage = bsoup(urlopen(purl))
            try:
                rows = ppage.findChild('tbody').findAll('tr')
            except:
                continue

            for row in rows:

                # Yay row parsing, yay!
                filelink = row.findNext(attrs={'class': 'col-file'})\
                              .findNext('a')
                rtype = row.findNext(attrs={'class': 'col-type'})\
                           .findNext('span').text
                fstatus = row.findNext(attrs={'class': 'col-status'})\
                             .findNext('span').text
                sdate = row.findNext(attrs={'class': 'col-date'})\
                           .findNext('span').get('data-epoch')
                vlist_raw = row.findNext(attrs={'class': 'col-game-version'})\
                           .findAll('li')
                fname = row.findNext(attrs={'class': 'col-filename'}).text
                md5sum = row.findNext(attrs={'class': 'col-md5'}).text

                # Now to break down the filelink variable to version name &
                # the link to the page that has the slug to the file.
                version_name = filelink.text
                version_link = '%s%s' % (host, filelink.get('href'))

                # Now to generate a proper datetime object based on this epoch
                version_date = datetime.datetime.fromtimestamp(float(sdate))

                # and now we parse out the CB Build numbers that this version
                # will work with.
                vlist = []
                for item in vlist_raw:
                    dset = item.text.split(' ')
                    if len(dset) > 1:
                        vlist.append(dset[1])

                # If the file isnt a Zipfile or a Jar file, then we can't
                # parse it, so lets just skip it.
                if len(fname.split('.')) > 1:
                    if fname.split('.')[-1].lower() not in ['zip','jar']:
                        continue

                try:
                    version = s.query(Version).filter_by(md5=md5sum).one()
                except:
                    count += 1
                    time.sleep(delay)
                    if debug:
                        print 'Opening %s' % version_link

                    # Now we parse out the real file location
                    dlpage = bsoup(urlopen(version_link))
                    dl_link = dlpage.findChild(attrs={
                                'class': 'user-action user-action-download'})\
                                .findNext('a').get('href')
                    soft_deps = []
                    hard_deps = []

                    # Here we will try to figure out the hard and soft
                    # dependencies.  This is in a try block as I can only
                    # assume that it will fail from time to time. and I would
                    # rather have a empty dependency set than the whole script
                    # fail out.
                    try:
                        dl_data = StringIO()
                        dl_data.write(urlopen(dl_link).read())
                        jar = ZipFile(dl_data)
                        if 'plugin.yml' in jar.namelist():
                            plugin_yaml = yaml.load(jar.read('plugin.yml'))
                            if 'depend' in plugin_yaml:
                                if plugin_yaml['depend'] is not None:
                                    hard_deps = plugin_yaml['depend']
                            if 'softdepend' in plugin_yaml:
                                if plugin_yaml['softdepend'] is not None:
                                    soft_deps = plugin_yaml['softdepend']
                        if debug:
                            print 'Soft: %s / Hard: %s' % (soft_deps, hard_deps)
                        jar.close()
                        dl_data.close()
                    except:
                        pass

                    # Now we add this shiney new version to the database and
                    # commit it up so we don't loose it.
                    version = Version(version_name, version_date,
                                      dl_link, vlist, fname, md5sum,
                                      soft_deps, hard_deps, plugin.id)
                    s.add(version)
                    s.commit()
        next = page.findAll(attrs={'class': 'listing-pagination-pages-next'})
        if count == 0 and speedy:
            phase1 = False
        elif len(next) > 0:
            link = next[0].findNext('a')
            curl = '%s%s' % (host, link.get('href'))
            time.sleep(delay)
        else:
            phase1 = False
    s.close()

def dump(debug=False):
    s = Session()
    plugins = s.query(Plugin).all()
    jdata = []
    for plugin in plugins:
        versions = []
        for version in plugin.versions:
            versions.append({
                'name': version.name,
                'dl_link': version.link,
                'date': int(time.mktime(version.date.timetuple())),
                'filename': version.filename,
                'md5': version.md5,
                'game_builds': [int(i) for i in version.get('cb_versions')],
                'soft_dependencies': version.get('soft_dependencies'),
                'hard_dependencies': version.get('hard_dependencies')
            })
        jdata.append({
            'name': plugin.name,
            'bukkitdev_link': plugin.link,
            'status': plugin.status,
            'authors': plugin.get('authors'),
            'categories': plugin.get('categories'),
            'versions': versions
        })
    return json.dumps(jdata, sort_keys=True, indent=4)

def update():
    global jdict
    jdict = json.loads(dump())

def reload_config():
    config.read('bukget.ini')

@app.route('/')
@app.route('/index.html')
def home_page():
    return template('home_page')

@app.route('/api/update')
def update_json():
    if request['REMOTE_ADDR'] == '127.0.0.1':
        reload_config()
        get(delay=config.getint('Settings', 'delay'),
            debug=config.getboolean('Settings', 'debug'),
            speedy=config.getboolean('Settings', 'speed_load'))
        update()

@app.route('/api/json')
def raw_json():
    response.headers['Content-Type'] = 'application/json'
    return json.dumps(jdict, sort_keys=True, indent=4)

@app.route('/api/plugins')
def plugin_list():
    response.headers['Content-Type'] = 'application/json'
    items = []
    for item in jdict:
        items.append(item['name'])
    return json.dumps(sorted(items), sort_keys=True, indent=4)

@app.route('/api/plugin/:name')
def plugin_info(name):
    response.headers['Content-Type'] = 'application/json'
    for item in jdict:
        if item['name'] == name:
            return json.dumps(item, sort_keys=True, indent=4)
    return ''

@app.route('/api/categories')
def cat_list():
    response.headers['Content-Type'] = 'application/json'
    cats = []
    for item in jdict:
        for cat in item['categories']:
            if cat not in cats:
                cats.append(cat)
    return json.dumps(sorted(cats), sort_keys=True, indent=4)

@app.route('/api/category/:name')
def cat_info(name):
    response.headers['Content-Type'] = 'application/json'
    cat_name = name.replace('_', ' ')
    items = []
    for item in jdict:
        if cat_name in item['categories']:
            items.append(item['name'])
    return json.dumps(sorted(items), sort_keys=True, indent=4)

@app.route('/api/search', method='POST')
def api_search():
    response.headers['Content-Type'] = 'application/json'
    field_name = request.forms.get('field_name')
    action = request.forms.get('action')
    value = request.forms.get('action')

    if field_name[:1] == 'v_':
        in_versions = True
        field_name = field_name[2:]
    else:
        in_versions = False

    items = []
    for item in jdict:
        match = False
        if in_versions:
            for version in item['versions']:
                match = seval(version, field_name, action, value)
        else:
            match = seval(item, field_name, action, value)
        if match:
            items.append(item)
    return json.dumps(items, sort_keys=True, indent=4)

def seval(item, name, action, value):
    if name in item:
        try:
            if action == '=':
                if value == item[name]:
                    return True
            if action == '<':
                if value < item[name]:
                    return True
            if action == '<=':
                if value <= item[name]:
                    return True
            if action == '>':
                if value > item[name]:
                    return True
            if action == '>=':
                if value >= item[name]:
                    return True
            if action == 'in':
                if value in item[name]:
                    return True
            if action == 'like':
                if len(re.findall(value, item[name])) > 0:
                    return True
        except:
            return False
    return False

if __name__ == '__main__':
    reload_config()
    update()
    debug(config.getboolean('Settings', 'debug'))
    run(app=app,
        port=config.getint('Settings','port'),
        host=config.get('Settings', 'host'))<|endoftext|>