Archive
Tags
android (3)
ant (2)
beautifulsoup (1)
debian (1)
decorators (1)
django (9)
dovecot (1)
encryption (1)
fix (4)
gotcha (2)
hobo (1)
htmlparser (1)
imaplib (2)
java (1)
json (2)
kerberos (2)
linux (7)
lxml (5)
markdown (4)
mechanize (6)
multiprocessing (1)
mysql (2)
nagios (2)
new_features (3)
open_source (5)
optparse (2)
parsing (1)
perl (2)
postgres (1)
preseed (1)
pxe (4)
pyqt4 (1)
python (41)
raid (1)
rails (1)
red_hat (1)
reportlab (4)
request_tracker (2)
rt (2)
ruby (1)
scala (1)
screen_scraping (7)
shell_scripting (8)
soap (1)
solaris (3)
sql (2)
sqlalchemy (2)
tips_and_tricks (1)
twitter (2)
ubuntu (1)
vmware (2)
windows (1)
zimbra (2)

I have been using lxml to generate XML to interface with Authorize.net's CIM API and I noticed something. Element does not behave as expected, which is supposed to be as a list. The key difference is with references to the same Element.

1
2
3
4
5
6
7
8
#!/usr/bin/env python
from lxml import etree

root = etree.Element('root')
child = etree.Element('child')
root.append(child)
root.append(child)
print etree.tostring(root, pretty_print=True)

If you run this, you will get the following output:

<root>
  <child/>
</root>

One child when we are expecting two. This is a bug. The workaround is to use deepcopy.

1
2
3
4
5
6
7
8
9
#!/usr/bin/env python
from copy import deepcopy
from lxml import etree

root = etree.Element('root')
child = etree.Element('child')
root.append(child)
root.append(deepcopy(child))
print etree.tostring(root, pretty_print=True)

This results with the expected output:

<root>
  <child/>
  <child/>
</root>
Posted by Tyler Lesmann on February 10, 2009 at 12:55 and commented on 1 time
Tagged as: gotcha lxml python

Google has put a lot of work into their Android platform, but their non-Eclipse development instructions could use some work. Just trying to build their Hello, Android fails if you follow their notes to the letter. You'll get this error or similar:

[tlesmann@kimiko HelloAndroid]$ ant
Buildfile: build.xml

dirs:
     [echo] Creating output directories if needed...

resource-src:
     [echo] Generating R.java / Manifest.java from the resources...

aidl:
     [echo] Compiling aidl files into Java classes...

compile:
    [javac] Compiling 2 source files to /home/lethal/src/android/HelloAndroid/bin/classes
    [javac] Compliance level '1.4' is incompatible with target level '1.5'. A compliance level '1.5' or better is required

BUILD FAILED
/home/tlesmann/src/android/HelloAndroid/build.xml:140: Compile failed; see the compiler error output for details.

Total time: 1 second

I was completely at a loss with this error and all the pages I found on Google were worthless. I'm hoping to change that with this post. The problem is that Sun's javac has a compliance level of 1.4 by default. This can be changed with a command-line argument of -1.5. To get ant to use this argument when compiling, you have to edit the build.xml like so:

<!-- Compile this project's .java files into .class files. -->
<target name="compile" depends="dirs, resource-src, aidl">
    <javac encoding="ascii" target="1.5" debug="true" extdirs=""
            srcdir="."
            destdir="${outdir-classes}"
            bootclasspath="${android-jar}">
        <compilerarg value="-1.5"/>
        <classpath>
            <fileset dir="${external-libs}" includes="*.jar"/>
        </classpath>
     </javac>
</target>

Add the line, <compilerarg value="-1.5"/>, within the javac element and ant will properly build the Hello, Android application. I'm surprised that the activitycreator program does not do this for you as Google advises you to use Sun's JDK.

I hope I've helped you avoid the frustration I suffered solving this silly issue.

NOTE: You no longer have to do this with the release of the 1.5 SDK! Just install Sun's Java and it will build without a problem.

Posted by Tyler Lesmann on December 6, 2008 at 7:08 and commented on 3 times
Tagged as: android ant fix gotcha java