diff --git a/pharaoh/pharaoh/app/__init__.py b/pharaoh/pharaoh/app/__init__.py index 139597f9c..e69de29bb 100644 --- a/pharaoh/pharaoh/app/__init__.py +++ b/pharaoh/pharaoh/app/__init__.py @@ -1,2 +0,0 @@ - - diff --git a/pharaoh/pharaoh/app/flask_app.py b/pharaoh/pharaoh/app/flask_app.py index c5029c4ee..e53bf8821 100644 --- a/pharaoh/pharaoh/app/flask_app.py +++ b/pharaoh/pharaoh/app/flask_app.py @@ -18,7 +18,6 @@ from flask_environments import Environments from pymongo import MongoClient - app = Flask(__name__) env = Environments(app) env.from_yaml(os.path.join(os.path.abspath(os.path.join('..', os.path.dirname(__file__))), '..', 'config.yaml')) diff --git a/pharaoh/pharaoh/app/flask_environments.py b/pharaoh/pharaoh/app/flask_environments.py new file mode 100644 index 000000000..bfd6878f3 --- /dev/null +++ b/pharaoh/pharaoh/app/flask_environments.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +""" + flask_environments + ~~~~~~~~~~~~~~~~~~ + + Environment tools and configuration for Flask applications + + :copyright: (c) 2012 by Matt Wright. + :license: MIT, see LICENSE for more details. + + :source: https://github.com/mattupstate/flask-environments +""" + +import os + +import yaml +from flask import current_app + + +class Environments(object): + + def __init__(self, app=None, var_name=None, default_env=None): + self.app = app + self.var_name = var_name or 'FLASK_ENV' + self.default_env = default_env or 'DEVELOPMENT' + self.env = os.environ.get(self.var_name, self.default_env) + + if app is not None: + self.init_app(app) + + def init_app(self, app): + app.config['ENVIORNMENT'] = self.env + + if app.extensions is None: + app.extensions = {} + + app.extensions['environments'] = self + + def get_app(self, reference_app=None): + if reference_app is not None: + return reference_app + if self.app is not None: + return self.app + return current_app + + def from_object(self, config_obj): + app = self.get_app() + + for name in self._possible_names(): + try: + obj = '%s.%s' % (config_obj, name) + app.config.from_object(obj) + return + except: + pass + + app.config.from_object(config_obj) + + def from_yaml(self, path): + with open(path) as f: + c = yaml.load(f) + + for name in self._possible_names(): + try: + c = c[name] + except: + pass + + app = self.get_app() + + for key in c.iterkeys(): + if key.isupper(): + app.config[key] = c[key] + + def _possible_names(self): + return (self.env, self.env.capitalize(), self.env.lower()) diff --git a/pharaoh/pharaoh/app/models.py b/pharaoh/pharaoh/app/models.py index 1b2bad069..c546b54a8 100644 --- a/pharaoh/pharaoh/app/models.py +++ b/pharaoh/pharaoh/app/models.py @@ -16,7 +16,6 @@ from flask_app import app, db - def get_sentences_in_file(fp, source_language, target_language, curr_db=db): '''This function gets all of the sentences in the given file :param dataabase db: database @@ -597,7 +596,6 @@ def trust_level(self, value): else: raise TypeError - class MyError(Exception): def __init__(self, msg, code): self.msg = msg @@ -606,7 +604,6 @@ def __init__(self, msg, code): def __str__(self): return self.msg - class LockError(Exception): def __init__(self, msg, file_path, username, target_language): self.msg = msg diff --git a/pharaoh/pharaoh/app/views.py b/pharaoh/pharaoh/app/views.py index 65e1faa49..499aeb3ab 100644 --- a/pharaoh/pharaoh/app/views.py +++ b/pharaoh/pharaoh/app/views.py @@ -161,7 +161,7 @@ def download_single_po_approved(language, file): @app.route('/download-all//') @app.route('/download-all/') def download_all_po(language): - ''' This function downloads all translations from all + ''' This function downloads all translations from all po files ''' po = generate_all_po_files( 'en', language, db, True) @@ -172,7 +172,7 @@ def download_all_po(language): @app.route('/download-approved//') @app.route('/download-approved/') def download_all_po_approved(language): - ''' This function downloads all approved translations from all + ''' This function downloads all approved translations from all po files ''' po = generate_all_po_files( 'en', language, db, False) @@ -191,10 +191,10 @@ def upload(): ''' This function uploads the given tar ball to mongodb''' app.logger.info(request.files['file']) app.logger.info(request.form) - put_po_data_in_mongo(request.files['file'], - request.form['username'], - request.form['status'], - request.form['source_language'], + put_po_data_in_mongo(request.files['file'], + request.form['username'], + request.form['status'], + request.form['source_language'], request.form['target_language'], db) return json.dumps({"code:": 200, "msg": "Unapproval Succeeded"}), 200 diff --git a/pharaoh/pharaoh/config.yaml b/pharaoh/pharaoh/config.yaml index 8b89269c2..5ea138a4a 100644 --- a/pharaoh/pharaoh/config.yaml +++ b/pharaoh/pharaoh/config.yaml @@ -14,7 +14,7 @@ APPROVAL_THRESHOLD: 2 -MONGO_PORT: 28000 +MONGO_PORT: 27019 MONGO_HOST: 'localhost' MONGO_DBNAME: 'veritest' NUM_FILES_PER_PAGE: 20 diff --git a/pharaoh/setup.py b/pharaoh/setup.py index 424ec3142..f32704dd7 100644 --- a/pharaoh/setup.py +++ b/pharaoh/setup.py @@ -2,27 +2,27 @@ from setuptools import setup, find_packages -REQUIRES = ['argh', 'polib', 'flask', 'gunicorn', 'pymongo', - 'pyYAML', 'flask-environments'] +REQUIRES = ['argh', 'polib', 'flask', 'gunicorn', 'pymongo', 'pyyaml', + 'flask-environments'] setup( name='pharaoh', - maintainer='judahschvimer', - maintainer_email='judah.schvimer@mongodb.com', - description='PO File Translation Verifier', + maintainer='tychoish', + maintainer_email='sam@tychoish.com', + author='judahschvimer', + author_email='judah.schvimer@mongodb.com', + description='PO File Translation Verification Web App', version=pharaoh.__version__, license='Apache 2.0', url='http://github.com/mongodb/docs-tools.git', packages=find_packages(), test_suite=None, install_requires=REQUIRES, - package_data={'pharaoh': ['quickstart/*']}, classifiers=[ 'Environment :: Console', 'Intended Audience :: Developers', 'Topic :: Documentation', 'Topic :: Software Development :: Testing', - 'Topic :: Translation', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'License :: OSI Approved :: Apache Software License', @@ -31,5 +31,5 @@ 'console_scripts': [ 'pharaoh = pharaoh.cmdline:main', ], - }, - ) + }, +) diff --git a/pharaoh/test/test_verifier.py b/pharaoh/test/test_verifier.py index 2637f7c8f..09a8003de 100644 --- a/pharaoh/test/test_verifier.py +++ b/pharaoh/test/test_verifier.py @@ -15,7 +15,7 @@ from pharaoh.mongo_to_po import generate_fresh_po_text MONGODB_TEST_PORT = 31415 -PATH_TO_MONGOD = '/home/wisdom/mongodb/2.6.0-rc0' + DBNAME = 'veritest' logger = logging.getLogger('pharaoh.test_verifier') @@ -42,7 +42,7 @@ def get_instance(cls): def __init__(self): self._tmpdir = tempfile.mkdtemp() logger.info(self._tmpdir) - self._process = subprocess.Popen('{0}/mongod --bind_ip localhost --port {1} --dbpath {2} --nojournal --nohttpinterface --noauth --smallfiles --syncdelay 0 --maxConns 10 --nssize 1'.format(PATH_TO_MONGOD, MONGODB_TEST_PORT, self._tmpdir), shell=True, executable='/bin/bash') + self._process = subprocess.Popen('mongod --bind_ip localhost --port {0} --dbpath {1} --nojournal --nohttpinterface --noauth --smallfiles --syncdelay 0 --maxConns 10 --nssize 1'.format(MONGODB_TEST_PORT, self._tmpdir), shell=True, executable='/bin/bash') # wait for the instance to be ready # Mongo is ready in a glance, we just wait to be able to open a # Connection. @@ -76,7 +76,7 @@ class ExportTestCase(unittest.TestCase): os.path.join(TEST_PATH, 'test_files', 'users.json'), os.path.join(TEST_PATH, 'test_files', 'files.json')] def __init__(self, *args, **kwargs): - super(VerifierTestCase, self).__init__(*args, **kwargs) + super(ExportTestCase, self).__init__(*args, **kwargs) self.db_inst = MongoTemporaryInstance.get_instance() self.client = self.db_inst.client self.db = self.client[DBNAME] @@ -157,7 +157,6 @@ def jumble_data(self): def setUp(self): '''This method sets up the test by deleting all of the databases and reloading them''' - super(TestCase, self).setUp() for db_name in self.client.database_names(): self.client.drop_database(db_name) @@ -289,4 +288,4 @@ def test_edit_lock(self): s.edit(wisdom, s.target_sentence) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()