コード例 #1
0
def backup_dumps(back_path):
    from app import createApp
    from models.cluster_model import ClusterModel

    with createApp().app_context(), open(back_path, 'w') as fout:
        print('backup export start...')
        all = ClusterModel.query.all()
        if all:
            for item in all:
                itemDict = {}
                itemDict['name'] = item.name
                itemDict['sampleLanguage'] = item.sampleLanguage
                itemDict['status'] = 0
                itemDict['description'] = item.description
                itemDict['pathInfo'] = item.pathInfo
                itemDict['filterInfo'] = item.filterInfo
                itemDict['excludeWords'] = item.excludeWords
                itemDict['similarity'] = item.similarity
                itemDict['uid'] = item.uid
                itemDict['cid'] = item.cid
                itemDict['hierarchiceUuid'] = item.hierarchiceUuid
                itemDict['ctime'] = time.mktime(item.ctime.timetuple())
                itemDict['utime'] = time.mktime(item.utime.timetuple())
                fout.write(json.dumps(itemDict) + '\n')
        print('backup export end')
コード例 #2
0
    def setUp(self):
        self.app = createApp()
        self.appContext = self.app.app_context()
        self.appContext.push()
        db.create_all()

        ipSpider = IpSpider()
        ipSpider.saveToSql()
コード例 #3
0
 def setUp(self):
     """Set up application for the tests"""
     # print(os.environ.get('MYSQL_PASSWORD'))
     self.app = createApp(TestConfig)
     self.appContext = self.app.app_context()
     self.appContext.push()
     self.testApp = self.app.test_client()
     self._savepointContext = transactionContext(self)
     # the context has member of enter or exist
     self._savepointContext.__enter__()  # pylint: disable=maybe-no-member
コード例 #4
0
    def createRoom(self, appName):
        '''
        Create a room for given game type and return the room number.
        Return -1 if the given game doesn't exist
        '''

        if app.haveApp(appName):
            self.current_number += 1
            self.roomDict[self.current_number] = app.createApp(
                appName, self.textManager)
            return self.current_number

        return -1
コード例 #5
0
 def setUp(self):
     self.app = createApp('development')
     self.client = self.app.test_client
     self.user = {
         'id': 1,
         'email': 'email@',
         'username': '******',
         'password': '******'
     }
     self.user2 = {'id': 1, 'username': '******', 'password': '******'}
     self.user3 = {'id': 1, 'email': 'emai@gma', 'username': '******'}
     self.event1 = {
         "eventid": 1,
         "userid": 2,
         "name": "Partymad",
         "location": "Nairobu",
         "description": "here and 2",
         "date": "10/10/2017",
         "cost": 2000
     }
     self.event2 = {
         "eventid": 1,
         "userid": 2,
         "name": "Partymad",
         "description": "here and 2",
         "date": "10/10/2017",
         "cost": 2000
     }
     self.event3 = {
         "eventid": 1,
         "userid": 2,
         "location": "Nairobu",
         "description": "here and 2",
         "date": "10/10/2017",
         "cost": 2000
     }
     self.event4 = {
         "eventid": 1,
         "name": "Partymad",
         "location": "Nairobu",
         "description": "here and 2",
         "date": "10/10/2017",
         "cost": 2000
     }
コード例 #6
0
def backup_loads(back_path):
    from app import createApp
    from models import db
    from models.cluster_model import ClusterModel
    from models.cluster_file_model import ClusterFileModel
    from models.cluster_cat_name_model import ClusterCatNameModel

    with createApp().app_context(), open(back_path, 'r') as fin:
        print('backup import start...')
        all = ClusterModel.query.all()
        if all:
            for item in all:
                clusterPath = os.path.join(WORK_PATH, str(item.id))
                if os.path.exists(clusterPath):
                    shutil.rmtree(clusterPath)
        ClusterModel.query.filter().delete()
        ClusterFileModel.query.filter().delete()
        ClusterCatNameModel.query.filter().delete()
        for line in fin:
            line = line.strip('\n')
            itemDict = json.loads(line)
            model = ClusterModel()
            model.name = itemDict.get('name')
            model.sampleLanguage = itemDict.get('sampleLanguage')
            model.status = itemDict.get('status')
            model.description = itemDict.get('description')
            model.pathInfo = itemDict.get('pathInfo')
            model.filterInfo = itemDict.get('filterInfo')
            model.excludeWords = itemDict.get('excludeWords')
            model.similarity = itemDict.get('similarity')
            model.uid = itemDict.get('uid')
            model.cid = itemDict.get('cid')
            model.hierarchiceUuid = itemDict.get('hierarchiceUuid')
            model.ctime = datetime.datetime.fromtimestamp(
                itemDict.get('utime'))
            model.utime = datetime.datetime.fromtimestamp(
                itemDict.get('utime'))
            db.session.add(model)
            db.session.commit()
        print('backup import end')
