コード例 #1
0
ファイル: layer.py プロジェクト: izrik/tudor
    def users(self, request, current_user):
        if request.method == 'GET':
            users = self.ll.get_users()
            return self.render_template('list_users.t.html',
                                        users=users,
                                        cycle=itertools.cycle)

        email = request.form['email']
        is_admin = False
        if 'is_admin' in request.form:
            is_admin = bool_from_str(request.form['is_admin'])

        self.ll.do_add_new_user(email, is_admin)

        return self.redirect(self.url_for('list_users'))
コード例 #2
0
ファイル: tudor.py プロジェクト: izrik/tudor
 def from_environ():
     debug = environ.get('TUDOR_DEBUG')
     if debug is not None:
         debug = bool_from_str(debug)
     return Config(
         debug=debug,
         host=environ.get('TUDOR_HOST'),
         port=int_from_str(environ.get('TUDOR_PORT')),
         db_uri=environ.get('TUDOR_DB_URI'),
         db_uri_file=environ.get('TUDOR_DB_URI_FILE'),
         db_options=environ.get('TUDOR_DB_OPTIONS'),
         db_options_file=environ.get('TUDOR_DB_OPTIONS_FILE'),
         upload_folder=environ.get('TUDOR_UPLOAD_FOLDER'),
         allowed_extensions=environ.get('TUDOR_ALLOWED_EXTENSIONS'),
         secret_key=environ.get('TUDOR_SECRET_KEY'),
         secret_key_file=environ.get('TUDOR_SECRET_KEY_FILE'))
コード例 #3
0
ファイル: test_conversions.py プロジェクト: izrik/tudor
    def test_bool_from_str(self):
        # true, unsurprising
        self.assertTrue(bool_from_str('True'))
        self.assertTrue(bool_from_str('true'))
        self.assertTrue(bool_from_str('tRuE'))
        self.assertTrue(bool_from_str('t'))
        self.assertTrue(bool_from_str('1'))
        self.assertTrue(bool_from_str('y'))

        # true, surprising
        self.assertTrue(bool_from_str('tr'))
        self.assertTrue(bool_from_str('tru'))
        self.assertTrue(bool_from_str('truee'))
        self.assertTrue(bool_from_str('ye'))
        self.assertTrue(bool_from_str('yes'))

        # false, unsurprising
        self.assertFalse(bool_from_str('False'))
        self.assertFalse(bool_from_str('false'))
        self.assertFalse(bool_from_str('fAlSe'))
        self.assertFalse(bool_from_str('f'))
        self.assertFalse(bool_from_str('0'))
        self.assertFalse(bool_from_str('n'))

        # false, surprising
        self.assertTrue(bool_from_str('no'))
        self.assertTrue(bool_from_str('fa'))
        self.assertTrue(bool_from_str('fal'))
        self.assertTrue(bool_from_str('fals'))
        self.assertTrue(bool_from_str('falsee'))

        # true, non-string, somewhat surprising
        self.assertTrue(bool_from_str(1))
        self.assertTrue(bool_from_str([1]))
        self.assertTrue(bool_from_str([False]))

        # false, non-string
        self.assertFalse(bool_from_str([]))
        self.assertFalse(bool_from_str(''))
        self.assertFalse(bool_from_str(None))
コード例 #4
0
ファイル: sawmill.py プロジェクト: izrik/sawmill
        json = request.get_json()
        timestamp = json['@timestamp']
        server = json['host']
        log_name = json['source']
        message = json['message']
        le = LogEntry(timestamp, server, log_name, message)
        db.session.add(le)
        db.session.commit()
        return ('', 204)

    return app


