via nytimes.com
Monday, December 20, 2010
Tuesday, July 27, 2010
oswalk
import sys
import os
import os.path
def walk_tree(path):
# print path
for rt, ds, fs in os.walk(path):
for f in fs:
fn = os.path.join(rt, f)
if os.path.isfile(fn):
# yield os.getmtime(fn), fn
yield os.path.basename(fn), os.path.getsize(fn), os.path.getmtime(fn),fn
def walk_dirs(path):
for rt, ds, fs in os.walk(path):
for d in ds:
# print d
dn = os.path.join(rt, d)
if os.path.isdir(dn):
yield dn
# yield os.getmtime(fn), fn
# yield os.path.basename(fn), os.path.getsize(fn), os.path.getmtime(fn),fn
#print sys.argv[1:]
def listing(path):
childs=[os.path.join(path,x) for x in os.listdir(path)]
dirs=[x for x in childs if os.path.isdir(x)]
# dirs=walk_dirs(path)
for d in dirs:
# print d
# print "======================================"
# print d
total=sum([x[1] for x in walk_tree(d)])
yield path,os.path.dirname(d),d,total
# yield path,os.path.dirname(d),d,total
from operator import itemgetter, attrgetter
ss=sorted(listing(sys.argv[1]),reverse=True,key=itemgetter(3))
for s in ss[:4]:
print "\t".join([str(s)])
# raw_input();
##for param in sys.argv[1:]:
## print param
## foo=listing(param)
##
## print "========="
##
## bigdirsize={}
## smalldirsize={}
## for f in foo:
## print f
## if f[0] in bigdirsize:
## bigdirsize[f[0]] += f[3]
## else:
## bigdirsize[f[0]] = f[3]
## if f[0] in smalldirsize:
## smalldirsize[f[1]] += f[3]
## else:
## smalldirsize[f[1]] = f[3]
##
## for b in bigdirsize.keys():
## print b,bigdirsize[b]
## print "=========="
### for b in smalldirsize.keys():
### print b,smalldirsize[b]
##
#asdf=raw_input()
#print "asdf"
#
#
#
##def keyfunc(x):
## return x[0]
#
#from itertools import groupby
#
#groups = []
#uniquekeys = []
#totalsize={}
##data = sorted(foo, key=keyfunc)
#for k, g in groupby(foo, lambda (x): x[0]):
# groups.append(list(g)) # Store group iterator as a list
# uniquekeys.append(k)
#
#
#for g in groups:
# total=0.1
# name=0.0
# for gg in g:
# name=gg[0]
# total+=gg[2]
# foo=[]
# for gg in g:
# foo.append([int(100 * gg[2]/total),gg[2]/1024/1024,gg[0],gg[1]])
#
# s=sorted(foo,reverse=True)
# perc=0
# for element in s:
# perc+=element[0]
# print "\t".join([str(x) for x in element])
# if perc > 80 or element[0]<5: break
# print
## print s
#
#
## print gg[0],
## print gg
## print "\n\n"
## print name,total
#
##for k in uniquekeys:
## print k
#
##for g in groups:
## print "----------------------"
## print g[0][0],
## print sum([x[2] for x in g ])
### print len(g)
## for item in groups:
## print item
##for u in uniquekeys:
## print u
#
#
#
#
## foo=raw_input()
## for f in walk_tree(d):
## print f,
## print walk_tree(d)
##x=walk_tree(sys.argv[1:][0])
##for y in x:
## print y
##for x in walk_tree(sys.argv[1:]):
## print x[0],x[1]
import os
import os.path
def walk_tree(path):
# print path
for rt, ds, fs in os.walk(path):
for f in fs:
fn = os.path.join(rt, f)
if os.path.isfile(fn):
# yield os.getmtime(fn), fn
yield os.path.basename(fn), os.path.getsize(fn), os.path.getmtime(fn),fn
def walk_dirs(path):
for rt, ds, fs in os.walk(path):
for d in ds:
# print d
dn = os.path.join(rt, d)
if os.path.isdir(dn):
yield dn
# yield os.getmtime(fn), fn
# yield os.path.basename(fn), os.path.getsize(fn), os.path.getmtime(fn),fn
#print sys.argv[1:]
def listing(path):
childs=[os.path.join(path,x) for x in os.listdir(path)]
dirs=[x for x in childs if os.path.isdir(x)]
# dirs=walk_dirs(path)
for d in dirs:
# print d
# print "======================================"
# print d
total=sum([x[1] for x in walk_tree(d)])
yield path,os.path.dirname(d),d,total
# yield path,os.path.dirname(d),d,total
from operator import itemgetter, attrgetter
ss=sorted(listing(sys.argv[1]),reverse=True,key=itemgetter(3))
for s in ss[:4]:
print "\t".join([str(s)])
# raw_input();
##for param in sys.argv[1:]:
## print param
## foo=listing(param)
##
## print "========="
##
## bigdirsize={}
## smalldirsize={}
## for f in foo:
## print f
## if f[0] in bigdirsize:
## bigdirsize[f[0]] += f[3]
## else:
## bigdirsize[f[0]] = f[3]
## if f[0] in smalldirsize:
## smalldirsize[f[1]] += f[3]
## else:
## smalldirsize[f[1]] = f[3]
##
## for b in bigdirsize.keys():
## print b,bigdirsize[b]
## print "=========="
### for b in smalldirsize.keys():
### print b,smalldirsize[b]
##
#asdf=raw_input()
#print "asdf"
#
#
#
##def keyfunc(x):
## return x[0]
#
#from itertools import groupby
#
#groups = []
#uniquekeys = []
#totalsize={}
##data = sorted(foo, key=keyfunc)
#for k, g in groupby(foo, lambda (x): x[0]):
# groups.append(list(g)) # Store group iterator as a list
# uniquekeys.append(k)
#
#
#for g in groups:
# total=0.1
# name=0.0
# for gg in g:
# name=gg[0]
# total+=gg[2]
# foo=[]
# for gg in g:
# foo.append([int(100 * gg[2]/total),gg[2]/1024/1024,gg[0],gg[1]])
#
# s=sorted(foo,reverse=True)
# perc=0
# for element in s:
# perc+=element[0]
# print "\t".join([str(x) for x in element])
# if perc > 80 or element[0]<5: break
## print s
#
#
## print gg[0],
## print gg
## print "\n\n"
## print name,total
#
##for k in uniquekeys:
## print k
#
##for g in groups:
## print "----------------------"
## print g[0][0],
## print sum([x[2] for x in g ])
### print len(g)
## for item in groups:
## print item
##for u in uniquekeys:
## print u
#
#
#
#
## foo=raw_input()
## for f in walk_tree(d):
## print f,
## print walk_tree(d)
##x=walk_tree(sys.argv[1:][0])
##for y in x:
## print y
##for x in walk_tree(sys.argv[1:]):
## print x[0],x[1]
Tuesday, July 13, 2010
pmail
import sys, smtplib
fromaddr = raw_input("From: ")
toaddrs = raw_input("To: ").split(',')
print "Enter message, end with ^D:"
msg = ''
while True:
line = sys.stdin.readline()
if not line:
break
msg += line
# The actual mail send
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
fromaddr = raw_input("From: ")
toaddrs = raw_input("To: ").split(',')
print "Enter message, end with ^D:"
msg = ''
while True:
line = sys.stdin.readline()
if not line:
break
msg += line
# The actual mail send
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
mbox_from
import mailbox
import email
mbox = mailbox.PortableUnixMailbox(open(filename, 'rU'), email.message_from_file)
for msg in mbox:
from = msg['From']
print from
import email
mbox = mailbox.PortableUnixMailbox(open(filename, 'rU'), email.message_from_file)
for msg in mbox:
from = msg['From']
print from
Thursday, July 8, 2010
columnate
#!/usr/bin/awk -f
BEGIN{FS="\t";}
{
line[NR] = $0 # saves the line
for (f=1; f<=NF; f++) {
len = length($f)
if (len>max[f])
max[f] = len # an array of maximum field widths
}
}
END {
for(nr=1; nr<=NR; nr++) {
nf = split(line[nr], fields)
for (f=1; f printf "%-*s", max[f]+2, fields[f]
print fields[f] # the last field need not be padded
}
}
BEGIN{FS="\t";}
{
line[NR] = $0 # saves the line
for (f=1; f<=NF; f++) {
len = length($f)
if (len>max[f])
max[f] = len # an array of maximum field widths
}
}
END {
for(nr=1; nr<=NR; nr++) {
nf = split(line[nr], fields)
for (f=1; f
print fields[f] # the last field need not be padded
}
}
Tuesday, June 29, 2010
sidebyside
daily.0 daily.1
daily.1 daily.2
daily.2 daily.3
daily.3 daily.4
daily.4 daily.5
daily.5 daily.6
daily.6 weekly.0
weekly.0 weekly.1
weekly.1 weekly.2
weekly.2 weekly.3
weekly.3 weekly.4
weekly.4 weekly.5
weekly.5 weekly.6
weekly.6 weekly.7
weekly.7 weekly.8
weekly.8 weekly.9
weekly.9 weekly.10
weekly.10 weekly.11
weekly.11 weekly.12
weekly.12 weekly.13
weekly.13 weekly.14
weekly.14 weekly.15
weekly.15 weekly.16
weekly.16 weekly.17
weekly.17 weekly.18
weekly.18 weekly.19
weekly.19 weekly.20
weekly.20 weekly.21
weekly.21 weekly.22
weekly.22 weekly.23
weekly.23 weekly.24
weekly.24 weekly.25
weekly.25 weekly.26
weekly.26 weekly.27
weekly.27 weekly.28
weekly.28 weekly.29
weekly.29 weekly.30
weekly.30 weekly.31
weekly.31 weekly.32
weekly.32 weekly.33
weekly.33 weekly.34
weekly.34 weekly.35
weekly.35 weekly.36
weekly.36 weekly.37
weekly.37 weekly.38
weekly.38 weekly.39
weekly.39 weekly.40
weekly.40 weekly.41
weekly.41 weekly.42
weekly.42 weekly.43
weekly.43 weekly.44
weekly.44 weekly.45
weekly.45 weekly.46
weekly.46 weekly.47
weekly.47 weekly.48
weekly.48 weekly.49
weekly.49 weekly.50
weekly.50 weekly.51
weekly.51 weekly.52
weekly.52 weekly.53
weekly.53 weekly.54
weekly.54 weekly.55
weekly.55 weekly.56
weekly.56 weekly.57
weekly.57 weekly.58
weekly.58 weekly.59
weekly.59 weekly.60
weekly.60 weekly.61
weekly.61 weekly.62
weekly.62 weekly.63
weekly.63 weekly.64
weekly.64 weekly.65
weekly.65 weekly.66
weekly.66 weekly.67
weekly.67 weekly.68
weekly.68 weekly.69
weekly.69 weekly.70
weekly.70 weekly.71
daily.1 daily.2
daily.2 daily.3
daily.3 daily.4
daily.4 daily.5
daily.5 daily.6
daily.6 weekly.0
weekly.0 weekly.1
weekly.1 weekly.2
weekly.2 weekly.3
weekly.3 weekly.4
weekly.4 weekly.5
weekly.5 weekly.6
weekly.6 weekly.7
weekly.7 weekly.8
weekly.8 weekly.9
weekly.9 weekly.10
weekly.10 weekly.11
weekly.11 weekly.12
weekly.12 weekly.13
weekly.13 weekly.14
weekly.14 weekly.15
weekly.15 weekly.16
weekly.16 weekly.17
weekly.17 weekly.18
weekly.18 weekly.19
weekly.19 weekly.20
weekly.20 weekly.21
weekly.21 weekly.22
weekly.22 weekly.23
weekly.23 weekly.24
weekly.24 weekly.25
weekly.25 weekly.26
weekly.26 weekly.27
weekly.27 weekly.28
weekly.28 weekly.29
weekly.29 weekly.30
weekly.30 weekly.31
weekly.31 weekly.32
weekly.32 weekly.33
weekly.33 weekly.34
weekly.34 weekly.35
weekly.35 weekly.36
weekly.36 weekly.37
weekly.37 weekly.38
weekly.38 weekly.39
weekly.39 weekly.40
weekly.40 weekly.41
weekly.41 weekly.42
weekly.42 weekly.43
weekly.43 weekly.44
weekly.44 weekly.45
weekly.45 weekly.46
weekly.46 weekly.47
weekly.47 weekly.48
weekly.48 weekly.49
weekly.49 weekly.50
weekly.50 weekly.51
weekly.51 weekly.52
weekly.52 weekly.53
weekly.53 weekly.54
weekly.54 weekly.55
weekly.55 weekly.56
weekly.56 weekly.57
weekly.57 weekly.58
weekly.58 weekly.59
weekly.59 weekly.60
weekly.60 weekly.61
weekly.61 weekly.62
weekly.62 weekly.63
weekly.63 weekly.64
weekly.64 weekly.65
weekly.65 weekly.66
weekly.66 weekly.67
weekly.67 weekly.68
weekly.68 weekly.69
weekly.69 weekly.70
weekly.70 weekly.71
Wednesday, June 23, 2010
comp_dirs
#!/bin/sh
#originally yoinked from #awk
#remove the trailing /'s
#while test $# -gt 0; do
case $1 in
--command | --cmd | --c | -c | -cmd )
shift
CMD=$1
# printf "%q " $1
# CMD="$VAR"
shift
;;
esac
one=$1
two=$2
echo "----------"
printf -v VAR "%q " $CMD
echo "----------"
dir1="${one/%\//}"
dir2="${two/%\//}"
echo "cmd=$CMD"
echo "vvv=$VAR"
echo "dir1=$dir1"
echo "dir2=$dir2"
TEMPDIR=${HOME}/tmp
FOO=$(cd ${dir1} && $CMD)
BAR=$(cd ${dir2} && $CMD)
seperator=":===============:"
echo "$FOO" > ${TEMPDIR}/foo.txt
echo "$BAR" > ${TEMPDIR}/bar.txt
#/* /^$seperator$/ {dir++; next}; */
echo -en "$seperator\n$FOO\n$seperator\n$BAR\n" > ${TEMPDIR}/foobar.txt
echo -en "$seperator\n$FOO\n$seperator\n$BAR\n" | awk -v "dir1_n=$dir1" -v "dir2_n=$dir2" -v "seperator=$seperator" '
$0 == seperator {dir++; next};
/^$/ {next};
1==dir{dir1[$0]++; next};
2==dir{dir2[$0]++; next};
END{
fmt = "%s\t%s\n";
printf fmt, dir1_n "/:", dir2_n "/:";
for (i in dir1) if (i in dir2) {delete dir1[i]; delete dir2[i]; printf fmt, i, i}
else {printf fmt, i, ""};
for (i in dir2) printf fmt, "", i}'
#originally yoinked from #awk
#remove the trailing /'s
#while test $# -gt 0; do
case $1 in
--command | --cmd | --c | -c | -cmd )
shift
CMD=$1
# printf "%q " $1
# CMD="$VAR"
shift
;;
esac
one=$1
two=$2
echo "----------"
printf -v VAR "%q " $CMD
echo "----------"
dir1="${one/%\//}"
dir2="${two/%\//}"
echo "cmd=$CMD"
echo "vvv=$VAR"
echo "dir1=$dir1"
echo "dir2=$dir2"
TEMPDIR=${HOME}/tmp
FOO=$(cd ${dir1} && $CMD)
BAR=$(cd ${dir2} && $CMD)
seperator=":===============:"
echo "$FOO" > ${TEMPDIR}/foo.txt
echo "$BAR" > ${TEMPDIR}/bar.txt
#/* /^$seperator$/ {dir++; next}; */
echo -en "$seperator\n$FOO\n$seperator\n$BAR\n" > ${TEMPDIR}/foobar.txt
echo -en "$seperator\n$FOO\n$seperator\n$BAR\n" | awk -v "dir1_n=$dir1" -v "dir2_n=$dir2" -v "seperator=$seperator" '
$0 == seperator {dir++; next};
/^$/ {next};
1==dir{dir1[$0]++; next};
2==dir{dir2[$0]++; next};
END{
fmt = "%s\t%s\n";
printf fmt, dir1_n "/:", dir2_n "/:";
for (i in dir1) if (i in dir2) {delete dir1[i]; delete dir2[i]; printf fmt, i, i}
else {printf fmt, i, ""};
for (i in dir2) printf fmt, "", i}'
Tuesday, June 22, 2010
pkginfo
#!/bin/sh
# stuart powers
# list the files installed from a specific package or all
# packages which match /pattern/ # one line of output per file:
# [exe|dir|pipe|etc] $PACKAGE $FILE
#to see all the executable files from libwww-perl:
#stu@sente ~ $ pkginfo.sh libwww-perl | grep ^x | cut -f3
# /usr/bin/lwp-download
# /usr/bin/lwp-mirror
# /usr/bin/lwp-rget
# /usr/bin/lwp-request
# /usr/bin/GET
# /usr/bin/POST
# /usr/bin/HEAD
#list installed apache packages:
#stu@sente ~ $ pkginfo.sh apache | cut -f2 | uniq
# apache2
# apache2-utils
# apache2.2-common
# libapache2-reload-perl
#show which packages have the most executables:
#stu@sente ~ $ pkginfo.sh | grep ^x | cut -f2 | uniq -c | sort -nr |head -5
# 131 git-core
# 96 coreutils
# 87 mailman
# 82 hal
# 70 texlive-base-bin
parm=$1
test -z $1 && parm=.
dpkg --list |
grep '^ii' |
grep -E "$parm" |
awk '{print $2}' |
while read package; do
dpkg -L $package |
while read file; do
#skips directories -- we only want files
# test -f "$file" || continue;
#if the file is executable, 'x', else 'f'
dest=
flag=
if [ -d "$file" ]; then
flag="dir"
elif [ -x "$file" ]; then
flag="exe"
fi
if [ -L "$file" ];
then flag="lnk"
fi;
if [ -L "$file" ];
then flag="lnk"
dest=$(readlink -e "$file")
fi;
if [ -L "$file" ];
then flag="pipe"
fi;
echo -e "$flag\t$package\t$file\t$dest";
done;
done
# stuart powers
# list the files installed from a specific package or all
# packages which match /pattern/ # one line of output per file:
# [exe|dir|pipe|etc] $PACKAGE $FILE
#to see all the executable files from libwww-perl:
#stu@sente ~ $ pkginfo.sh libwww-perl | grep ^x | cut -f3
# /usr/bin/lwp-download
# /usr/bin/lwp-mirror
# /usr/bin/lwp-rget
# /usr/bin/lwp-request
# /usr/bin/GET
# /usr/bin/POST
# /usr/bin/HEAD
#list installed apache packages:
#stu@sente ~ $ pkginfo.sh apache | cut -f2 | uniq
# apache2
# apache2-utils
# apache2.2-common
# libapache2-reload-perl
#show which packages have the most executables:
#stu@sente ~ $ pkginfo.sh | grep ^x | cut -f2 | uniq -c | sort -nr |head -5
# 131 git-core
# 96 coreutils
# 87 mailman
# 82 hal
# 70 texlive-base-bin
parm=$1
test -z $1 && parm=.
dpkg --list |
grep '^ii' |
grep -E "$parm" |
awk '{print $2}' |
while read package; do
dpkg -L $package |
while read file; do
#skips directories -- we only want files
# test -f "$file" || continue;
#if the file is executable, 'x', else 'f'
dest=
flag=
if [ -d "$file" ]; then
flag="dir"
elif [ -x "$file" ]; then
flag="exe"
fi
if [ -L "$file" ];
then flag="lnk"
fi;
if [ -L "$file" ];
then flag="lnk"
dest=$(readlink -e "$file")
fi;
if [ -L "$file" ];
then flag="pipe"
fi;
echo -e "$flag\t$package\t$file\t$dest";
done;
done
pylons
# run these commands to install/configure/test a pylons app
# test the app by going to http://localhost:5000
virtualenv --no-site-packages pyenv_quickwiki
. ./pyenv_quickwiki/bin/activate
easy_install Distribute
easy_install pip
pip install QuickWiki
paster make-config QuickWiki test.ini
paster setup-app test.ini
paster serve test.ini
# test the app by going to http://localhost:5000
virtualenv --no-site-packages pyenv_quickwiki
. ./pyenv_quickwiki/bin/activate
easy_install Distribute
easy_install pip
pip install QuickWiki
paster make-config QuickWiki test.ini
paster setup-app test.ini
paster serve test.ini
Subscribe to:
Posts (Atom)