Skip to content

Instantly share code, notes, and snippets.

View happz's full-sized avatar

Miloš Prchlík happz

  • Red Hat
  • Brno, Czech Republic
View GitHub Profile
import ZODB.DB, ZODB.FileStorage
import hlib.runtime, hruntime, lib.datalayer # Moje knihovny, aby byly "citelne" objekty ve stromu, ktery lezi v db
storage = ZODB.FileStorage.FileStorage('/data/virtualenv/settlers/osadnici/db.test/settlers')
db = ZODB.DB(storage)
connection = db.open()
root = connection.root()
>>> print root
#!/bin/bash
USER="$1"
HOST="$2"
while `/bin/true`; do
echo 'loop...'
ping -c 3 $HOST &> /dev/null
[ "$?" = "0" ] && break
# generic one, any fns accepted
def reduce_to_false(*ps):
def __reduce_to_false(*args, **kwargs):
return all([p(*args, **kwargs) for p in ps])
return __reduce_to_false
# this one should work too but it's limited only to fns with exactly one parameter
def reduce_to_false_short(*ps):
return lambda arg: all([p(arg) for p in ps])
[local:0]: mprchlik@dhcp-25-152 ~ $ cat t.py
def f(l = []):
l.append('foo')
return l
print f()
print f()
[local:0]: mprchlik@dhcp-25-152 ~ $ python t.py
['foo']
from netaddr import IPNetwork
with open('workfile', 'r') as f:
print '\n'.join(['{0},{1}-{2}'.format(name, ip.network + 1, ip.broadcast - 1) for name, ip in [(net_name, IPNetwork(net_addr + '/' + net_mask)) for net_name, net_addr, net_mask in [line.strip().split() for line in f]]])
@happz
happz / retry.py
Last active February 16, 2016 15:58
import signal
import time
class Timeout(object):
def __init__(self, retry, timeout):
self.retry = retry
self.timeout = timeout
def __enter__(self):
def timeout_handler(signum, frame):
@happz
happz / retry.py
Last active February 24, 2016 12:49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of Cockpit.
#
# Copyright (C) 2016 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
class Foo():
def query(sql_query, sql_params = None, dryrun = None, fetchall = False):
# execute query
if fetchall:
result = cur.fetchall()
...
def select(self, *args, **kwargs):
kwargs['fetchall'] = True
return self.query(*args, **kwargs)
createdb proormedent
createuser -e -E -l -P proormed
REVOKE ALL ON DATABASE proormedent FROM public; -- shut out the general public
GRANT CONNECT ON DATABASE proormedent TO proormed; -- since we revoked from public
GRANT USAGE ON SCHEMA public TO proormed;
GRANT ALL ON ALL TABLES IN SCHEMA public TO proormed;
import filters
def _import_filters(directory):
filters = []
for name in os.listdir(directory):
if name == '__init__.py' or name.endswith('.pyc') or not name.endswith('.py'):
continue
mod_name = name[0:-3] # 'foo.py' => 'foo'