Changeset - ed548e9a54fa
[Not reviewed]
default
0 5 0
Dennis Fink - 11 years ago 2014-01-26 14:39:30
dennis.fink@c3l.lu
unified strings use ' instead of ", updated classifiers and use date in donations
5 files changed with 23 insertions and 23 deletions:
0 comments (0 inline, 0 general)
ennstatus/api/views.py
Show inline comments
 
@@ -13,64 +13,64 @@ def update():
 

	
 
    current_app.logger.info('Handling update')
 
    if current_app.debug:
 
        accepted_ips = ['127.0.0.1']
 
    else:
 
        accepted_ips = current_app.config.get('ENNSTATUS_ACCEPTED_IPS', [])
 

	
 
    json = request.get_json()
 
    if json is None:
 
        current_app.logger.info('No JSON data supplied!')
 
        return 'No JSON data supplied!\n', 400, {'Content-Type': 'text/plain'}
 

	
 
    try:
 
        check_json_format(json)
 
    except ValueError as e:
 
        current_app.logger.warning(' '.join([str(e), str(json)]))
 
        return str(e), 409, {'Content-Type': 'text/plain'}
 

	
 
    if 'ip' in json:
 
        ip = json['ip']
 
    else:
 
        ip = request.remote_addr
 

	
 
    if request.remote_addr not in accepted_ips:
 
        current_app.logger.warn("Unallowed IP %s tried to update data!"
 
        current_app.logger.warn('Unallowed IP %s tried to update data!'
 
                                % ip)
 
        return 'IP not allowed!\n', 403, {'Content-Type': 'text/plain'}
 

	
 
    current_app.logger.info(str(json))
 
    server = update_server(server=json, ip=ip)
 

	
 
    if server:
 
        current_app.logger.info('Return result')
 
        current_app.logger.info(str(server))
 
        return (jsonify(server), 201,
 
                {'Location': '/api/export/json/single?server_name=%s'
 
                 % server['server_name']})
 

	
 
    else:
 
        current_app.logger.error("Unexpected error: %s" % server,
 
        current_app.logger.error('Unexpected error: %s' % server,
 
                                 exc_info=True)
 
        return abort(500)
 

	
 

	
 
@api_page.route('/export', defaults={'server_type': 'all',
 
                                     'export_format': 'json'})
 
@api_page.route('/export/<any("json", "xml"):export_format>',
 
                defaults={'server_type': 'all'})
 
@api_page.route(('/export/<any("json", "xml"):export_format>'
 
                 '/<any("all", "exit", "bridge", "relay", "single")'
 
                 ':server_type>'))
 
def export(export_format, server_type):
 

	
 
    current_app.logger.info('Handling export')
 
    if server_type == 'single':
 
        server_name = request.args.get('server_name', None)
 
        if server_name is not None:
 
            server = single_server(server_name)
 
            if server:
 
                if export_format == 'json':
 
                    current_app.logger.info('Returning server as json!')
 
                    return jsonify(server)
 
                else:
 
                    current_app.logger.info('Returning server as xml!')
ennstatus/donate/views.py
Show inline comments
 
@@ -47,42 +47,42 @@ def bpm():
 
def received():
 

	
 
    current_app.logger.info('Handling received')
 
    form = DateForm()
 

	
 
    current_app.logger.debug('Creating choices')
 
    choices = [name for name in get_choices()]
 
    choices.sort()
 
    form.date.choices = [(name, name) for name in choices]
 

	
 
    if not choices:
 
        current_app.logger.warn('No donations found!')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=None,
 
                               date=None)
 

	
 
    if request.method == 'POST':
 
        current_app.logger.debug('Validating form')
 
        if form.validate_on_submit():
 
            date = form.date.data
 
            return redirect(url_for('donate.received', date=date))
 
    else:
 
        if 'date' in request.args:
 
            date = request.args['date']
 
            if request.args['date'] in choices:
 
            if date in choices:
 
                current_app.logger.info('Showing date %s' % date)
 
                form.date.data = date
 
                csv_file = load_csv(date)
 
            else:
 
                current_app.logger.warn('Date %s not found' % date)
 
                return ('Date %s not found!' % date, 500,
 
                        {'Content-Type': 'text/plain'})
 
        else:
 
            current_app.logger.info('Showing last date %s' % choices[-1])
 
            form.date.data = choices[-1]
 
            csv_file = load_csv(choices[-1])
 
            date = choices[-1]
 

	
 
        current_app.logger.info('Return result')
 
        return render_template('donate/received.html',
 
                               form=form, csv_file=csv_file,
 
                               date=date)
ennstatus/log.py
Show inline comments
 
import logging
 
import logging.handlers
 

	
 

	
 
logging_debug_string = ("%(levelname)s:%(name)s:%(asctime)s:%(filename)s"
 
                        ":%(lineno)d: %(message)s")
 
logging_string = "%(levelname)s - %(name)s - %(asctime)s - %(message)s"
 
logging_debug_string = ('%(levelname)s:%(name)s:%(asctime)s:%(filename)s'
 
                        ':%(lineno)d: %(message)s')
 
logging_string = '%(levelname)s - %(name)s - %(asctime)s - %(message)s'
 
logging_debug_formatter = logging.Formatter(logging_debug_string)
 
logging_formatter = logging.Formatter(logging_string)
 

	
 

	
 
def init_logging(app):
 

	
 
    app.logger.setLevel(logging.DEBUG)
 
    stream_handler = logging.StreamHandler()
 
    stream_handler.setLevel(logging.DEBUG)
 
    stream_handler.setFormatter(logging_debug_formatter)
 

	
 
    rotating_file_handler = logging.handlers.RotatingFileHandler(
 
        'log/ennstatus.log',
 
        maxBytes=1300000,
 
        backupCount=10,
 
        encoding='utf-8')
 
    rotating_file_handler.setLevel(logging.INFO)
 
    rotating_file_handler.setFormatter(logging_formatter)
 

	
 
    if app.debug:
 
        second_rotating_file_handler = logging.handlers.RotatingFileHandler(
 
            'log/ennstatus_debug.log',
 
            maxBytes=1300000,
 
            backupCount=20,
 
            encoding='utf-8')
 
        second_rotating_file_handler.setLevel(logging.DEBUG)
 
        second_rotating_file_handler.setFormatter(logging_debug_formatter)
 
        app.logger.addHandler(second_rotating_file_handler)
 

	
 
    smtp_handler = logging.handlers.SMTPHandler(
 
        "localhost",
 
        "info@c3l.lu",
 
        'localhost',
 
        'info@c3l.lu',
 
        app.config.get('ENNSTATUS_ADMINS', None),
 
        "[Ennstatus] Error")
 
        '[Ennstatus] Error')
 
    smtp_handler.setLevel(logging.ERROR)
 
    smtp_handler.setFormatter(logging_formatter)
 

	
 
    app.logger.addHandler(stream_handler)
 
    app.logger.addHandler(rotating_file_handler)
