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

Receiving Error on Line 29 of generate-xml.py #2

Closed
jribs opened this issue Jun 3, 2015 · 6 comments
Closed

Receiving Error on Line 29 of generate-xml.py #2

jribs opened this issue Jun 3, 2015 · 6 comments

Comments

@jribs
Copy link

jribs commented Jun 3, 2015

First off, thank you for the work you've done. The Android 5 stencils are incredibly useful. There are issues arising from the python script saying " 'Nonetype' object has no attribute 'group' ". Unfortunately I'm not too familiar with Python script.The error is coming from line 29:

element.set('name', (match.group(1) + ' - ' + match.group(2).replace('_', ' ')).title())

The gen folder is created, but no actions are performed after that. Any suggestions would be much appreciated:

image

@nathanielw
Copy link
Owner

Oh, I haven't tried generating the stencil collection on Windows, so I suspect it could be a Windows-specific problem. It looks like the regex I'm using to extract the icon name from its file path isn't matching anything, probably because Windows uses backslashes (rather than forward slashes) in its paths. I'll hopefully just need to change it so that it's matching against a platform-independent path.

I'll try and get it fixed tomorrow some time. Cheers for the report.

Edit: I'm away from a computer at the moment, but if you're wanting to try and get it working, try replacing str(f) on line 28 with f.as_posix() (and maybe also do the same for any other lines that call str on a file path).

@jribs
Copy link
Author

jribs commented Jun 3, 2015

Thanks for the swift response. I Replaced all str(f)'s, and graduated from line 29 to line 35. The error is posted below, but I will wait for your solution instead of suggestion ping-pong.

image

@nathanielw
Copy link
Owner

Interesting. I just set up Python on Windows and am getting the same error.
It looks like Cairosvg is failing to find a constant in the pycairo module. I just tried with a super-simple script as well:

import cairosvg
cairosvg.svg2png(file_obj='./svg.svg', write_to='./svg.png')

And am still getting the error, so I don't think it's something wrong with the script - likely we're both doing something incorrect when installing pycairo or it's a bug in cairosvg.

I'm now trying to get cairocffi installed, which might fix the problem.

And the error (in case anyone is searching it):

PS F:\Programming\Material-Icons-for-Pencil> python.exe .\test.py
Traceback (most recent call last):
  File ".\test.py", line 3, in <module>
    cairosvg.svg2png(file_obj='./svg.svg', write_to='./svg.png')
  File "C:\Python34\lib\site-packages\cairosvg\__init__.py", line 43, in <lambda>
    surface_type.convert(*args, **kwargs))(_surface_type)
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 87, in convert
    cls(tree, output, dpi).finish()
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 141, in __init__
    self.draw_root(tree)
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 194, in draw_root
    self.draw(node)
  File "C:\Python34\lib\site-packages\cairosvg\surface\__init__.py", line 324, in draw
    "optimizeSpeed": cairo.ANTIALIAS_FAST,
AttributeError: 'module' object has no attribute 'ANTIALIAS_FAST'

@nathanielw
Copy link
Owner

Update: Installing cairocffi seemed to do the trick!

So the steps I followed:

  1. Install Python version >=3.4 (and pip, which seems to be included in the Windows installer)
  2. If you want, set up virtualenv
  3. Install lxml. pip install lxml doesn't seem to be working for me on Windows, so I used the unofficial binary from http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
  4. Install cairosvg: pip install cairosvg
  5. Install cairocffi: pip install cairocffi
  6. At this point it might be worth trying to run the generate-xml script and seeing if it works...
  7. ...If not, install the GTK+ Runtime (as noted in the cairocffi docs)
  8. Restart your command prompt and try running the generate-xml.py script again. Hopefully it'll work!

(I'll still need to change the script to use f.as_posix() on line 28)
Edit: looks like there still might be some more changes I'll need to make for the generated xml to actually be useful, (probably also to do with paths from the looks of things). Getting late here so I'll look at it tomorrow.

@nathanielw
Copy link
Owner

That commit fixes any issues I was still getting on Windows, hopefully the steps above now work for you too!

@jribs
Copy link
Author

jribs commented Jun 5, 2015

Everything worked just fine in your steps. The last step (installing GDK+) was my specific issue. Thank you for making this compatible with the Windows environment and the quick response.

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

2 participants