Skip to content

Commit 08f3193

Browse files
author
John Gilmore
committed
Merge branch 'master' of git://github.com/jgilmore/Cruft
2 parents 9761a9b + f5e8ab6 commit 08f3193

16 files changed

+462
-46
lines changed

README.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ playrandom and its aliases playonce playmeonce playme, and the GUI script which
99
Dontcatchfire.sh is also technically in use daily, but whatever.
1010

1111
Documentation is sparse to non-existant, in contrast to dependancies, which are abundant.
12+
13+
Unless otherwise specified, licensed under GPL V3 or later

autobackup

Lines changed: 168 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,100 @@
11
#!/usr/bin/python
2+
import os
3+
import glob
4+
import subprocess
5+
from cPickle import load
6+
7+
8+
9+
def mail(From, to, subject, text, filelist=[],bcc="",cc="",headers=""):
10+
from email.MIMEMultipart import MIMEMultipart
11+
from email.MIMEBase import MIMEBase
12+
from email.MIMEText import MIMEText
13+
from email import Encoders
14+
from email.generator import Generator
15+
""" send mail to somebody. Return true on success, false on failure
16+
17+
"to" "bcc" and "cc" may be lists of addresses, or a single address as a string.
18+
19+
Note: all attached files are base64 encoded and stored IN MEMORY before being sent to
20+
the server. You probably will not be able to send any file or set of files even close to as
21+
large as your computers memory.
22+
23+
All attachements are given the mime-type "application/octet-stream" which is wrong.
24+
"""
25+
msg = MIMEMultipart()
26+
27+
msg['From'] = From
28+
msg['Subject'] = subject
29+
try:
30+
test = to.lower()
31+
#no error? to is a string, convert it to a list.
32+
sendto=[to]
33+
msg['To'] = to
34+
except AttributeError:
35+
#to is a list
36+
sendto=[]
37+
for addr in to:
38+
sendto.append(addr)
39+
msg.__setitem__('To',addr)
40+
41+
if cc:
42+
msg['Cc'] = cc
43+
try:
44+
test = bcc.lower()
45+
to.append(bcc)
46+
msg.__setitem__('Cc',addr)
47+
except AttributeError:
48+
for addr in bcc:
49+
sendto.append(addr)
50+
msg.__setitem__('Cc',addr)
51+
if bcc:
52+
#The point of "bcc" is that it's not in the message header, only the smtp reciepients.
53+
#msg['Bcc'] = bcc
54+
try:
55+
test = cc.lower()
56+
to.append(cc)
57+
except AttributeError:
58+
for addr in bcc:
59+
sendto.append(addr)
60+
if headers:
61+
try:
62+
test = headers.lower()
63+
#no error? headers is a string, convert it to a list.
64+
headers=[headers]
65+
except AttributeError:
66+
#already a list
67+
pass
68+
for header in headers:
69+
name, value = header.split(':',1)
70+
msg.__setitem__(name,value)
71+
72+
msg.attach(MIMEText(text))
73+
74+
for attach in filelist:
75+
part = MIMEBase('application', 'octet-stream')
76+
#The "read" call reads and encodes all files INTO MEMORY!!!
77+
# This severly limits the sendable file size.
78+
#TODO: rewrite email and smtplib to accept pointers, so these things can be done on the fly,
79+
#using MUCH less memory.
80+
part.set_payload(open(attach, 'rb').read())
81+
Encoders.encode_base64(part)
82+
part.add_header('Content-Disposition',
83+
'attachment; filename="%s"' % os.path.basename(attach))
84+
msg.attach(part)
85+
86+
sendmail=subprocess.Popen(["/usr/sbin/sendmail","-i"] + sendto,stdin=subprocess.PIPE,bufsize=-1)
87+
t = Generator(sendmail.stdin,mangle_from_=False,maxheaderlen=0)
88+
t.flatten(msg)
89+
sendmail.stdin.close()
90+
return sendmail.wait()
91+
292

3-
import libgmail
4-
from cPickle import load, dump
593

