Пример #1
0
 def __init__(self, config=config.get('sender')):
     self.url = config['url']
     self.key = config['key']
     self.maxRowsToSend = 10
     self.lists = self.get_result('getLists', {
         'format': 'json',
         'api_key': self.key
     })
Пример #2
0
def clean_locale(locale):
    """
    Strips out the warning from all of a locale's translated po files
    about being an English source file.
    Iterates over machine-generated files.
    """
    dirname = CONFIGURATION.get_messages_dir(locale)
    for filename in ('django-partial.po', 'djangojs.po', 'mako.po'):
        clean_file(dirname.joinpath(filename))
Пример #3
0
    def assert_merge_headers(self, locale):
        """
        This is invoked by test_main to ensure that it runs after
        calling generate.main().
        
        There should be exactly three merge comment headers
        in our merged .po file. This counts them to be sure.
        A merge comment looks like this:
        # #-#-#-#-#  django-partial.po (0.1a)  #-#-#-#-#

        """
        path = os.path.join(CONFIGURATION.get_messages_dir(locale), 'django.po')
        po = pofile(path)
        pattern = re.compile('^#-#-#-#-#', re.M)
        match = pattern.findall(po.header)
        self.assertEqual(len(match), 3,
                         msg="Found %s (should be 3) merge comments in the header for %s" % \
                         (len(match), path))