if __name__ == '__main__':

    SAWMILL_DEBUG = bool_from_str(
        environ.get('SAWMILL_DEBUG', DEFAULT_SAWMILL_DEBUG))
    SAWMILL_PORT = environ.get('SAWMILL_PORT', DEFAULT_SAWMILL_PORT)
    try:
        SAWMILL_PORT = int(SAWMILL_PORT)
    except:
        SAWMILL_PORT = DEFAULT_SAWMILL_PORT
    SAWMILL_DB_URI = environ.get('SAWMILL_DB_URI', DEFAULT_SAWMILL_DB_URI)
    SAWMILL_SECRET_KEY = environ.get('SAWMILL_SECRET_KEY')

    parser = argparse.ArgumentParser()
    parser.add_argument('--debug', action='store_true', default=SAWMILL_DEBUG)
    parser.add_argument('--port', action='store', default=SAWMILL_PORT,
                        type=int)
    parser.add_argument('--create-db', action='store_true')
    parser.add_argument('--db-uri', action='store', default=SAWMILL_DB_URI)
    parser.add_argument('--secret-key', action='store',
コード例 #5
0
ファイル: tudor.py プロジェクト: izrik/tudor
def main(argv):
    arg_config = get_config_from_command_line(argv)

    arg_config.DB_URI = get_db_uri(arg_config.DB_URI, arg_config.DB_URI_FILE)
    arg_config.DB_OPTIONS = get_db_options(arg_config.DB_OPTIONS,
                                           arg_config.DB_OPTIONS_FILE)
    arg_config.SECRET_KEY = get_secret_key(arg_config.SECRET_KEY,
                                           arg_config.SECRET_KEY_FILE)

    arg_config = Config.combine(arg_config, Config.from_defaults())

    print(f'__version__: {__version__}', file=sys.stderr)
    print(f'__revision__: {__revision__}', file=sys.stderr)
    print(f'DEBUG: {arg_config.DEBUG}', file=sys.stderr)
    print(f'HOST: {arg_config.HOST}', file=sys.stderr)
    print(f'PORT: {arg_config.PORT}', file=sys.stderr)
    print(f'UPLOAD_FOLDER: {arg_config.UPLOAD_FOLDER}', file=sys.stderr)
    print(f'ALLOWED_EXTENSIONS: {arg_config.ALLOWED_EXTENSIONS}',
          file=sys.stderr)
    if arg_config.DEBUG:
        print(f'DB_URI: {arg_config.DB_URI}', file=sys.stderr)
        print(f'DB_OPTIONS: {arg_config.DB_OPTIONS}', file=sys.stderr)
        print(f'SECRET_KEY: {arg_config.SECRET_KEY}', file=sys.stderr)

    app = generate_app(db_uri=arg_config.DB_URI,
                       db_options=arg_config.DB_OPTIONS,
                       upload_folder=arg_config.UPLOAD_FOLDER,
                       secret_key=arg_config.SECRET_KEY,
                       allowed_extensions=arg_config.ALLOWED_EXTENSIONS)

    args = arg_config.args

    if args.create_db:
        print('Setting up the database')
        app.pl.create_all()
    elif args.create_secret_key:
        digits = '0123456789abcdef'
        key = ''.join((random.choice(digits) for x in range(48)))
        print(key)
    elif args.hash_password is not None:
        print(app.bcrypt.generate_password_hash(args.hash_password).decode())
    elif args.make_public is not None:
        make_task_public(app.pl, args.make_public,
                         descendants=args.descendants)
    elif args.make_private is not None:
        make_task_private(app.pl, args.make_private,
                          descendants=args.descendants)
    elif args.test_db_conn:
        test_db_conn(app.pl, args.debug)
    elif args.create_user:
        email = args.create_user[0]
        hashed_password = args.create_user[1]
        is_admin = False
        if len(args.create_user) > 2 and bool_from_str(args.create_user[2]):
            is_admin = True
        create_user(app.pl, email=email, hashed_password=hashed_password,
                    is_admin=is_admin)
    elif args.export_db:
        with app.app_context():
            types_to_export = ('tasks', 'tags', 'notes', 'attachments',
                               'users', 'options')
            result = app.ll.do_export_data(types_to_export)
            import json
            print(json.dumps(result))
    elif args.import_db:
        with app.app_context():
            import json
            data = json.load(sys.stdin)
            app.ll.do_import_data(data)
            print('Finished')
    else:
        app.run(debug=arg_config.DEBUG, host=arg_config.HOST,
                port=arg_config.PORT)