def run(self, *a, **ka): if not 'debug' in ka: ka['debug'] = self.debug if not 'host' in ka: ka['host'] = conf.get('backend', 'host') if not 'port' in ka: ka['port'] = conf.get('backend', 'port') return self.app.run(*a, **ka)
def run(self, *a, **ka): if not 'debug' in ka: ka['debug'] = self.debug if not 'host' in ka: ka['host'] = conf.get('backend', 'host') if not 'port' in ka: ka['port'] = conf.get('backend', 'port') return self.app.run(*a, **ka)
def client(): uri = u'mongodb://%s' % conf.get('db.mongo', 'host') port = conf.get('db.mongo', 'port') if port is not None and port != '': port = int(port) uri = u'%s:%s' % (uri, port) log.info('> Connect %s', uri) return MongoClient(uri)
def client(): uri = u'mongodb://%s' % conf.get('db.mongo', 'host') port = conf.get('db.mongo', 'port') if port is not None and port != '': port = int(port) uri = u'%s:%s' % (uri, port) log.info('> Connect %s', uri) return MongoClient(uri)
def init_storage(self): log.info(' - storage') self.fileSet = uploads.UploadSet('files', uploads.ALL) self.app.config['UPLOADED_FILES_DEST'] = conf.get('backend.storage', 'path') uploads.configure_uploads(self.app, (self.fileSet,)) uploads.patch_request_class(self.app, 512 * 1024 * 1024) # Set max file upload 512MiB
def init_static(self): log.info(' - static') if not conf.getboolean('ui', 'serve_static'): log.info(' [-] not serving static') return False static_folder = conf.get('ui', 'static_folder') dist = path.basename(static_folder).lower() == 'dist' component_folder = path.abspath(path.join(static_folder, path.pardir, 'bower_components')) log.info(' > static_folder: %s', static_folder) if not dist: log.info(' > component_folder: %s', component_folder) @self.app.route('/bower_components/<path:path>') def send_components(path): return send_from_directory(component_folder, path) @self.app.route('/<path:path>') def send_html(path): return send_from_directory(static_folder, path) @self.app.route('/') def root(): return send_from_directory(static_folder, 'index.html')
def __init__(self): self.app = Flask(__name__, static_url_path=conf.get('ui', 'static_folder')) self.api = Api(self.app) self.debug = conf.getboolean('debug', 'active') self.fileSet = None self.init()
def __init__(self): self.app = Flask(__name__, static_url_path=conf.get('ui', 'static_folder')) self.api = Api(self.app) self.debug = conf.getboolean('debug', 'active') self.fileSet = None self.init()
def init_storage(self): log.info(' - storage') self.fileSet = uploads.UploadSet('files', uploads.ALL) self.app.config['UPLOADED_FILES_DEST'] = conf.get( 'backend.storage', 'path') uploads.configure_uploads(self.app, (self.fileSet, )) uploads.patch_request_class(self.app, 512 * 1024 * 1024) # Set max file upload 512MiB
def get(name=None): parser = parser_factory(namespace='file', locations=['values', 'json', 'headers']) args = parser.parse_args() path = os.path.join(conf.get('backend.storage', 'path'), name) log.info('Requesting file with hash: %s', path) if not os.path.exists(path): return "File not found", 404 return flask.send_file(path, args.mime) # , as_attachment, attachment_filename, add_etags, cache_timeout, conditional)
def get(name=None): parser = parser_factory(namespace='file', locations=['values', 'json', 'headers']) args = parser.parse_args() path = os.path.join(conf.get('backend.storage', 'path'), name) log.info('Requesting file with hash: %s', path) if not os.path.exists(path): return "File not found", 404 return flask.send_file( path, args.mime ) # , as_attachment, attachment_filename, add_etags, cache_timeout, conditional)
def init_static(self): log.info(' - static') if not conf.getboolean('ui', 'serve_static'): log.info(' [-] not serving static') return False static_folder = conf.get('ui', 'static_folder') dist = path.basename(static_folder).lower() == 'dist' component_folder = path.abspath( path.join(static_folder, path.pardir, 'bower_components')) log.info(' > static_folder: %s', static_folder) if not dist: log.info(' > component_folder: %s', component_folder) @self.app.route('/bower_components/<path:path>') def send_components(path): return send_from_directory(component_folder, path) @self.app.route('/<path:path>') def send_html(path): return send_from_directory(static_folder, path) @self.app.route('/') def root(): return send_from_directory(static_folder, 'index.html')
def on_start(): data_path = conf.get('main', 'data_path') print('DataPath: %s' % data_path) # mode = conf.getint('main', 'directory_mode') if not path.exists(data_path): mkdir(data_path)
def init_configure(self): log.info(' - configure') self.app.config['SECRET_KEY'] = conf.get('backend', 'secret') self.app.config['BUNDLE_ERRORS'] = True # self.app.config['UPLOAD_FOLDER'] = conf.get('backend.storage', 'path') log.info(self.app.config)
def filter(self, record): # return True if self.param is None: allow = True else: allow = self.param not in record.msg if allow: record.msg = record.msg return allow class UTCFormatter(logging.Formatter): converter = time.gmtime __FN__ = conf.get('log', 'path') LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'default': { 'format': '%(asctime)s [monu.%(name)-12s] %(levelname)-6s %(message)s' }, 'utc': { '()': UTCFormatter, 'format': '%(asctime)s %(message)s', }, 'stream': { 'format': '[monu.%(name)-12s] %(levelname)-6s %(message)s', }
def filter(self, record): # return True if self.param is None: allow = True else: allow = self.param not in record.msg if allow: record.msg = record.msg return allow class UTCFormatter(logging.Formatter): converter = time.gmtime __FN__ = conf.get('log', 'path') LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'default': { 'format': '%(asctime)s [monu.%(name)-12s] %(levelname)-6s %(message)s' }, 'utc': { '()': UTCFormatter, 'format': '%(asctime)s %(message)s', }, 'stream': { 'format': '[monu.%(name)-12s] %(levelname)-6s %(message)s',
def init_configure(self): log.info(' - configure') self.app.config['SECRET_KEY'] = conf.get('backend', 'secret') self.app.config['BUNDLE_ERRORS'] = True # self.app.config['UPLOAD_FOLDER'] = conf.get('backend.storage', 'path') log.info(self.app.config)
def get_upload_path(name): return os.path.join(conf.get('frontend.upload', 'path'), name)
# -*- coding: utf-8 -*- from monu.conf import conf from monu.srv.application import application as _application application = _application.app if __name__ == '__main__': host = conf.get('uwsgi', 'host') port = conf.getint('uwsgi', 'port') application.run(port=port, host=host, debug=True)