aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-07 22:03:50 +0200
committerCédric Bonhomme <cedric@cedricbonhomme.org>2016-04-07 22:03:50 +0200
commitb70ae0e1dd2b21e1257a6894d0c3977bb02cc251 (patch)
tree65d7ffd95283c74bf2828c20dbc23aef0e224d2f
parentWon't use munin. (diff)
downloadnewspipe-b70ae0e1dd2b21e1257a6894d0c3977bb02cc251.tar.gz
newspipe-b70ae0e1dd2b21e1257a6894d0c3977bb02cc251.tar.bz2
newspipe-b70ae0e1dd2b21e1257a6894d0c3977bb02cc251.zip
Minor updates in the manager.
-rwxr-xr-xsrc/manager.py34
-rw-r--r--src/web/models/__init__.py15
2 files changed, 21 insertions, 28 deletions
diff --git a/src/manager.py b/src/manager.py
index b6ff87a0..d5e91d70 100755
--- a/src/manager.py
+++ b/src/manager.py
@@ -1,11 +1,17 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
-from bootstrap import application, db, populate_g, conf
+import os
+import logging
+from werkzeug import generate_password_hash
+from bootstrap import application, db, conf
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
import web.models
+from web.controllers import FeedController, UserController
+
+logger = logging.getLogger(__name__)
Migrate(application, db)
@@ -17,16 +23,20 @@ manager.add_command('db', MigrateCommand)
def db_empty():
"Will drop every datas stocked in db."
with application.app_context():
- populate_g()
web.models.db_empty(db)
@manager.command
def db_create():
"Will create the database from conf parameters."
+ admin = {'is_admin': True, 'is_api': True, 'is_active': True,
+ 'nickname': 'admin',
+ 'pwdhash': generate_password_hash(
+ os.environ.get("ADMIN_PASSWORD", "password")),
+ 'email': os.environ.get("ADMIN_EMAIL", "root@jarr.localhost")}
with application.app_context():
- populate_g()
- web.models.db_create(db)
+ db.create_all()
+ UserController(ignore_context=True).create(**admin)
@manager.command
@@ -44,18 +54,17 @@ def fetch_asyncio(user_id, feed_id):
import asyncio
with application.app_context():
- populate_g()
- from flask import g
- from web.models import User
+ from flask.ext.login import current_user
from crawler import classic_crawler
+ ucontr = UserController()
users = []
try:
- users = User.query.filter(User.id == int(user_id)).all()
+ users = [ucontr.get(user_id)]
except:
- users = User.query.all()
+ users = ucontr.read()
finally:
if users == []:
- users = User.query.all()
+ users = ucontr.read()
try:
feed_id = int(feed_id)
@@ -65,9 +74,8 @@ def fetch_asyncio(user_id, feed_id):
loop = asyncio.get_event_loop()
for user in users:
if user.is_active:
- print("Fetching articles for " + user.nickname)
- g.user = user
- classic_crawler.retrieve_feed(loop, g.user, feed_id)
+ logger.info("Fetching articles for " + user.nickname)
+ classic_crawler.retrieve_feed(loop, user, feed_id)
loop.close()
diff --git a/src/web/models/__init__.py b/src/web/models/__init__.py
index 7c50cab3..260f3263 100644
--- a/src/web/models/__init__.py
+++ b/src/web/models/__init__.py
@@ -83,18 +83,3 @@ def db_empty(db):
conn.execute(DropTable(table))
trans.commit()
-
-def db_create(db):
- "Will create the database from conf parameters."
- db.create_all()
-
- user1 = User(nickname="admin",
- email=os.environ.get("ADMIN_EMAIL",
- "root@jarr.localhost"),
- pwdhash=generate_password_hash(
- os.environ.get("ADMIN_PASSWORD", "password")),
- is_admin=True)
-
- db.session.add(user1)
- db.session.commit()
- return user1
bgstack15