def set_log_and_verbosity(log): # Always write to log file. args = parseArgs() # Create directory for log files. if not os.path.exists(args.log_path): os.mkdir(args.log_path) if not args.no_file_logs: filename = os.path.join(args.log_path, args.log_filename) if not args.log_rotation: filelog = logging.FileHandler(filename) else: filelog = RotatingFileHandler( filename, maxBytes=args.log_rotation_file_size, backupCount=args.log_rotation_backup_count) filelog.setFormatter( logging.Formatter( '%(asctime)s [%(threadName)18s][%(module)14s][%(levelname)8s] ' + '%(message)s')) log.addHandler(filelog) if args.verbose: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO)
See http://stackoverflow.com/a/39501288/1709587 for explanation. """ if platform.system() == 'Windows': return os.path.getctime(path_to_file) else: stat = os.stat(path_to_file) try: return stat.st_birthtime except AttributeError: # We're probably on Linux. No easy way to get creation dates here, # so we'll settle for when its content was last modified. return stat.st_mtime if __name__ == "__main__": from utils.walkerArgs import parseArgs from db.monocleWrapper import MonocleWrapper from db.rmWrapper import RmWrapper args = parseArgs() if args.db_method == "rm": db_wrapper = RmWrapper(args, None) elif args.db_method == "monocle": db_wrapper = MonocleWrapper(args, None) else: log.error("Invalid db_method in config. Exiting") sys.exit(1) app.run()
import json import datetime import os import six import glob from flask import (make_response, request) from functools import update_wrapper, wraps from math import floor from utils.walkerArgs import parseArgs from utils.functions import (creation_date) from pathlib import Path mapping_args = parseArgs() def auth_required(func): @wraps(func) def decorated(*args, **kwargs): username = getattr(mapping_args, 'madmin_user', '') password = getattr(mapping_args, 'madmin_password', '') quests_pub_enabled = getattr(mapping_args, 'quests_public', False) if not username: return func(*args, **kwargs) if quests_pub_enabled and func.__name__ in ['get_quests', 'quest_pub', 'pushAssets']: return func(*args, **kwargs) if request.authorization: if (request.authorization.username == username) and ( request.authorization.password == password): return func(*args, **kwargs) return make_response('Could not verify!', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})
import sys MAD_ROOT = '/opt/mad/' sys.path.append(MAD_ROOT) import logging from unittest import TestCase from db.dbWrapperBase import DbWrapperBase from db.DbFactory import DbFactory from utils import data_manager from utils.walkerArgs import parseArgs mad_args = parseArgs() class DataManagerBase(TestCase): created_resources = [] instance_id = 1 def __init__(self, *args, **kwargs): super(DataManagerBase, self).__init__(*args, **kwargs) # We want a dumb logger and dont really care about the output self.logger = logging.getLogger() self.logger.setLevel(logging.CRITICAL) self.dbc, db_wrapper_manager = DbFactory.get_wrapper(mad_args) if 'instance_id' in kwargs: self.instance_id = kwargs['instance_id'] del kwargs['instance_id'] def tearDown(self): for resource in reversed(self.created_resources):
from db.monocleWrapper import MonocleWrapper from db.rmWrapper import RmWrapper from flask import (Flask, jsonify, make_response, redirect, render_template, request, send_from_directory) from flask_caching import Cache from utils.questGen import generate_quest from utils.walkerArgs import parseArgs sys.path.append("..") # Adds higher directory to python modules path. app = Flask(__name__) cache = Cache(app, config={'CACHE_TYPE': 'simple'}) log = logging.getLogger(__name__) conf_args = parseArgs() if conf_args.db_method == "rm": db_wrapper = RmWrapper(conf_args, None) elif conf_args.db_method == "monocle": db_wrapper = MonocleWrapper(conf_args, None) else: log.error("Invalid db_method in config. Exiting") sys.exit(1) def auth_required(func): @wraps(func) def decorated(*args, **kwargs): username = getattr(conf_args, 'madmin_user', '') password = getattr(conf_args, 'madmin_password', '')