move package root
This commit is contained in:
parent
c6f1e8b82e
commit
7e8930faba
19 changed files with 37 additions and 119 deletions
1
stacosys/__init__.py
Normal file
1
stacosys/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
__version__ = '1.1.0'
|
||||
0
stacosys/conf/__init__.py
Normal file
0
stacosys/conf/__init__.py
Normal file
0
stacosys/core/__init__.py
Normal file
0
stacosys/core/__init__.py
Normal file
|
|
@ -6,10 +6,10 @@ import re
|
|||
import time
|
||||
from datetime import datetime
|
||||
|
||||
from core import mailer, rss
|
||||
from core.templater import get_template
|
||||
from model.comment import Comment, Site
|
||||
from model.email import Email
|
||||
from stacosys.core import mailer, rss
|
||||
from stacosys.core.templater import get_template
|
||||
from stacosys.model.comment import Comment, Site
|
||||
from stacosys.model.email import Email
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
from playhouse.db_url import connect
|
||||
|
||||
from conf import config
|
||||
from stacosys.conf import config
|
||||
|
||||
|
||||
def get_db():
|
||||
|
|
@ -11,7 +11,7 @@ def get_db():
|
|||
|
||||
|
||||
def setup():
|
||||
from model.site import Site
|
||||
from model.comment import Comment
|
||||
from stacosys.model.site import Site
|
||||
from stacosys.model.comment import Comment
|
||||
|
||||
get_db().create_tables([Site, Comment], safe=True)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import imaplib
|
|||
import logging
|
||||
import re
|
||||
|
||||
from model.email import Attachment, Email, Part
|
||||
from stacosys.model.email import Attachment, Email, Part
|
||||
|
||||
filename_re = re.compile('filename="(.+)"|filename=([^;\n\r"\']+)', re.I | re.S)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ from email.mime.text import MIMEText
|
|||
|
||||
import requests
|
||||
|
||||
from conf import config
|
||||
from core import imap
|
||||
from model.email import Email
|
||||
from stacosys.conf import config
|
||||
from stacosys.core import imap
|
||||
from stacosys.model.email import Email
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ from datetime import datetime
|
|||
import markdown
|
||||
import PyRSS2Gen
|
||||
|
||||
from conf import config
|
||||
from core.templater import get_template
|
||||
from model.comment import Comment
|
||||
from model.site import Site
|
||||
from stacosys.conf import config
|
||||
from stacosys.core.templater import get_template
|
||||
from stacosys.model.comment import Comment
|
||||
from stacosys.model.site import Site
|
||||
|
||||
|
||||
def generate_all():
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import os
|
|||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from conf import config
|
||||
from stacosys.conf import config
|
||||
|
||||
current_path = os.path.dirname(__file__)
|
||||
template_path = os.path.abspath(os.path.join(current_path, '../templates'))
|
||||
|
|
|
|||
0
stacosys/interface/__init__.py
Normal file
0
stacosys/interface/__init__.py
Normal file
|
|
@ -5,9 +5,9 @@ import logging
|
|||
|
||||
from flask import abort, jsonify, request
|
||||
|
||||
from conf import config
|
||||
from model.comment import Comment
|
||||
from model.site import Site
|
||||
from stacosys.conf import config
|
||||
from stacosys.model.comment import Comment
|
||||
from stacosys.model.site import Site
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
app = config.flaskapp()
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ from datetime import datetime
|
|||
|
||||
from flask import abort, redirect, request
|
||||
|
||||
from conf import config
|
||||
from model.comment import Comment
|
||||
from model.site import Site
|
||||
from stacosys.conf import config
|
||||
from stacosys.model.comment import Comment
|
||||
from stacosys.model.site import Site
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
app = config.flaskapp()
|
||||
|
|
|
|||
0
stacosys/model/__init__.py
Normal file
0
stacosys/model/__init__.py
Normal file
|
|
@ -6,8 +6,8 @@ from peewee import CharField
|
|||
from peewee import TextField
|
||||
from peewee import DateTimeField
|
||||
from peewee import ForeignKeyField
|
||||
from model.site import Site
|
||||
from core.database import get_db
|
||||
from stacosys.model.site import Site
|
||||
from stacosys.core.database import get_db
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
from peewee import Model
|
||||
from peewee import CharField
|
||||
from core.database import get_db
|
||||
from stacosys.core.database import get_db
|
||||
|
||||
|
||||
class Site(Model):
|
||||
|
|
|
|||
105
stacosys/run.py
105
stacosys/run.py
|
|
@ -1,105 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
from flask import Flask
|
||||
from flask_apscheduler import APScheduler
|
||||
|
||||
from conf import config
|
||||
|
||||
|
||||
# configure logging
|
||||
def configure_logging(level):
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.setLevel(level)
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(level)
|
||||
# create formatter
|
||||
formatter = logging.Formatter('[%(asctime)s] %(name)s %(levelname)s %(message)s')
|
||||
# add formatter to ch
|
||||
ch.setFormatter(formatter)
|
||||
# add ch to logger
|
||||
root_logger.addHandler(ch)
|
||||
|
||||
|
||||
class JobConfig(object):
|
||||
|
||||
JOBS = []
|
||||
|
||||
SCHEDULER_EXECUTORS = {'default': {'type': 'threadpool', 'max_workers': 4}}
|
||||
|
||||
def __init__(self, imap_polling_seconds, new_comment_polling_seconds):
|
||||
self.JOBS = [
|
||||
{
|
||||
'id': 'fetch_mail',
|
||||
'func': 'core.cron:fetch_mail_answers',
|
||||
'trigger': 'interval',
|
||||
'seconds': imap_polling_seconds,
|
||||
},
|
||||
{
|
||||
'id': 'submit_new_comment',
|
||||
'func': 'core.cron:submit_new_comment',
|
||||
'trigger': 'interval',
|
||||
'seconds': new_comment_polling_seconds,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def stacosys_server(config_pathname):
|
||||
|
||||
app = Flask(__name__)
|
||||
config.initialize(config_pathname, app)
|
||||
|
||||
# configure logging
|
||||
logger = logging.getLogger(__name__)
|
||||
configure_logging(logging.INFO)
|
||||
logging.getLogger('werkzeug').level = logging.WARNING
|
||||
logging.getLogger('apscheduler.executors').level = logging.WARNING
|
||||
|
||||
# initialize database
|
||||
from core import database
|
||||
|
||||
database.setup()
|
||||
|
||||
# cron email fetcher
|
||||
app.config.from_object(
|
||||
JobConfig(
|
||||
config.get_int(config.IMAP_POLLING), config.get_int(config.COMMENT_POLLING)
|
||||
)
|
||||
)
|
||||
scheduler = APScheduler()
|
||||
scheduler.init_app(app)
|
||||
scheduler.start()
|
||||
|
||||
logger.info('Start Stacosys application')
|
||||
|
||||
# generate RSS for all sites
|
||||
from core import rss
|
||||
|
||||
rss.generate_all()
|
||||
|
||||
# start Flask
|
||||
from interface import api
|
||||
|
||||
logger.info('Load interface %s' % api)
|
||||
|
||||
from interface import form
|
||||
|
||||
logger.info('Load interface %s' % form)
|
||||
|
||||
app.run(
|
||||
host=config.get(config.HTTP_HOST),
|
||||
port=config.get(config.HTTP_PORT),
|
||||
debug=False,
|
||||
use_reloader=False,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('config', help='config path name')
|
||||
args = parser.parse_args()
|
||||
stacosys_server(args.config)
|
||||
Loading…
Add table
Add a link
Reference in a new issue