694
#Open for reading
95+
796
try:
8-
from os.path import expanduser
9-
f=open(expanduser("~/.gmailpasswd"),"r")
97+
f=open(os.path.expanduser("~/.gmailpasswd"),"r")
1098
except IOError, (errno, strerror):
1199
if errno == 2:
12100
print("""
@@ -24,26 +112,84 @@ except IOError, (errno, strerror):
24112
print "Unhandled IO error type"
25113
raise
26114

27-
#Load the stored credentials.
28-
credentials=load(f)
115+
#close the file - I really only needed to verify its existance.
29116
f.close()
30117

31-
#debug
32-
print credentials
33-
exit(17)
118+
#Time to beat:
119+
mytime=os.stat(os.path.expanduser("~/.gmailpasswd")).st_mtime
34120

121+
# cycle through all documents in /doc, encrypt and email any which are newer
122+
# filestring = string list of files
123+
fileslist=[]
124+
bodystring=""
125+
filestring=""
126+
subject=""
127+
def checkNadd(filename):
128+
""" Add a file to the file list. IF its newer """
129+
global filestring
130+
global fileslist
131+
global bodystring
132+
global subject
133+
status = os.stat(filename)
134+
if status.st_mtime > mytime:
135+
fileslist.append(filename)
136+
filestring += filename + "\n"
137+
#print filename
138+
if os.path.basename(filename).startswith("Journal") and filename.endswith(".txt"):
139+
f=open(filename,"r")
140+
addme=False
141+
for line in f:
142+
if line.endswith(":"):
143+
addme=False
144+
if addme:
145+
bodystring+=line
146+
if line.lower().lstrip().startswith("anna:"):
147+
addme=True
148+
bodystring+="From " + filename + "\n\n"
149+
name, sub=line.split(":",1)
150+
if sub:
151+
subject += sub.strip() + " "
152+
f.close()
153+
#else:
154+
# print str(status.st_mtime) + "<" + str(mytime)
155+
#For journal entries, add any "anna:" sections to the email body.
35156

36-
#login to gmail
37-
ga=libgmail.GmailAccount("j.arthur.gilmore","nDhiRp8w")
38-
ga.login()
157+
# Backup my Documents directory
158+
for root,dirs,files in os.walk(os.path.expanduser("~/docs")):
159+
#print root, dirs, files
160+
files.sort()
161+
for file in files:
162+
checkNadd(os.path.join(root,file))
163+
164+
# Backup my firefox bookmarks file
165+
for root,dirs,files in os.walk(glob.glob(os.path.expanduser("~/.mozilla/firefox/*.default/bookmarkbackups"))[0]):
166+
#print root, dirs, files
167+
files.sort()
168+
for file in files:
169+
checkNadd(os.path.join(root,file))
170+
171+
if len(fileslist) == 0:
172+
exit(0)
173+
174+
bodystring += "\n\n Changed files included in the backup:\n\n" + filestring
175+
176+
fileslist.insert(0,"-P")
177+
fileslist.insert(0,"-c")
178+
fileslist.insert(0,"/bin/tar")
179+
#print fileslist
180+
#print fileslist
181+
#print filestring
182+
#print bodystring
183+
# This implements "tar -c --strip-components
184+
tar=subprocess.Popen(fileslist,stdout=subprocess.PIPE,bufsize=-1)
185+
f=open("/tmp/autobackup.tar.gpg","wb")
186+
gpg=subprocess.Popen(["/usr/bin/gpg","-r","j.arthur.gilmore@gmail.com","--encrypt"],stdout=f,stdin=tar.stdout,bufsize=-1)
187+
188+
if subject == "":
189+
subject="Autobackup Email"
190+
191+
if gpg.wait() == 0 and tar.wait() == 0:
192+
if not mail("j.arthur.gilmore@gmail.com","anna.gilmore@gmail.com",subject,bodystring,filelist=["/tmp/autobackup.tar.gpg","/home/jgilmore/Safe.dat"]):
193+
# os.mtime(os.path.expanduser("~/.gmailpasswd"),None)
194+
os.execv("/usr/bin/touch",("touch",os.path.expanduser("~/.gmailpasswd")))
39195

40-
#compose our message
41-
msg=libgmail.GmailComposedMessage(
42-
"j.arthur.gilmore@gmail.com",
43-
"Automatic Safe Backup",
44-
"non-empty body text is not required",
45-
filenames=["/home/jgilmore/Safe.dat"])
46-
try:
47-
ga.sendMessage(msg)
48-
except http404:
49-
ga.sendMessage(msg)

camera-inserted

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# Stupid script to clean of a camera's SD card (or whatever) for reuse.
3+
debug=
4+
if [ "$debug" != "" ] ;then
5+
echo `whoami`>/tmp/camera
6+
fi
7+
8+
[ ! -d ~/pics -o ! -d "$1/dcim" ] && echo "missing either source or destination directory" && exit 1
9+
10+
zenity --info --text "Camera-type thingie inserted, moving pictures etc to ~/pics" &
11+
for dir in $1/dcim/*; do
12+
for file in $dir/*; do
13+
if [ "$debug" != "" ];then
14+
echo "$file" >>/tmp/camera
15+
fi
16+
mv "$file" ~/pics
17+
# Clear extranious a+x permissions on coppied files - they're not really executable.
18+
chmod a-x ~/pics/${file##*/}
19+
done
20+
done
21+
22+
if [ "$debug" != "" ] ;then
23+
set >>/tmp/camera
24+
mount >>/tmp/camera
25+
fi
26+
umount $1
27+
mplayer /usr/share/sounds/KDE_Beep_ClockChime.wav
28+
29+
zenity --info --text "Done moving pictures, media is unmounted and you may remove it" &
30+
rsync -avub ~/pics herb:
31+

crudetalker

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
3+
#default for fived_on_arduino
4+
BAUD=115200
5+
6+
7+
while [ $# -gt 0 ]; do
8+
case "$1" in
9+
-v)
10+
echo Crude Talker version 1.1
11+
;;
12+
-b)
13+
BAUD=$2
14+
shift
15+
;;
16+
-*)
17+
cat <<'EOF'
18+
usage: crudetalker [-v] [-b baud]
19+
-v: version
20+
-b baud: set baud rate
21+
22+
"cat"s terminal to /dev/arduino at the spec'd baudrate (default 115200)
23+
Hit Ctrl-D to terminate
24+
If you hit Ctrl-C, you'll have to kill the "cat" processes manually.
25+
26+
EOF
27+
;;
28+
*)
29+
break
30+
;;
31+
esac
32+
shift
33+
done
34+
35+
#Super-crude serial talker. Hit Ctrl-D to exit.
36+
#If you hit Ctrl-C, you'll have to manually kill it with "killall cat" or similar.
37+
#copied from a forum post by triffid hunter.
38+
#Written here so I'll remember it when I need it.
39+
#See http://forums.reprap.org/read.php?4,61654
40+
echo 'G21 (units are mm)'
41+
echo 'G91 (relative positioning)'
42+
43+
echo Setting baudrate to $BAUD
44+
45+
if ps | grep 'cat$' >/dev/null; then
46+
skip_kill_cat=1
47+
fi
48+
echo "press ctrl+D to exit"
49+
stty raw ignbrk hup $BAUD < /dev/arduino && echo Baudrate set to $BAUD && ( tee log.txt <&3 | cat & cat >&3; kill %%; ) 3<>/dev/arduino
50+
# You're supposed to use "^D" to exit. If somebody uses "^C" instead,
51+
# it leaves the "cat" process connected between the terminal and /dev/arduino
52+
# detect this condition and kill that process.
53+
if [ "$skip_kill_cat" == "" ]; then
54+
kill `ps | grep 'cat$'| cut -d " " -f -1` 2>/dev/null
55+
fi
56+
57+
#Command to set fuse bits and install bootloader
58+
#Doesn't work ¿because fuses are unwriteable using serial programming?
59+
#avrdude -c Diecimila -P /dev/arduino -p m168 -U hfuse:w:0xDD:m -U lfuse:w:0xff:m -U efuse:w:0x00:m
60+
#avrdude -c Diecimila -P /dev/arduino -p m168 -U flash:w:ATmega168BOOT.hex
61+
#avrdude -c Diecimila -P /dev/arduino -p m168 -U lock:w:0x0f:m
62+
63+

j

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
11
#!/bin/bash
2-
vim "$HOME/docs/Journal/`date '+Journal entry %F.txt'`"
2+
if [ "$1" == "" ]; then
3+
# Automatically edit a new journal entry, with spell check after.
4+
FILE="$HOME/docs/Journal/`date '+Journal entry %F.txt'`"
5+
if [ "${0##*/}" = "j" ]; then
6+
vim "$FILE"
7+
if [ -e "$FILE" ]; then
8+
ispell -x "$FILE"
9+
fi
10+
elif [ "${0##*/}" = "js" ]; then
11+
vim "$FILE"
12+
ispell -x "$FILE"
13+
else
14+
echo "huh? I'm not called that?"
15+
fi
16+
else
17+
# View yesterday's journal entry.
18+
line=$(($1 + 1))
19+
vim "`find $HOME/docs/Journal | sort -r | head -n $line | tail -n 1`"
20+
fi

kitchentimer.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SLEEPARG=`zenity --entry --title="Simple Timer" \
99
sleep ${SLEEPARG%-*}
1010

1111

12-
play /usr/share/sounds/startup3.wav
12+
playonce forget remember don.t
1313

1414
zenity --info --title="Simple Timer" --text="The ${SLEEPARG#*-} Timer is up." &
1515

playnext

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ fi
7373
#Grab the $NEXT'th $NUMBER line(s) of the playlist
7474
echo "playing the $NEXT'th $NUMBER files"
7575
head "$NAME.playlist" -n $(( $NEXT + $NUMBER - 1 )) | tail -n $NUMBER >/tmp/playnext
76+
echo "this file is called:"
77+
cat /tmp/playnext
7678

7779
#And play that file(s)
7880
mplayer -fs -nojoystick -playlist /tmp/playnext

0 commit comments

Comments
 (0)