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 abc | |
class PluginBase(object): | |
__metaclass__ = abc.ABCMeta | |
def __init__(self): | |
self.base = 'base_info' | |
@abc.abstractmethod | |
def load(self, input): |
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
base_path, _ = os.path.split( | |
os.path.dirname(os.path.realpath(__file__) | |
)) | |
src = os.path.join(base_path, 'lib') | |
cfg = os.path.join(base_path, 'cfg') |
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 ColorScreen: | |
red = '\033[91m' | |
null = '\033[0m' | |
green = '\033[92m' | |
yellow = '\033[93m' | |
cyan = "\033[36m" | |
magenta = "\033[35m" | |
light_red = "\033[1;31m" |
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 functools import partial | |
def log_template(level, message): | |
print("{}: {}".format(level, message)) | |
log_info = partial(log_template, "info") | |
log_warning = partial(log_template, "warning") | |
log_error = partial(log_template, "error") | |
>>> log_info("test test test 1 2 3") |
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 Command(object): | |
def __init__(self, args): | |
self.cmd_args = args | |
def __call__(self): | |
(self.out, self.err) = subprocess.Popen(self.cmd_args, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
shell=True).communicate() |
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 optparse | |
# http://code.activestate.com/recipes/573441-extended-optparse-to-allow-definition-of-required-/ | |
strREQUIRED = 'required' | |
class OptionWithDefault(optparse.Option): | |
ATTRS = optparse.Option.ATTRS + [strREQUIRED] | |
def __init__(self, *opts, **attrs): |
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
def pp(json_docs): | |
"""preety print for json docs""" | |
print json.dumps(json_docs, indent=4) | |
def get_md5(key): | |
"""return md5 hex for key""" | |
md5 = hashlib.md5() | |
md5.update(key) | |
return md5.hexdigest() |
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
def yes_no(arg): | |
"""get input yes or no""" | |
print '%s [y|n]:' % arg, | |
if str(raw_input()).lower() == 'y': | |
return True | |
print 'Oops exiting!' | |
return False | |
def get_input(msg=None, password=False): |
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
>>> dic = { 1 : 'a', 2: 'b' } | |
>>> set(dic) | |
set([1, 2]) | |
# Check if any key exists: | |
>>> set([1,2]) <= set(dic) | |
True | |
>>> set([1]) <= set(dic) |
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 cProfile | |
from faker import Faker | |
from timeit import Timer | |
from UserString import MutableString | |
from cStringIO import StringIO | |
#from memory_profiler import profile | |
def func1(List): | |
"""Naive appending""" |