Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyxform 0.9.22 validation not completing #7

Closed
JasonIves opened this issue Sep 3, 2014 · 3 comments
Closed

pyxform 0.9.22 validation not completing #7

JasonIves opened this issue Sep 3, 2014 · 3 comments

Comments

@JasonIves
Copy link

What steps will reproduce the problem?
1.Install pyxform 0.9.22
2.Run converter
3.Conversion completes but validation does not

What is the expected output? What do you see instead?
Successful conversion and validation. Conversion to XML completes but validation does not.

Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\pyxform\xls2xform.py", line 65, in <module

warnings = xls2xform_convert(args.path_to_XLSForm, args.output_path)

File "C:\Python27\Lib\site-packages\pyxform\xls2xform.py", line 22, in xls2xfo
rm_convert
survey.print_xform_to_file(xform_path, validate=True, warnings=warnings)
File "C:\Python27\Lib\site-packages\pyxform\survey.py", line 394, in print_xfo
rm_to_file
warnings.extend(check_xform(path))
File "C:\Python27\Lib\site-packages\pyxform\odk_validate__init__.py", line 96
, in check_xform
if not java_installed():
File "C:\Python27\Lib\site-packages\pyxform\odk_validate__init
_.py", line 43
, in _java_installed
p = Popen(["which","java"], stdout=PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

What version of the product are you using? On what operating system?
pyxform 0.9.22 Windows 7 OS

Please provide any additional information below.
I could be wrong, I'm not a Unix expert; but it looks to me like this is an issue with a Unix specific command being included in pyxform which doesn't work on Windows. It is in pyxform/odk_validate/init.py, the _java_installed function, the "which" command submitted through Popen.

def _java_installed():
p = Popen(["which","java"], stdout=PIPE)
return len(p.stdout.readlines()) != 0

When I comment out the call for this function, converter and validation both work fine.

@yanokwa
Copy link
Contributor

yanokwa commented Sep 5, 2014

popen in Python has lots of dragons, so it's hard to write platform independent code. If java is in your PATH, the code as written should work. Here is the code I use for XLSForm Offline.

#!/usr/bin/env python

import os
import re
import subprocess

def is_java_installed():

    # needed to hide the pop up cmd window
    startupinfo = None
    if os.name == 'nt':
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

    java_version = None
    java_regex = re.compile('java version "(.*)"')
    try:
        java_version = subprocess.Popen(['java', '-version'], stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False, startupinfo=startupinfo).communicate()[1].splitlines()[0]
    except:
        # throw away the can't find java exception
        pass

    if java_version and java_regex.match(java_version):
        return True
    else:
        return False

print is_java_installed()

@lethanhtu2
Copy link

Problem, "which" is command in linux and "where" is command in windows. You must change function like this:
def _java_installed():
#p = Popen(["which","java"], stdout=PIPE)
if sys.platform =='win32':
p = Popen(["where","java"], stdout=PIPE)
else:
p = Popen(["which","java"], stdout=PIPE)
return len(p.stdout.readlines()) != 0

@lindsay-stevens
Copy link
Contributor

Windows support for this has been fixed for a while, since #63. And since ec28a04 it's using the platform-independent method of just trying to call java -version and deciding if it's installed based on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants