This file contains 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 | |
"""Aliases for argparse positional arguments.""" | |
import argparse | |
class AliasedSubParsersAction(argparse._SubParsersAction): | |
class _AliasedPseudoAction(argparse.Action): | |
def __init__(self, name, aliases, help): |
This file contains 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/python | |
import zypp # import the module | |
#myRepoString = "http://download.meego.com/snapshots/1.2.80.6.0.20110630.1/repos/non-oss/ia32/packages/?proxy=proxy01.pd.intel.com&proxyport=911" | |
myRepoString = "http://download.meego.com/snapshots/1.2.0.90.6.20110630.1/repos/non-oss/ia32/packages/?proxy=proxy01.pd.intel.com&proxyport=911" | |
repoTmpPath = "/tmp/repoTmpPath" # temporary Path | |
myZypp = zypp.ZYppFactory_instance().getZYpp() # create the instance | |
myTarget = myZypp.initializeTarget(zypp.Pathname(repoTmpPath)) # target (aka "root") | |
repoManagerOptions = zypp.RepoManagerOptions(zypp.Pathname(repoTmpPath)) # where to store the metadata | |
repoManager = zypp.RepoManager(repoManagerOptions) # manages multiple repositories |
This file contains 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 mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.pyplot as plt | |
import numpy as np | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): | |
xs = np.arange(20) | |
ys = np.random.rand(20) |
This file contains 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
class PluginMount(type): | |
def __init__(cls, name, bases, attrs): | |
if not hasattr(cls, 'plugins'): | |
# This branch only executes when processing the mount point itself. | |
# So, since this is a new plugin type, not an implementation, this | |
# class shouldn't be registered as a plugin. Instead, it sets up a | |
# list where plugins can be registered later. | |
cls.plugins = [] | |
else: | |
# This must be a plugin implementation, which should be registered. |
This file contains 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
class DelegateMetaClass(type): | |
def __new__(cls, name, bases, attrs): | |
methods = attrs.pop('delegated_methods', ()) | |
for m in methods: | |
def make_func(m): | |
def func(self, *args, **kwargs): | |
return getattr(self.delegate, m)(*args, **kwargs) | |
return func | |
attrs[m] = make_func(m) |
This file contains 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
import logging | |
from StringIO import StringIO | |
from five import grok | |
from xxx.objects.interfaces import IXXXResearcher | |
from Products.CMFCore.interfaces import ISiteRoot | |
from Products.statusmessages.interfaces import IStatusMessage | |
from xxx.objects.sync import sync_with_xxx |
This file contains 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
import sys | |
import tempfile | |
import os | |
class captured_stdout: | |
def __init__(self): | |
self.prevfd = None | |
self.prev = None | |
def __enter__(self): |
This file contains 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
class Filter(object): | |
""" | |
Workaround filter for annoying and worthless errors. | |
""" | |
def __init__(self, veto_words={'ClassTable'}): | |
self.veto_words = set(veto_words) | |
self.temp = tempfile.NamedTemporaryFile() | |
def __enter__(self): | |
sys.stdout.flush() # <--- NEEDED? | |
sys.stderr.flush() # <--- NEEDED? |
This file contains 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
import sys | |
def redirect_stderr_stdout(stderr=sys.stderr, stdout=sys.stdout): | |
def wrap(f): | |
def newf(*args, **kwargs): | |
old_stderr, old_stdout = sys.stderr, sys.stdout | |
sys.stderr = stderr | |
sys.stdout = stdout | |
try: | |
return f(*args, **kwargs) |
This file contains 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
import os | |
import sys | |
class RedirectStdStreams(object): | |
def __init__(self, stdout=None, stderr=None): | |
self._stdout = stdout or sys.stdout | |
self._stderr = stderr or sys.stderr | |
def __enter__(self): | |
self.old_stdout, self.old_stderr = sys.stdout, sys.stderr |
NewerOlder