Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
# $Id: offline_bootstrap.py 73407 2011-08-21 20:35:04Z glenfant $
"""Offline buildout bootstraping for use on installation targets with no
Internet access.
See http://glenfant.wordpress.com/2011/07/31/bootstrap-and-install-a-buildout-based-project-without-internet-connection/
We assume that the directory that contains this file has the following
structure:
@glenfant
glenfant / buildout.cfg
Created March 9, 2012 12:59
Add Products.PloneFilesZip to Plone 4.1.3
############################################
#
# Buildout Configuration File for ZEO Plone
# -----------------------------------------
# $LastChangedDate: 2011-08-05 17:56:09 -0700 (Fri, 05 Aug 2011) $ $LastChanged$
#
# After making changes in this configuration file,
# you should run bin/buildout to update the components.
#
# ALWAYS back up all Plone/Zope data and components
@glenfant
glenfant / test_aws_with_splinter.py
Created July 22, 2012 18:30
Démonstration de Splinter
# -*- coding: utf-8 -*-
"""Tests de www.alterway.fr avec splinter"""
# Préambule
import splinter
HOME = 'http://www.alterway.fr'
browser = splinter.Browser('firefox')
# On va à la page d'accueil
@glenfant
glenfant / issueorderinglist.py
Created August 28, 2012 15:30
sqlalchemy OrderingList issue
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.orderinglist import ordering_list
from sqlalchemy import Column, Integer, Text, ForeignKey
sa_engine = create_engine("sqlite:///:memory:")
@glenfant
glenfant / logging_yaml_config.py
Last active November 11, 2021 14:08
A example of logging medium complex configuration using YAML on Python 2.7 or 3.2
# -*- coding: utf-8
"""\
A simple demo of logging configuration with YAML (Python 2.7)
=============================================================
Requires PyYAML -> "easy_install PyYAML"
See the recipes for configuring logging with dicts and YAML
- http://docs.python.org/2.7/howto/logging-cookbook.html
- http://stackoverflow.com/questions/10519392/python2-7-logging-configuration-with-yaml
@glenfant
glenfant / recurse_to_jpg.py
Last active December 11, 2015 08:09
Hint to David Hernandez
import os
from PIL import Image
# Prefer the r"xxx" notation when you have backslashes
pathe = r"C:\David\"
for (path, dirs, files) in os.walk(pathe):
print path
print dirs
print files
for archivo in files:
@glenfant
glenfant / buildout.cfg
Created June 29, 2013 12:40
Make a wsgi script with zc.buildout (buildout.cfg)
[wsgiscript]
# Build the wsgi script for mod_wsgi
recipe = z3c.recipe.runscript
install-script = ${buildout:directory}/buildouthelpers.py:make_wsgi_script
update-script = ${:install-script}
# Parameters
egg = egg.with.wsgiapp
script = ${buildout:parts-directory}/wsgiscript/myapp.wsgi
@glenfant
glenfant / buildouthelpers.py
Last active December 19, 2015 03:29
Make a wsgi script with zc.buildout (buildouthelpers.py)
WSGISCRIPT_TEMPLATE = """\
# -*- coding: utf-8 -*-
import sys
import os
sys.path[0:0] = [
{0}
]
_application = None
@glenfant
glenfant / mock_time.py
Last active November 11, 2021 14:08
A simple context manager that enabes to change time.time() to whatever you need (future or past) in your unit tests.
import contextlib
import time
@contextlib.contextmanager
def mock_time(timestamp):
"""A simple context manager for mocking time.time() useful for traveling
immediately in the future or in the past in unit tests.
>>> t0 = time.time()
>>> with mock_time(t0 + 5.0):
@glenfant
glenfant / enumeration.py
Last active November 11, 2021 14:08
There is no enumeration type in Python a in some other languages as pascal or RubyThis is a poor man's enumeration that works as expected.
# -*- coding: utf-8 -*-
"""Python enumeration"""
import itertools
def enumeration(name, *auto, **named):
"""Pythonic enumeration type
>>> Colors = enumeration('Colors', 'GREEN', 'RED', 'YELLOW')