Пример #4
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main()
     for locale in CONFIGURATION.locales:
         for filename in ('django', 'djangojs'):
             mofile = filename+'.mo'
             path = os.path.join(CONFIGURATION.get_messages_dir(locale), mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists, msg='Missing file in locale %s: %s' % (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(os.path.getmtime(path)) >= self.start_time,
                             msg='File not recently modified: %s' % path)
         self.assert_merge_headers(locale)
Пример #5
0
def merge(locale, target='django.po', fail_if_missing=True):
    """
    For the given locale, merge django-partial.po, messages.po, mako.po -> django.po
    target is the resulting filename
    If fail_if_missing is True, and the files to be merged are missing,
    throw an Exception.
    If fail_if_missing is False, and the files to be merged are missing,
    just return silently.
    """
    LOG.info('Merging locale={0}'.format(locale))
    locale_directory = CONFIGURATION.get_messages_dir(locale)
    files_to_merge = ('django-partial.po', 'messages.po', 'mako.po')
    try:
        validate_files(locale_directory, files_to_merge)
    except Exception, e:
        if not fail_if_missing:
            return
        raise e
Пример #6
0
def merge(locale, target='django.po', fail_if_missing=True):
    """
    For the given locale, merge django-partial.po, messages.po, mako.po -> django.po
    target is the resulting filename
    If fail_if_missing is True, and the files to be merged are missing,
    throw an Exception.
    If fail_if_missing is False, and the files to be merged are missing,
    just return silently.
    """
    LOG.info('Merging locale={0}'.format(locale))
    locale_directory = CONFIGURATION.get_messages_dir(locale)
    files_to_merge = ('django-partial.po', 'messages.po', 'mako.po')
    try:
        validate_files(locale_directory, files_to_merge)
    except Exception, e:
        if not fail_if_missing:
            return
        raise e
Пример #7
0
    def assert_merge_headers(self, locale):
        """
        This is invoked by test_main to ensure that it runs after
        calling generate.main().

        There should be exactly three merge comment headers
        in our merged .po file. This counts them to be sure.
        A merge comment looks like this:
        # #-#-#-#-#  django-partial.po (0.1a)  #-#-#-#-#

        """
        path = os.path.join(CONFIGURATION.get_messages_dir(locale),
                            'django.po')
        po = pofile(path)
        pattern = re.compile('^#-#-#-#-#', re.M)
        match = pattern.findall(po.header)
        self.assertEqual(len(match), 3,
                         msg="Found %s (should be 3) merge comments in the header for %s" % \
                         (len(match), path))
Пример #8
0
 def test_main(self):
     """
     Runs generate.main() which should merge source files,
     then compile all sources in all configured languages.
     Validates output by checking all .mo files in all configured languages.
     .mo files should exist, and be recently created (modified
     after start of test suite)
     """
     generate.main()
     for locale in CONFIGURATION.locales:
         for filename in ('django', 'djangojs'):
             mofile = filename + '.mo'
             path = os.path.join(CONFIGURATION.get_messages_dir(locale),
                                 mofile)
             exists = os.path.exists(path)
             self.assertTrue(exists,
                             msg='Missing file in locale %s: %s' %
                             (locale, mofile))
             self.assertTrue(datetime.fromtimestamp(os.path.getmtime(path))
                             >= self.start_time,
                             msg='File not recently modified: %s' % path)
         self.assert_merge_headers(locale)
Пример #9
0
""" Helper functions. """
from config import CONFIGURATION

LOGGER = CONFIGURATION.get_logger(__name__)
redis_con = CONFIGURATION.get_db()


def get_all_todos():
    """ Return all todos from database. """
    redis_key = 'todos'
    todo_ids = redis_con.smembers(redis_key)
    # If no todos, return empty.
    if (not todo_ids or len(todo_ids) <= 0):
        return None
    # Get all todos
    todos = []
    for todo_id in todo_ids:
        temp_key = ":".join((redis_key, todo_id))
        todo = redis_con.hgetall(temp_key)
        todo['id'] = todo_id
        todos.append(todo)

    return todos


def delete_todo(todo_id):
    """ Remove Todo from db """
    redis_key = 'todos'
    todo_ids = redis_con.smembers(redis_key)
    # If no todos, return empty.
    if (not todo_ids or len(todo_ids) <= 0 or todo_id not in todo_ids):
Пример #10
0
        raise IOError('File does not exist: %s' % file)
    pofile = polib.pofile(file)
    converter = Dummy()
    converter.init_msgs(pofile.translated_entries())
    for msg in pofile:
        converter.convert_msg(msg)
    new_file = new_filename(file, locale)
    create_dir_if_necessary(new_file)
    pofile.save(new_file)


def new_filename(original_filename, new_locale):
    """Returns a filename derived from original_filename, using new_locale as the locale"""
    orig_dir = os.path.dirname(original_filename)
    msgs_dir = os.path.basename(orig_dir)
    orig_file = os.path.basename(original_filename)
    return os.path.abspath(
        os.path.join(orig_dir, '../..', new_locale, msgs_dir, orig_file))


if __name__ == '__main__':
    # required arg: file
    if len(sys.argv) < 2:
        raise Exception("missing file argument")
    # optional arg: locale
    if len(sys.argv) < 3:
        locale = CONFIGURATION.get_dummy_locale()
    else:
        locale = sys.argv[2]
    main(sys.argv[1], locale)
Пример #11
0
""" Parkingslots api module. """
# Python mail libs.
import numpy as np
# Python libs.
import flask
import logging
from flask_restplus import Resource, Namespace
# Project files.
from . import lib
from config import CONFIGURATION
from webmaps.models.slots_cluster import ParkingSlotsCluster
from constans import VALIDATION_NAMESPACE

NAMESPACE = Namespace(
    'parking-slot', description='Api namespace representing a parking slot.')
LOGGER = CONFIGURATION.get_logger(__name__)
# Model for parsing arguments.
user_location_model = NAMESPACE.parser()
user_location_model.add_argument(
    'longitude', type=float, help='Longitude of parking slot.', required=True)
user_location_model.add_argument(
    'latitude', type=float, help='Latitude of parking slot.', required=True)
user_location_model.add_argument(
    'radius', type=float, help='Radius of circle to look for parking.',
    required=True
)
user_location_model.add_argument(
    'time', type=float, help='Time of day the user wants to park.',
    required=True
)
Пример #12
0
    pofile = polib.pofile(file)
    converter = Dummy()
    converter.init_msgs(pofile.translated_entries())
    for msg in pofile:
        converter.convert_msg(msg)
    new_file = new_filename(file, locale)
    create_dir_if_necessary(new_file)
    pofile.save(new_file)

def new_filename(original_filename, new_locale):
    """Returns a filename derived from original_filename, using new_locale as the locale"""
    orig_dir = os.path.dirname(original_filename)
    msgs_dir = os.path.basename(orig_dir)
    orig_file = os.path.basename(original_filename)
    return os.path.abspath(os.path.join(orig_dir,
                                        '../..',
                                        new_locale,
                                        msgs_dir,
                                        orig_file))

if __name__ == '__main__':
    # required arg: file
    if len(sys.argv)<2:
        raise Exception("missing file argument")
    # optional arg: locale
    if len(sys.argv)<3:
        locale = CONFIGURATION.get_dummy_locale()
    else:
        locale = sys.argv[2]
    main(sys.argv[1], locale)
Пример #13
0
""" This is the main application module. """
from config import CONFIGURATION
from flask_login import LoginManager
from flask_cors import CORS
from webmaps import APP
from webmaps.modules import API

LOGGIN_MANAGER = LoginManager(APP)
CORS(APP)

APP.secret_key = CONFIGURATION.secret_key
APP.config['SERVER_NAME'] = CONFIGURATION.get_server_name()
API.init_app(APP)

if __name__ == '__main__':
    APP.run(debug=CONFIGURATION.debug_mode,
            host=CONFIGURATION.backend_ip,
            port=CONFIGURATION.port)
Пример #14
0
    print('maintanance')
    return jsonify(logic.maintenanceAccurals())


@app.route('/', methods=['GET'])
def get_tasks():
    result = db.test_db()
    return jsonify(result)


@app.route('/payments', methods=['POST'])
@auth
def post_payments():
    result = None
    data = request.get_json(force=True)
    result = logic.upsert_payment(data)
    # except Exception as e:
    #     print(e)
    #     traceback.print_stack()
    #     # result = {'ERROR'}
    return jsonify(result)


TOKEN = config.get('TOKEN', None)
if not (TOKEN):
    print('WARNING: TOKEN is not found in config.py')


if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=True)
""" This is the main application module. """

# Python libs.
from flask_cors import CORS
from src import APP

# Porject files.
from src.modules import API
from config import CONFIGURATION

CORS(APP)
# APP.secret_key = CONFIGURATION.secret_key
APP.config['SERVER_NAME'] = CONFIGURATION.get_backend_socket()
API.init_app(APP)

if __name__ == '__main__':
    APP.run(debug=CONFIGURATION.debug_mode,
            host=CONFIGURATION.backend_ip,
            port=CONFIGURATION.backend_port)