Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@buchi
buchi / dns_adfinis2aws.py
Last active September 17, 2019 14:48
Convert JSON DNS Zone File to Route 53
import json
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument('dir', help='Directory containing zone files')
options = parser.parse_args()
path = os.path.abspath(options.dir)
@buchi
buchi / zodb_refmap.py
Created March 2, 2018 13:41
ZODB: find oids of objects referencing a specific oid
from ZODB.serialize import referencesf
from ZODB.FileStorage import FileStorage
def build_refmap(filename):
"""Build a refmap from a filestorage. Look in every record of every
transaction. Build a dict of oid -> list(referenced oids)
"""
refmap = {}
fs = FileStorage(filename, read_only=1)
@buchi
buchi / pac.js
Created September 22, 2017 14:45
function FindProxyForURL(url, host) {
// Adressen, die auf example.com liegen, brauchen keinen Proxy:
if (shExpMatch(host,"*.example.com")) {
return "DIRECT";
}
// URLs innerhalb dieses Netzwerkes werden abgefragt über
// Port 8080 auf fastproxy.example.com: (macht Nameserver Anfrage)
if (isInNet(host, "10.0.0.0", "255.255.248.0")) {
return "PROXY fastproxy.example.com:8080";
@buchi
buchi / check_indexes.py
Last active June 22, 2017 07:37
Check Plone indexes for Unicode values
# Checks all UnIndex-based indexes for Unicode strings.
# Indexes should contain only byte strings.
# Having Unicode strings in indexes may result in UnicodeDecodeErrors during indexing or searching.
from Products.CMFPlone.interfaces import IPloneSiteRoot
from Products.CMFCore.utils import getToolByName
def get_plone_sites(root):
result = []
@buchi
buchi / require_login.py
Last active December 4, 2015 08:21
require_login.py (Fix for links to authenticated Plone content from MS Office)
from Products.PythonScripts.standard import url_unquote
login = 'login'
portal = context.portal_url.getPortalObject()
# if cookie crumbler did a traverse instead of a redirect,
# this would be the way to get the value of came_from
#url = portal.getCurrentUrl()
#context.REQUEST.set('came_from', url)
@buchi
buchi / delete_versions.py
Created August 16, 2015 09:03
Delete versions of deleted objects.
# setup dummy request
from Testing.makerequest import makerequest
app=makerequest(app)
plone = app.unrestrictedTraverse('/Plone')
# get user context of portal owner
from AccessControl.SecurityManagement import newSecurityManager
user = plone.getOwner()
newSecurityManager(app, user)
@buchi
buchi / multizexp.py
Created June 28, 2015 09:54
ZODB export with support for cross-database references.
"""ZODB export with support for cross-database references."""
# Inital version by David Glick
# http://glicksoftware.com/blog/recombining-zodb-storages
#
# ZODB 3.10 and Blob support by Thomas Buchberger
from ZODB.blob import Blob
from ZODB.utils import p64, u64, cp
from ZODB.ExportImport import export_end_marker
from ZODB.ExportImport import blob_begin_marker
from ldap.controls import SimplePagedResultsControl
import ldap
import csv
try:
# python-ldap 2.4
LDAP_CONTROL_PAGED_RESULTS = ldap.CONTROL_PAGEDRESULTS
PYTHON_LDAP_24 = True
except AttributeError:
# python-ldap 2.3
class ThreadedRequest(threading.Thread):
def __init__(self, url, data):
super(ThreadedRequest, self).__init__()
self.url = url
self.data = data
@log_error
def run(self):
response = urllib.urlopen(self.url, self.data)
# deco-grid maker
# calculates widths and positions for the deco grid system for arbitrary
# number of columns, cell width and gutter (margin).
# author: Thomas Buchberger <t.buchberger@4teamwork.ch>
# last modified: Di 2 Nov 2010 18:05:36 CET
from optparse import OptionParser
def main():