Inspiroval jsem se tady:
http://www.css-networks.com/2010/12/how ... ter-works/
Hexa cisla jsou ukoncena h.
Konfigurace mdraid:
/dev/md => /dev/sda,/dev/sdb - mirror
/dev/md0 - systemovy bootovaci disk
/dev/md1 - swap
/dev/md2 - datovy disk
/dev/sda(sdb)
rozdeleni analogicke jako u mdx
typ filesystemu je u vsech 3 FDh(linux dynamic raid??)
Postup:
Prihlasit se jako root.
1) fdisk
upravit typ filesystemu u /dev/sda1 a 3 na kod 83h(linux)
a u /dev/sda2 na typ 82h (swap)
(pri ukladani konfigurace zahlasi fdisk,ze ji uplatni az po restartu!)
Neni nutno restartovat ted!
2) v /etc:
cp fstab fstab.old
cp grub.conf grub.old (grub.conf je symlink do /boot/grub/grub.conf)
mv mdadm.conf mdadm.old (puvodni je zrusen)
3) upravit v /etc:
fstab z /dev/md(0-3) na /dev/sda(1 - 3)
grub.conf sekce boot parametru root= na /dev/sda1
4) reboot
(pripadne je mozno jeste pomoci mkinitrd vyhodit z kernelu modul mdraid (viz link vyse))
(mozno fyzicky odpojit 2. hdd(/dev/sdb))
Po rebootu zkontrolovat df -ah ze system najel z /dev/sda1 a swap je /dev/sda2 ...
[ add comment ] ( 2 views ) | [ 0 trackbacks ] | permalink
>>> def myreturn():
... x = 100
... y = 200
... z = "hey"
... return { 'x': x, 'y': y, 'z': z }
...
>>> ret = myreturn()
>>> ret
{'y': 200, 'x': 100, 'z': 'hey'}
>>> ret.get('x')
100
>>> ret.get('y')
200
>>> ret.get('z')
'hey'
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink
This is a scene at one end of Liverpool Street train station looking towards the MacDonald's and up towards the Gerkin, which is slightly obscured by the rainy weather and space-age lights they have in the court yard. I think it's called Hope Square as this is the same square where the 'Children of the Kinderstransport' statue is.
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink
$ cat functs.py
def foo():
print "totot je foo"
def bar():
print "toto je bar"
def baz():
print "a nyni baz"
>>> import functs
>>> x = getattr( functs, 'bar' )
>>> x
<function bar at 0x2b0133cddcf8>
>>> x()
toto je bar
>>> x = getattr( functs, 'baz')
>>> x
<function baz at 0x2b0133cddd70>
>>> x()
a nyni baz
>>> x = getattr( functs, 'foo' )
>>> x
<function foo at 0x2b0133cddc80>
>>> x()
totot je foo
János Juhász wrote:
>
> Dear All,
>
> I want to use getattr() to collect a list with all the functions on my
> simple script those has got some functionname like 'On....'.
>
> #This should be the complete file
> def OnMenuFindMe():
> print 'You found me'
>
> f = getattr(What_Should_It_Be???, 'OnMenuFindMe')
>
> f()
> #Till here
>
> It can use getattr() to get an object of a class or module, but not in
> this much simpler situation.
You can look up the function in the globals() dict, or you can import
__main__, which is the top-level module, and use getattr() on it. Or you
could wrap your functions in a class...
def OnMenuFindMe():
print 'You found me'
f = globals()['OnMenuFindMe']
f()
import __main__
g = getattr(__main__, 'OnMenuFindMe')
g()
Kent
this is a nice way
func = getattr(obj, "method", None)
if callable(func):
func(args)
[ add comment ] ( 2 views ) | [ 0 trackbacks ] | permalink | related link
handle csv files in python with dialect autodetect
import csv
with open('/opt/oracle/dbid1.txt', 'rb') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
for row in reader:
print row[1]
print "next row please"
a simple example of dialect definition
>>> import csv
>>> import StringIO
>>> class MyDialect(csv.Dialect):
... quotechar = '\x07'
... delimiter = ','
... lineterminator = '\n'
... doublequote = False
... skipinitialspace = False
... quoting = csv.QUOTE_NONE
... escapechar = '\\'
...
>>> dialect = MyDialect()
>>> data = """
... 1,2,3,4,"5
... 1,2,3,4,5
... """
>>> reader = csv.reader(StringIO.StringIO(data), dialect=dialect)
>>> for i in reader: print i
...
[]
['1', '2', '3', '4', '"5']
['1', '2', '3', '4', '5']
code above from stackoverflow
data sample
$ cat /tmp/csvfile.csv
1;2;3;4
uluh;huliu;luhu;uhul;huhu
uluh;huliu;luhu;uhul;huhu
uluh;huliu;luhu;uhul;huhu
uluh;huliu;luhu;uhul;huhu
>>> import csv
>>> with open('/tmp/csvfile.csv', 'rb') as csvfile:
... reader = csv.reader(csvfile, delimiter=';', quotechar='|')
... for row in reader:
... for col in row:
... print col
... print "next row please"
...
1
2
3
4
next row please
uluh
huliu
luhu
uhul
huhu
next row please
uluh
huliu
luhu
uhul
huhu
next row please
uluh
huliu
luhu
uhul
huhu
next row please
uluh
huliu
luhu
uhul
huhu
next row please
#!/usr/bin/python
import os
import sys
import string
os.environ['DJANGO_SETTINGS_MODULE'] = "pure.settings"
sys.path.append("/home/pure/")
from tea.models import *
from assets.models import *
def import_line( line ):
""" split fields to parse data """
line_field = line.split(";")
""" put in respective containers """
hostname_alias = line_field[0].lower()
hostname = line_field[1].lower()
black_box = line_field[2]
installation_date = None
installed_by = line_field[4]
...
...
""" save enumeration fields to appropriate tables """
if console:
role, created = AssetAttribConsole.objects.get_or_create( enum=console )
if location:
role, created = AssetAttribLocation.objects.get_or_create( enum=location )
if installed_by:
role, created = AssetAttribGEperson.objects.get_or_create( enum=installed_by )
if authentication:
role, created = AssetAttribAuthentication.objects.get_or_create( enum=authentication )
""" save main data, enums are prepared already """
uxserver, create = AssetDomainServerUnix.objects.get_or_create( \
hostname_alias = hostname_alias )
if create:
print "* record for <%s> is being created" % hostname
else:
print "* record for <%s> will be updated" % hostname
print " - record id is %s" % uxserver.id
...
...
uxserver.black_box = black_box
uxserver.installation_date = installation_date
if installed_by:
uxserver.installed_by = AssetAttribGEperson.objects.get( enum = installed_by )
uxserver.decommission_date = decommission_date
uxserver.ip = ip
if console:
uxserver.console = AssetAttribConsole.objects.get( enum=console )
uxserver.ip_service_console = ip_service_console
...
...
if __name__ == "__main__":
file = open("/tmp/servers.txt", "r")
for line_raw in file:
try:
import_line( filter(lambda x: x in string.printable, line_raw) )
except:
print "* error: with line, required field is missing or duplicity of alias or fqdn, line follows: ^%s" % line_raw
[ add comment ] ( 2 views ) | [ 0 trackbacks ] | permalink
class Guest( models.Model ):
room = models.ForeignKey('Room')
name = models.CharField( max_length = 32, unique = False, default = "name not set" )
birth_date = models.DateField( auto_now = False, auto_now_add = False, unique = False, null = False )
check_in = models.DateField( auto_now = False, auto_now_add = False, unique = False, null = False )
check_out = models.DateField( auto_now = False, auto_now_add = False, unique = False, null = False )
services = models.TextField( max_length = 4092, unique = False, default = "", blank = True )
comment = models.CharField( max_length = 300, unique = False, default = "", blank = True )
>>> id = Guest.objects.filter( check_in__range=["2013-02-12", "2013-02-13"] ).filter( room__name="101" )
>>> id
[<Guest: 101>]
>>> Room.objects.get(id=id)
<Room: 101>
>>>
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink
convert string to datetime object
>>> import datetime
>>> x = '10/26/2010'
>>> month, day, year = x.split('/')
>>> month
'10'
>>> day
'26'
>>> year
'2010'
>>> d = datetime.date( int(year), int(month), int(day) )
>>> d
datetime.date(2010, 10, 26)
>>> type(d)
<type 'datetime.date'>
now consider we have a class Guest with attribute check_in and we need to select only guests checked in on specific date.
$ ./manage.py shell
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from essentials.models import *
>>> Guest.objects.all()
[<Guest: 101>]
>>> Guest.objects.filter( check_in__range=["2013-02-12", "2013-02-13"] )
[<Guest: 101>]
>>>
[ add comment ] ( 2 views ) | [ 0 trackbacks ] | permalink | related link
Python module inspect can inspect the run-time python stack. Useful for logging of debug. Link below.
import inspect
# functions
def whoami():
return inspect.stack()[1][3]
def whosdaddy():
return inspect.stack()[2][3]
def foo():
print "hello, I'm %s, daddy is %s" % (whoami(), whosdaddy())
bar()
def bar():
print "hello, I'm %s, daddy is %s" % (whoami(), whosdaddy())
johny = bar
# call them!
foo()
bar()
johny()
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link
/etc/rsyslog.conf
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
# local log
local2.* /var/log/local2.log
python code
import logging
import logging.handlers
logger = logging.getLogger( __name__ )
logger.addHandler( logging.handlers.SysLogHandler( \
address = ( 'localhost', 514 ), \
facility = logging.handlers.SysLogHandler.LOG_LOCAL2 ) )
logger.setLevel( logging.DEBUG )
logger.debug( "debug" )
logger.info( "info" )
logger.warning( "warning" )
logger.error( "error" )
logger.critical( "critical" )
facility
>>> dir(logging.handlers.SysLogHandler)
['LOG_ALERT', 'LOG_AUTH', 'LOG_AUTHPRIV', 'LOG_CRIT', 'LOG_CRON', 'LOG_DAEMON', 'LOG_DEBUG', 'LOG_EMERG', 'LOG_ERR', 'LOG_INFO', 'LOG_KERN', 'LOG_LOCAL0', 'LOG_LOCAL1', 'LOG_LOCAL2', 'LOG_LOCAL3', 'LOG_LOCAL4', 'LOG_LOCAL5', 'LOG_LOCAL6', 'LOG_LOCAL7', 'LOG_LPR', 'LOG_MAIL', 'LOG_NEWS', 'LOG_NOTICE', 'LOG_SYSLOG', 'LOG_USER', 'LOG_UUCP', 'LOG_WARNING', '__doc__', '__init__', '__module__', '_connect_unixsocket', 'acquire', 'addFilter', 'close', 'createLock', 'emit', 'encodePriority', 'facility_names', 'filter', 'flush', 'format', 'handle', 'handleError', 'log_format_string', 'mapPriority', 'priority_map', 'priority_names', 'release', 'removeFilter', 'setFormatter', 'setLevel']
severity
>>> logging.handlers.SysLogHandler.facility_names
{'kern': 0, 'daemon': 3, 'uucp': 8, 'local7': 23, 'local4': 20, 'lpr': 6, 'auth': 4, 'local0': 16, 'cron': 9, 'syslog': 5, 'user': 1, 'news': 7, 'local5': 21, 'mail': 2, 'security': 4, 'local6': 22, 'local1': 17, 'authpriv': 10, 'local3': 19, 'local2': 18}
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink | related link
networkx needs
matplotlib
and numpy
http://www.scipy.org/Download
[ add comment ] ( 3 views ) | [ 0 trackbacks ] | permalink

Calendar