コード例 #7
0
 def setUp(self):
     self.app = createApp(configName="testing")
     self.appContext = self.app.app_context()
     self.appContext.push()
     db.create_all()
コード例 #8
0
ファイル: manager.py プロジェクト: zippies/websnail
from app import createApp,db
from flask import render_template,flash,redirect,url_for
from app.models import *
from flask.ext.script import Manager,Shell
from flask.ext.migrate import Migrate,MigrateCommand
from werkzeug.contrib.fixers import ProxyFix

app = createApp('testing')
app.wsgi_app = ProxyFix(app.wsgi_app)
manager = Manager(app)
migrate = Migrate(app,db)
manager.add_command('db',MigrateCommand)

@manager.command
def dbinit():
	db.create_all()
	print('ok')


@manager.command
def dbdrop():
	db.drop_all()
	print('ok')

@app.errorhandler(404)
def page_not_found(e):
	return render_template('404.html'),404

@app.errorhandler(401)
def unauthorized(e):
	flash({"type":"info","message":"请登陆后访问!"})
コード例 #9
0
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from config import mapping_config
from app import createApp
from app import db


app = createApp(mapping_config['dev'])
# 扩展
manager = Manager(app)
Migrate(app, db)
manager.add_command('db', MigrateCommand)

import www
if __name__ == '__main__':
    # app.run()
    manager.run()
コード例 #10
0
ファイル: wsgi.py プロジェクト: seniortesting/python-spider
# -*- coding:utf-8 -*-
from werkzeug.middleware.proxy_fix import ProxyFix

from app import createApp
import app.config as config

# production app server instance
app = createApp(config=config.ProdConfig)
app.wsgi_app = ProxyFix(app.wsgi_app)
コード例 #11
0
from app import createApp, db
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from flask_cors import CORS

app = createApp("product")

manage = Manager(app)
Migrate(app, db)
manage.add_command('db', MigrateCommand)

CORS(app, supports_credentials=True)

if __name__ == '__main__':
    manage.run()
コード例 #12
0
from app import createApp
from app.ext import db

app = createApp()
app.app_context().push()
db.drop_all()
コード例 #13
0
ファイル: Launcher.py プロジェクト: ninotorres9/Squirrel
# -*- coding: utf-8 -*-

from flask import redirect, url_for, render_template
from flask_script import Manager, Shell
from app import createApp

app = createApp("default")
launcher = Manager(app)


@launcher.command
def test():
    """
        执行单元测试
    """
    import unittest
    tests = unittest.TestLoader().discover("tests")
    unittest.TextTestRunner(verbosity=2).run(tests)


@app.route("/")
def index():
    return redirect(url_for("news.index"))


def main():
    # pass
    launcher.run()
    # test()

