Skip to content
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 29 additions and 16 deletions.
  1. +22 −11 epubtag.py
  2. +7 −5 masq
View
33 epubtag.py
@@ -60,17 +60,17 @@ def get_matches(elname, delete_tags=False) :
matches.append(el.childNodes[0].wholeText.encode('utf-8',
'backslashreplace'))
- return matches
+ return matches, elements, parent
# But first, grab the title and author
- titles = get_matches('dc:title')
+ titles, elements, parent = get_matches('dc:title')
if titles :
if brief :
print ', '.join(titles), '|',
else :
for t in titles :
print "Title:", t
- authors = get_matches('dc:creator')
+ authors, elements, parent = get_matches('dc:creator')
if brief :
print ', '.join(authors), '|',
else :
@@ -80,8 +80,8 @@ def get_matches(elname, delete_tags=False) :
print 'Author:',
print ', '.join(authors)
- # Now get the subject tags.
- tags = get_matches(subjectTag, delete_tags)
+ # Now get the subject tags, deleting them if appropriate.
+ tags, elements, parent = get_matches(subjectTag, delete_tags)
if brief :
print ', '.join(tags)
else :
@@ -96,14 +96,25 @@ def get_matches(elname, delete_tags=False) :
zf.close()
return
+ # There are new tags to add.
+
# If we didn't see a dc:subject, we still need a parent, the <metadata> tag.
if not parent :
+ print "Warning: didn't see any subject tags previously"
parent = dom.getElementsByTagName("metadata")[0]
- # If there's no metadata tag, maybe we should add one,
- # but it might be better to throw an error.
- # There are new tags to add.
- # First, add them to the DOM by cloning the last node:
+ # If there's no metadata tag, maybe we should add one,
+ # but it might be better to throw an error.
+ if not parent :
+ print "No metadata tag! Bailing."
+ return
+
+ # We'll want to add the new subject tags after the last one.
+ if elements :
+ last_tag_el = elements[-1]
+ else :
+ last_tag_el = None
+
for new_tag in new_tag_list :
# Make the new node:
#newnode = tag.cloneNode(False)
@@ -117,8 +128,8 @@ def get_matches(elname, delete_tags=False) :
textnode = dom.createTextNode('\n')
# Append nodenode after the last tag node we saw:
- if tag and tag.nextSibling :
- parent.insertBefore(textnode, tag.nextSibling)
+ if last_tag_el and last_tag_el.nextSibling :
+ parent.insertBefore(textnode, last_tag_el.nextSibling)
parent.insertBefore(newnode, textnode)
# If we didn't see a tag, or the tag was the last child
# of its parent, we have to do it this way:
View
12 masq
@@ -5,26 +5,28 @@
# http://www.ibiblio.org/pub/linux/docs/howto/other-formats/html_single/Masquerading-Simple-HOWTO.html
pi_net=192.168.0
+ext_iface=wlan0 # Would be nice to figure this out
+pi_iface=eth0
# Don't actually need to know the Pi's intended address, just the network.
#pi_addr=97
-myaddr=$(ifconfig wlan0 | grep 'inet addr:' | sed -e 's/.*addr://' -e 's/ *Bcast:.*//')
-echo My wlan0 address is $myaddr
+myaddr=$(ifconfig ${ext_iface} | grep 'inet addr:' | sed -e 's/.*addr://' -e 's/ *Bcast:.*//')
+echo My ${ext_iface} address is $myaddr
# Set up IP masquerading:
modprobe ipt_MASQUERADE
iptables -F
iptables -t nat -F
iptables -t mangle -F
-iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to $myaddr
+iptables -t nat -A POSTROUTING -o ${ext_iface} -j SNAT --to $myaddr
echo 1 > /proc/sys/net/ipv4/ip_forward
# A little security: set it up so that the pi can send us anything,
# but outside hosts can't:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-iptables -A INPUT -m state --state NEW ! -i wlan0 -j ACCEPT
+iptables -A INPUT -m state --state NEW ! -i ${ext_iface} -j ACCEPT
iptables -P INPUT DROP
# Bring up eth0 so we can actually talk:
-ifconfig eth0 ${pi_net}.1 up
+ifconfig ${pi_iface} ${pi_net}.1 up

No commit comments for this range

Something went wrong with that request. Please try again.