Skip to content

Instantly share code, notes, and snippets.

@dirkakrid
dirkakrid / pyzzer.py
Created March 13, 2017 22:30 — forked from vsajip/pyzzer.py
A utility to create runnable zip files from Python sources.
#
# Copyright 2013 by Vinay Sajip.
# Licensed to the Python Software Foundation under a contributor agreement.
#
'''
Usage: pyzzer.py [options] DIRS
Convert Python source directories to runnable zip files.
Options:
@dirkakrid
dirkakrid / logtree.py
Created March 13, 2017 22:29 — forked from vsajip/logtree.py
Introspection of the logging hierarchy
#
# Copyright (C) 2012 Vinay Sajip. Licensed under the MIT license.
#
from collections import namedtuple
import logging
import re
class Snapper(object):
DEFAULT_CONFIG = {
@dirkakrid
dirkakrid / mplog3.py
Created March 13, 2017 22:28 — forked from vsajip/mplog3.py
Example of logging and multiprocessing
import logging
import logging.config
import logging.handlers
from multiprocessing import Process, Queue, Event, current_process
import os
import random
import time
class MyHandler(object):
"""
@dirkakrid
dirkakrid / custfmt.py
Created March 13, 2017 22:28 — forked from vsajip/custfmt.py
Example of logging formatter factory usage with fileConfig()
import logging
class CustomFormatter(logging.Formatter):
def __init__(self, default):
self.default = default
def format(self, record):
if record.levelno in (logging.WARNING,
logging.ERROR,
logging.CRITICAL):
@dirkakrid
dirkakrid / deleghand.py
Created March 13, 2017 22:27 — forked from vsajip/deleghand.py
Example of a delegating handler
import logging
import random
import re
class DelegatingHandler(logging.Handler):
def __init__(self, *handlers):
logging.Handler.__init__(self)
self.handlers = handlers
@dirkakrid
dirkakrid / mptest2.py
Created March 13, 2017 22:25 — forked from vsajip/mptest2.py
Example of multiprocessing and logging where main process uses a thread
#!/usr/bin/env python
# Copyright (C) 2011 Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Vinay Sajip
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
@dirkakrid
dirkakrid / ansistrm.py
Created March 13, 2017 22:21 — forked from vsajip/ansistrm.py
Python logging: colourising terminal output
#
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
#
import ctypes
import logging
import os
class ColorizingStreamHandler(logging.StreamHandler):
# color names to indices
color_map = {
import logging
import sys
from logutils.dictconfig import dictConfig
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
@dirkakrid
dirkakrid / configurator.py
Created March 12, 2017 23:06 — forked from vsajip/configurator.py
Example of configurator which shows cross-referencing between different parts of the configuration + access to data in external modules.
#
# Copyright (C) 2013 Vinay Sajip. All rights reserved.
#
import re
import sys
import unittest
from distlib.util import Configurator
@dirkakrid
dirkakrid / depmodel.py
Created March 12, 2017 23:06 — forked from vsajip/depmodel.py
Simple RDBMS modelling of dependencies based on PEP 426. Needs SQLAlchemy 0.8. Now updated to reflect the latest schema from PEP 426.
import codecs
import itertools
import json
import optparse # support 2.6
import os
import sys
from sqlalchemy import create_engine
from sqlalchemy import Column, Date, Integer, String, ForeignKey
from sqlalchemy.ext.declarative import declarative_base