コード例 #14
0
def startServer(localSettings='localSettings',
                appPort=7000,
                logFilename="logFile.log"):
    global theApp
    bufferSize = 64 * 1024
    password = str(
        snowflake.make_snowflake(
            snowflake_file=os.path.join(base_dir, 'snowflake')))
    manager = multiprocessing.Manager()
    servers = manager.list()
    workers = manager.list()
    backupInfo = manager.dict()
    for i in range(0, 10000):
        workers.append(-1)
    if os.path.isfile(os.path.join(base_dir, 'secretEnc')):
        pyAesCrypt.decryptFile(os.path.join(base_dir, "secretEnc"),
                               os.path.join(base_dir, "secretPlain"), password,
                               bufferSize)
        file = open(os.path.join(base_dir, "secretPlain"), 'r')
        aList = json.load(file)
        for server in aList:
            servers.append(server)
        file.close()
        os.remove(os.path.join(base_dir, "secretPlain"))
    if os.path.isabs(localSettings):
        setFile = localSettings
    else:
        setFile = os.path.join(base_dir, localSettings)
    globals = setupLocalSettings(setFile)
    theApp = app.createApp(theServers=servers, theWorkers=workers)
    p = multiprocessing.Process(target=backupServer.startBackup,
                                args=(os.path.join(base_dir, 'static',
                                                   'rsync'), backupInfo,
                                      setFile))
    p.start()
    multiprocesses.append({
        'name': 'Backup',
        'pid': p.pid,
        'description': 'DAQBroker backup process'
    })
    time.sleep(1)
    p = multiprocessing.Process(target=logServer.logServer,
                                args=(globals["logport"], base_dir),
                                kwargs={'logFilename': logFilename})
    p.start()
    multiprocesses.append({
        'name': 'Logger',
        'pid': p.pid,
        'description': 'DAQBroker log process'
    })
    time.sleep(1)
    p = multiprocessing.Process(target=commServer.collector,
                                args=(servers, globals["commport"],
                                      globals["logport"], backupInfo, setFile))
    p.start()
    multiprocesses.append({
        'name': 'Collector',
        'pid': p.pid,
        'description': 'DAQBroker message collector process'
    })
    time.sleep(1)
    p = multiprocessing.Process(target=monitorServer.producer,
                                args=(servers, globals["commport"],
                                      globals["logport"], False, backupInfo,
                                      workers, setFile))
    p.start()
    multiprocesses.append({
        'name':
        'Producer',
        'pid':
        p.pid,
        'description':
        'DAQBroker broadcasting server process'
    })
    time.sleep(1)
    print("STARTED", multiprocesses)
    http_server = HTTPServer(WSGIContainer(theApp))
    http_server.listen(appPort)
    webbrowser.open('http://localhost:' + str(appPort) + "/daqbroker")
    IOLoop.instance().start()
コード例 #15
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-08-10 08:52:48
# @Author  : Wangmengcn ([email protected])
# @Link    : https://eclipsesv.com
# @Version : $Id$
from app import createApp

running = createApp('default')

# 将flask的访问方式改为https,需要用openssl生成mygit.crt, mygit.key
if __name__ == '__main__':
    context = ('mygit.crt', 'mygit.key')
    running.run(ssl_context=context, threaded=True)
