This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# | |
# Copyright 2011 Richard Mitchell | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def constrained_insert(list_, item, before=None, after=None, strict=True): | |
""" Given a list and an item to be inserted into that list, attempts | |
to insert the item into the list in such a way that it is before | |
any items listed in the 'before' argument and after any of those | |
listed in the 'after' argument. If this is not possible, raises | |
a RuntimeError. | |
If any of the values in before or after do not appear in the | |
list, ValueError will be raised, unless 'strict' is set to | |
False. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wp_dir=$1 | |
backup_dir=$2 | |
latest_version=`echo -e "HEAD /latest.tar.gz HTTP/1.1\nHost: wordpress.org\n\n" | \ | |
nc -i 1 wordpress.org 80 | \ | |
grep 'Content-Disposition:' | \ | |
sed 's:.*filename=[A-Za-z-]*\([0-9\.]*\)\.tar\.gz.*:\1:'` | |
current_version=`grep '$wp_version = ' ${wp_dir}/wp-includes/version.php | \ | |
sed "s:.*['\"]\([0-9\.]*\)['\"].*:\1:"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@memoize | |
def get_wf_transitions_for(workflow, from_state, to_state): | |
exit_state_maps = {} | |
for state in workflow.states.objectValues(): | |
for t in state.getTransitions(): | |
exit_state_maps.setdefault(t, []) | |
exit_state_maps[t].append(state.getId()) | |
transition_maps = {} | |
for transition in workflow.transitions.objectValues(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from copy import deepcopy | |
def two_way_list_diff(left, right): | |
""" Compares two lists, returns a tuple of two lists detailing | |
which items have been added to the second list and removed | |
from the first list. | |
Example | |
------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrap_text(text, limit): | |
#s = map(str.split, text.split('\n')) | |
#i = 0 | |
#for n in range(len(s)): | |
# while i < len(s[n]) - 1: | |
# if (len(s[n][i]) + len(s[n][i+1])) <= limit: | |
# s[n][i] += ' ' + s[n][i+1] | |
# s[n] = s[n][:i+1] + s[n][i+2:] | |
# elif len(s[n][i+1]) > limit: | |
# i += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flatten(iterable): | |
if not isinstance(iterable, (list, tuple)): | |
yield iterable | |
else: | |
for i in iterable: | |
if isinstance(i, (list, tuple)): | |
for j in flatten(i): | |
yield j | |
else: | |
yield i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>HTML & CSS tree</title> | |
<!-- tree --> | |
<style type="text/css"> | |
ul.tree { | |
overflow-x: auto; | |
white-space: nowrap; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from AccessControl.SecurityManagement import newSecurityManager | |
from Testing.makerequest import makerequest | |
from zope.component.hooks import setSite | |
def get_manager(app): | |
for uid in app.acl_users.users.listUserIds(): | |
user = app.acl_users.users.getUser(uid) | |
if 'Manager' in user.getRoles(): | |
return user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configure | |
xmlns="http://namespaces.zope.org/zope"> | |
<adapter | |
factory=".datamanager.PersistentDictionaryField" /> | |
</configure> |
OlderNewer