def main(): """ Bootstrap the update process by wrapping the initialization and termination of logging and database access. Errors raised by tasks are caught here and logged, and the script is immediately killed. """ initialize_logging('../logs/update.log') logger = logging.getLogger() engine, session = database.initialize('sqlite:///../data/isrid-master.db') tasks = [augment_weather_instances] for task in tasks: try: task_name = task.__name__.replace('_', ' ') logger.info('Starting task: {}'.format(task_name)) task(session) except KeyboardInterrupt: print() logger.info('Terminating update ... ') break except Exception as error: logger.error('{}: {}'.format(type(error).__name__, error)) break logging.shutdown() # Flush files database.terminate(engine, session)
def execute(): warnings.filterwarnings("ignore") initialize_logging("../logs/merge.log", "a+") logger = logging.getLogger() engine, session = database.initialize("sqlite:///../data/isrid-master.db") with open("../data/mappings.yaml") as mappings_file: mappings = yaml.load(mappings_file.read()) for filename in os.listdir("../data/"): if filename.endswith(".xlsx"): for title, rows in read_excel(os.path.join("../data/", filename)): procedure = Registry.retrieve(filename, title) procedure = procedure or Registry.retrieve(filename) mapping = mappings.get(filename, {}).get(title, {}) if procedure: message = "Merging '{}' from '{}' ... " logger.info(message.format(title, filename)) labels = list(next(rows)) if labels.count("Equipment4") > 1: index = labels[::-1].index("Equipment4") labels[-index - 1] = "Equipment5" for index, row in enumerate(rows): labeled_row = dict(zip(labels, row)) for model in procedure(index, labeled_row, mapping): session.add(model) session.commit() logging.shutdown() database.terminate(engine, session)
def execute(deploy=False, host='0.0.0.0', port=5000): initialize_logging('../logs/server.log', 'w+', app.logger) if deploy: http_server = HTTPServer(WSGIContainer(app)) http_server.listen(port) IOLoop.instance().start() else: app.run(host, port, debug=True)
def execute(): initialize_logging('../logs/update.log') logger = logging.getLogger() engine, session = database.initialize('sqlite:///../data/isrid-master.db') tasks = [augment_weather_instances] for task in tasks: try: task_name = task.__name__.replace('_', ' ') logger.info('Starting task: {}'.format(task_name)) task(session) except KeyboardInterrupt: print() logger.info('Terminating update ... ') break except Exception as error: logger.error('{}: {}'.format(type(error).__name__, error)) break logging.shutdown() database.terminate(engine, session)
import os ROOT_DIR = os.path.normpath(os.path.dirname(__file__)) STATIC_DOC_ROOT = os.path.join(ROOT_DIR, "formplayer", "static") STATIC_URL = '/static/' STATIC_ROOT = os.path.join(ROOT_DIR, 'staticroot') #XFORMS_BOOTSTRAP_PATH = "static/demo_forms" XFORMS_PATH = "data/xforms" XFORMS_PLAYER_URL = "http://localhost:4444/" TOUCHFORMS_AUTOCOMPL_DATA_DIR = os.path.join(ROOT_DIR, 'static', 'census') LOG_FILE = os.path.join(ROOT_DIR, 'touchforms.log') init_logging = lambda: util.default_logging(LOG_FILE) #### IMPORT LOCALSETTINGS #### try: from localsettings import * except ImportError: pass TEMPLATE_DEBUG = DEBUG MANAGERS = ADMINS util.initialize_logging(init_logging) REVISION = util.get_revision('git', ROOT_DIR, 'flag') STATICFILES_STORAGE = 'staticfiles.storage.StaticFilesStorage' GMAPS_API_KEY = ''
def parse_args(args=None): parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("host", help="server to connect to") parser.add_argument("nick", help="irc nickname to use") parser.add_argument("channels", nargs="*", help="list of channels to join") parser.add_argument("--ident", "-i", help="value to send for ident command") parser.add_argument("--realname", "-r", help="value to send for real name (default: same as nick)") parser.add_argument("--password", "-p", help="value to send for pass command (default: same as nick)") parser.add_argument("--port", type=int, default=6667, help="port to connect to (default: 6667)") parser.add_argument("--ssl", "-s", action="store_true", help="use ssl for connection") return parser.parse_args(args) if __name__ == "__main__": args = parse_args() util.initialize_logging() mgr = ConnectionManager( args.host, args.port, args.nick, args.ident or args.nick, args.realname or args.nick, args.password, args.channels, ) mgr.connect() t = threading.Thread(target=print_messages, args=(mgr,)) t.start() try: while True: line = sys.stdin.readline()
nargs='?', help='keywords to track (optional, uses sample stream if omitted)') parser.add_argument('--username', '-u', required=True, help='twitter api username (required)') parser.add_argument('--password', '-p', required=True, help='twitter api password (required)') return parser.parse_args(args) if __name__ == '__main__': args = parse_args() util.initialize_logging() log = logging.getLogger(__name__) url = _API_URL % ('filter' if args.track else 'sample', ) kwargs = {} if args.track: kwargs['track'] = args.track stream = stream(sys.stdout, url, args.username, args.password, **kwargs) stream = handle_http_error_backoff(stream) stream = handle_network_error_backoff(stream) error = stream.next() log.error("shouldn't get error here, got %s", error) stream.send(False)