ennstatus/status/functions.py
Show inline comments
 
@@ -4,49 +4,49 @@ import json
 

	
 
from collections import defaultdict
 
from datetime import datetime
 

	
 
from flask import current_app
 

	
 

	
 
def _check_server(data):
 

	
 
    if data['server_status'] == 'Offline':
 
        return data
 

	
 
    date = datetime.strptime(data['last_updated'], '%d-%m-%Y %H:%M:%S')
 
    now = datetime.utcnow()
 
    delta = now - date
 

	
 
    if delta.seconds >= 3600:
 
        status = 'Offline'
 
    elif delta.seconds >= 1200:
 
        status = 'Unknown'
 
    else:
 
        status = None
 

	
 
    if status is not None:
 
        current_app.logger.error("%s is set to %s" % (data['server_name'],
 
        current_app.logger.error('%s is set to %s' % (data['server_name'],
 
                                 status))
 
        for key in ('server_status', 'tor_status'):
 
            data[key] = status
 

	
 
    filename = os.path.join('data', data['server_name'].lower()+'.json')
 

	
 
    with open(filename, mode='w', encoding='utf-8') as file_object:
 
        json.dump(data, file_object)
 

	
 
    return data
 

	
 

	
 
def _load_single_server(filename):
 

	
 
    try:
 
        with open(filename, encoding='utf-8') as f:
 
            server = json.load(f)
 
    except IOError:
 
        return False
 

	
 
    server = _check_server(server)
 
    return server
 

	
 

	
setup.py
Show inline comments
 
@@ -13,39 +13,39 @@ def _get_requirements():
 
setup(name='Ennstatus',
 
      version='4.0.1',
 
      description=('Ennstatus provides the user with vital information about '
 
                   'the status of the organizations Tor servers.'),
 
      author='Frënn vun der Ënn',
 
      author_email='info@enn.lu',
 
      url='https://bitbucket.org/fvde/ennstatus',
 
      license="GPLv3+",
 
      packages=find_packages(),
 
      package_data={'ennstatus': ['static/css/*.css',
 
                                  'static/css/flags/img/png/*.png',
 
                                  'static/css/flags/img/gif/*.gif',
 
                                  'static/css/flags/*.css',
 
                                  'static/files/*',
 
                                  'static/images/*',
 
                                  'static/videos/*',
 
                                  'templates/*.html',
 
                                  'templates/api/extract/xml/*.xml',
 
                                  'templates/donate/*.html',
 
                                  'templates/root/*.html',
 
                                  'templates/status/*.html',
 
                                  'templates/stats/*.html'
 
                                  ]},
 
      install_requires=_get_requirements(),
 
      classifiers=["Development Status :: 5 - Production/Stable",
 
                   "Environment :: Web Environment",
 
                   "Operating System :: POSIX",
 
                   "Programming Language :: Python",
 
                   "Programming Language :: Python :: 2",
 
                   "Programming Language :: Python :: 2.7",
 
                   "Topic :: Internet",
 
                   "Topic :: Internet :: WWW/HTTP",
 
                   "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
 
                   "Topic :: Internet :: WWW/HTTP :: WSGI",
 
                   "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
 
                   ("License :: OSI Approved :: "
 
                    "GNU General Public License v3 or later (GPLv3+)"),
 
      classifiers=['Development Status :: 5 - Production/Stable',
 
                   'Environment :: Web Environment',
 
                   'Operating System :: POSIX',
 
                   'Programming Language :: Python',
 
                   'Programming Language :: Python :: 3',
 
                   'Programming Language :: Python :: 3.3',
 
                   'Topic :: Internet',
 
                   'Topic :: Internet :: WWW/HTTP',
 
                   'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
 
                   'Topic :: Internet :: WWW/HTTP :: WSGI',
 
                   'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
 
                   ('License :: OSI Approved :: '
 
                    'GNU General Public License v3 or later (GPLv3+)'),
 
                   ]
 
      )
0 comments (0 inline, 0 general)