Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pyxform/odk_validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ def _kill_process_after_a_timeout(pid):
return (p.returncode, timeout, stdout, stderr)

def _java_installed():
p = Popen(["which","java"], stdout=PIPE)
return len(p.stdout.readlines()) != 0
if os.name == "nt":
p = Popen(["where","java"], stdout=PIPE)
try:
return p.stdout.readlines()[0].find("INFO:") == -1
except:
return False
else:
p = Popen(["which","java"], stdout=PIPE)
return len(p.stdout.readlines()) != 0

def _cleanup_errors(error_message):
def get_last_item(xpathStr):
Expand Down Expand Up @@ -104,7 +111,6 @@ def check_xform(path_to_xform):
returncode, timeout, stdout, stderr = run_popen_with_timeout(
["java", "-jar", ODK_VALIDATE_JAR, path_to_xform], 100)
warnings = []

if timeout:
return ["XForm took to long to completely validate."]
else:
Expand Down
13 changes: 10 additions & 3 deletions pyxform/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,16 @@ def print_xform_to_file(self, path="", validate=True, warnings=None):
warnings.extend(check_xform(path))

def to_xml(self, validate=True, pretty=True):
with tempfile.NamedTemporaryFile() as tmp:
# this will throw an exception if the xml is not valid
self.print_xform_to_file(tmp.name)
#windows cannot create a tempfile then open it again
tmp = tempfile.NamedTemporaryFile(delete=False)
tmpfilename = tmp.name
tmp.close()
self.print_xform_to_file(tmpfilename)
os.unlink(tmpfilename)

# with tempfile.NamedTemporaryFile() as tmp:
# # this will throw an exception if the xml is not valid
# self.print_xform_to_file(tmp.name)
return self._to_pretty_xml()

def instantiate(self):
Expand Down