Skip to content

Commit

Permalink
pharoah: incremental dev work
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Kleinman committed Aug 19, 2014
1 parent 4231325 commit bda44f7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 27 deletions.
2 changes: 0 additions & 2 deletions pharaoh/pharaoh/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@


1 change: 0 additions & 1 deletion pharaoh/pharaoh/app/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
76 changes: 76 additions & 0 deletions pharaoh/pharaoh/app/flask_environments.py
Original file line number Diff line number Diff line change
@@ -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())
3 changes: 0 additions & 3 deletions pharaoh/pharaoh/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -597,7 +596,6 @@ def trust_level(self, value):
else:
raise TypeError


class MyError(Exception):
def __init__(self, msg, code):
self.msg = msg
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pharaoh/pharaoh/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def download_single_po_approved(language, file):
@app.route('/download-all/<language>/')
@app.route('/download-all/<language>')
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)
Expand All @@ -172,7 +172,7 @@ def download_all_po(language):
@app.route('/download-approved/<language>/')
@app.route('/download-approved/<language>')
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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pharaoh/pharaoh/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


APPROVAL_THRESHOLD: 2
MONGO_PORT: 28000
MONGO_PORT: 27019
MONGO_HOST: 'localhost'
MONGO_DBNAME: 'veritest'
NUM_FILES_PER_PAGE: 20
Expand Down
18 changes: 9 additions & 9 deletions pharaoh/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
description='PO File Translation Verifier',
maintainer='tychoish',
maintainer_email='[email protected]',
author='judahschvimer',
author_email='[email protected]',
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',
Expand All @@ -31,5 +31,5 @@
'console_scripts': [
'pharaoh = pharaoh.cmdline:main',
],
},
)
},
)
9 changes: 4 additions & 5 deletions pharaoh/test/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -289,4 +288,4 @@ def test_edit_lock(self):
s.edit(wisdom, s.target_sentence)

if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit bda44f7

Please sign in to comment.