0

I've been trying to run these scripts https://github.com/balsamiq/mockups-strings-extractor within XP. I'm getting errors per this screenshot https://www.dropbox.com/s/rlbqp1iytkwvq3m/Screenshot%202014-05-30%2011.57.48.png

Also I tried CD into my test directory and although a text output file is generated it is empty and I still get these errors https://www.dropbox.com/s/odjfbr97e5i4gnn/Screenshot%202014-05-30%2012.09.31.png

Is anybody running Balsamiq on windows able to make this work ?

Julie S.
  • 127
  • 3
  • 18

1 Answers1

1

1) From the looks of the first error pic you included, you were trying to execute a Windows Shell command inside of a Python Interpreter. If you've still got the window open, type quit() before attempting your command again.

2) Your script was written for Python 2.x. If you're using Python 3.x, you'll need to add parentheses to the print lines in the script file and change urllib to urllib.parse. I made the changes below:

import os
import glob
import re
import urllib.parse

for infile in glob.glob( os.path.join(".", '*.bmml') ):
    print("STRINGS FOUND IN " + infile)
    print("===========================================================")
    f = open (infile,"r")
    data = f.read()
    p = re.compile("<text>(.*?)</text>")
    textStrings = p.findall(data)
    print(urllib.parse.unquote('\n'.join(textStrings))+"\n")
    f.close()

Hope this helps.

Samba
  • 199
  • 2
  • 6
  • Thank you very much. I made the changes you suggested and get error per https://www.dropbox.com/s/8yy0i05ll5bbwsv/Screenshot%202014-05-31%2020.59.48.png – Julie S. Jun 01 '14 at 01:03
  • @JulieS.: When stdout is redirected, Python uses the encoding returned by `locale.getpreferredencoding()`, such as Windows code page 1252 in your case. The environment variable `PYTHONIOENCODING` overrides this, but it's also simple enough to just rebind `stdout` when output is redirected: `if not sys.stdout.isatty(): sys.stdout = io.TextIOWrapper(sys.stdout.detach(), 'utf-8')`. The same applies to `sys.stdin` and `sys.stderr`. – Eryk Sun Jun 01 '14 at 08:35
  • @eryksun - could you please clarify what I should do step by step ? Where do I place this "rebind" code ? – Julie S. Jun 01 '14 at 11:42
  • 1
    @JulieS., rebind `sys.stdout` to the UTF-8 `TextIOWrapper` at the start of your program, before you execute the for loop. You also need `import sys, io` to use those modules. If you don't follow that, just run `set PYTHONIOENCODING=utf8` in the cmd shell to override the default encoding for stdin, stdout, and stderr. – Eryk Sun Jun 01 '14 at 11:51
  • I did not follow that :) but I did run set PYTHONIOENCODING=utf8 in the cmd shell and now the string extraction works! Thank you! I will mark this question as answered. – Julie S. Jun 01 '14 at 12:50
  • The script no longer seems to be working as I am getting a 0 kb in the resulting "out.txt" per https://www.dropbox.com/s/7cjivjce8bvyl93/Screenshot%202014-06-07%2015.52.03.png. I do not believe I changed anything since last week. – Julie S. Jun 07 '14 at 19:53
  • Your dropbox link isn't working. Can you share it again? – Samba Jun 08 '14 at 14:31
  • sorry about that - here it is again https://www.dropbox.com/s/7cjivjce8bvyl93/Screenshot%202014-06-07%2015.52.03.png – Julie S. Jun 09 '14 at 18:21
  • I'm gonna guess that you have Python 2.x installed on your computer. Change the first line of your script to `#!/usr/bin/python3`. – Samba Jun 10 '14 at 00:01
  • Actually, last week before I posted my question I installed Python34 - I do not believe i ever installed Python 2.x. Is there anything I can run to check if Pytyhon 2.x is installed also on the same computer ? Do I need to start the Python interpreter or something instead of running CMD ? @eryksun, any suggestion you may have would be greatly appreciated... – Julie S. Jun 10 '14 at 00:20
  • Even if you don't have another version of Python, let me know if the change I suggested works. If it didn't help, see what gets printed to the console if you don't redirect the output to `out.txt`. – Samba Jun 10 '14 at 01:04
  • @JulieS., you're running the script with Python 3, else `import urllib.parse` would raise an `ImportError` exception and print a traceback to `stderr`. Change the shebang to `#!/usr/bin/python3` anyway, just in case later on you decide to install 2.x. (FYI, Windows Python 3.3+ associates .py files with py.exe, which parses the shebang line to run a script with the specified interpreter.) To help debug your script, run it without redirecting stdout to `out.txt`, and add `print(textStrings)` to inspect the regex result. – Eryk Sun Jun 10 '14 at 01:45
  • Eryk , @Samba, thank you. I changed per your suggestions as https://www.dropbox.com/s/uhoewfb3lyxu3k5/Screenshot%202014-06-14%2015.28.08.png - unfortunately still 0kb in output and print(textStrings) also comes out empty. – Julie S. Jun 14 '14 at 19:29
  • @eryksun, unfortunately still 0 kb in output and print(textStrings) also comes out empty. – Julie S. Jun 22 '14 at 12:49
  • @Julie, I'm not sure why your new problem persists. I was able to run the code on my computer without a problem. I confess that I'm more familiar with the inner workings of Python than Windows. I suggest opening a new question; there may be someone with more Windows expertise to help you. – Samba Jun 23 '14 at 14:15