コード例 #16
0
 def setUp(self):  #测试前运行
     self.app = createApp('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
コード例 #17
0
 def setUp(self):
     app = createApp(TestConfig())
     app.app_context().push()
     db.create_all()
コード例 #18
0
ファイル: server.py プロジェクト: dnjsakf/crawl_community
from app import createApp

if __name__ == '__main__':
    server = createApp('dev')
    server.run(host='0.0.0.0', port='3000')
コード例 #19
0
ファイル: server.py プロジェクト: jod75/ics5200
def runServer(app):

    # Enable WSGI access logging via Paste
    appLogged = TransLogger(app)

    # Mount the WSGI callable object (app) on the root directory
    cherrypy.tree.graft(appLogged, '/')

    # Set the configuration of the web server
    cherrypy.config.update({
        'engine.autoreload.on': True,
        'log.screen': True,
        'server.socket_port': 5432,
        'server.socket_host': 'hadoop1'
    })

    # Start the CherryPy WSGI web server
    cherrypy.engine.start()
    cherrypy.engine.block()


if __name__ == "__main__":
    # Init spark context and load libraries
    sc = initSparkContext()
    dataset_path = ''  # os.path.join('datasets', 'ml-latest')
    app = createApp(sc, dataset_path)

    # start web server
    runServer(app)
コード例 #20
0
import app
import config
import entities
import intents
import phraselists
import train
import utterances

if __name__ == "__main__":
    configData = config.getConfig()

    if configData["appID"] == "None":
        app.createApp()
    else:
        application = app.getApplication()
        if application:
            print "Application Found"
        else:
            print "No application with that ID exists"
            if raw_input("Create New Application? (Y/N):").lower() == "y":
                app.createApp()
                application = app.getApplication()
            else:
                print "Cancelled"

    if application:
        #### Handle Intents #####

        # Get list of existing intents of the application
        existingIntents = intents.getExistingIntents()
        existingIntentsSet = set(
コード例 #21
0
ファイル: TestUser.py プロジェクト: ninotorres9/Squirrel
 def setUp(self):
     self.app = createApp("testing")
     self.appContext = self.app.app_context()
     self.appContext.push()
     db.create_all()
     Role.insertRoles()
コード例 #22
0
# -*- coding: utf-8 -*-
from os import getenv
from dotenv import load_dotenv
from os.path import dirname, isfile, join

# a partir do arquivo atual adicione ao path o arquivo .env
_ENV_FILE = join(dirname(__file__), '.env')

# existindo o arquivo faça a leitura do arquivo através da função load_dotenv
if isfile(_ENV_FILE):
  load_dotenv(dotenv_path=_ENV_FILE)


from app import createApp

# instancia nossa função factory criada anteriormente
app = createApp(getenv('FLASK_ENV') or 'default')

if __name__ == '__main__':
  ip = '0.0.0.0'
  port = app.config['APP_PORT']
  debug = app.config['DEBUG']

  # executa o servidor web do flask
  app.run(
    host=ip, debug=debug, port=port, use_reloader=debug
  )
コード例 #23
0
ファイル: cli.py プロジェクト: ThePorcupine/shaba
from app import createApp
import os

app = createApp(os.getenv('FLASK_CONFIG') or 'default')
コード例 #24
0
import click
from flask import current_app
from flask_migrate import Migrate, upgrade
from sqlalchemy import create_engine
from app import createApp, db
from app.models import Area, Element, ElementAttribute, ElementAttributeTemplate, ElementTemplate, Enterprise, EventFrame, EventFrameAttribute, \
 EventFrameAttributeTemplate, EventFrameAttributeTemplateEventFrameTemplateView, EventFrameEventFrameGroup, EventFrameGroup, EventFrameNote, \
 EventFrameTemplate, EventFrameTemplateView, Lookup, LookupValue, Message, Note, Role, Site, Tag, TagValue, TagValueNote, UnitOfMeasurement, User

application = app = createApp()
migrate = Migrate(app, db, directory="db/migrations")


@app.shell_context_processor
def make_shell_context():
    return dict(app=app,
                db=db,
                Area=Area,
                Element=Element,
                ElementAttribute=ElementAttribute,
                ElementAttributeTemplate=ElementAttributeTemplate,
                ElementTemplate=ElementTemplate,
                Enterprise=Enterprise,
                EventFrame=EventFrame,
                EventFrameAttribute=EventFrameAttribute,
                EventFrameAttributeTemplate=EventFrameAttributeTemplate,
                EventFrameAttributeTemplateEventFrameTemplateView=
                EventFrameAttributeTemplateEventFrameTemplateView,
                EventFrameEventFrameGroup=EventFrameEventFrameGroup,
                EventFrameGroup=EventFrameGroup,
                EventFrameNote=EventFrameNote,
コード例 #25
0
ファイル: manage.py プロジェクト: mukjos30/News_Articles
from app import createApp
from flask_script import Manager, Server

app = createApp('development')

manager = Manager(app)
manager.add_command('server', Server)


@manager.command
def test():
    """Run the unit tests."""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == '__main__':
    manager.run()
コード例 #26
0
from app import createApp

if __name__ == "__main__":
	app = createApp()
	app.run(host = "0.0.0.0", port = "6003", debug = True)
コード例 #27
0
ファイル: serve.py プロジェクト: seniortesting/python-spider
# -*- coding:utf-8 -*-
from app import createApp, config

app = createApp(config=config.DevConfig)
コード例 #28
0
ファイル: server.py プロジェクト: dnjsakf/cra_flask
import app

server = app.createApp('dev')
server.run( host='0.0.0.0', port='3000' )
コード例 #29
0
from app import createApp, db
from flask import render_template, flash, redirect, url_for
from app.models import *
from flask.ext.script import Manager, Shell
from flask.ext.migrate import Migrate, MigrateCommand
from werkzeug.contrib.fixers import ProxyFix

app = createApp('testing')
app.wsgi_app = ProxyFix(app.wsgi_app)
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)


@manager.command
def dbinit():
    db.create_all()
    print('ok')


@manager.command
def dbdrop():
    db.drop_all()
    print('ok')


@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404