Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dan 29 posts 53 karma points
    Sep 18, 2009 @ 23:31
    dan
    0

    Python

    Hello all,

    I am trying to use python with the Umbraco CMS, and I am running into some problems with missing modules. I want to use a python script to send a request to a webservice with some querystrings and get a response and print that response. Does anyone know of a easier way to do this. I tried to use several modules including urllib and urllib2 but umbraco says that module not found. Any help would be great.

    Thank you

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Sep 19, 2009 @ 09:55
    Niels Hartvig
    2

    The current implementation of IronPython in Umbraco is *very* old and uses very early versions of IronPython - as such the implementation is very hacked and even "very'er" experimental.

    We're looking at either drop support for IronPython in 4.1 or re-write it.

  • Petr Snobelt 923 posts 1535 karma points
    Sep 19, 2009 @ 15:21
    Petr Snobelt
    0

    I never use python with umbraco and if umbraco doesn't need it +1 to drop it (and optionally move it to package or addon).

  • Immo Wache 69 posts 224 karma points
    Sep 19, 2009 @ 23:42
    Immo Wache
    2

    hi Dan, 
    long times ago (seams like about a year) i was playing around with Python in umbraco V3 and the upcoming V4.
    I wrote some articles in german :-((( on my blog about it, but one is translated into english which has some links for more info here: Snake Charming - Python in Umbraco

    Two next articles (in german) are about how to get the macro paramters from inside the Python script. But the basic solution you can find in the forum post here: access template properties and value via python

    One other Python macro I wrote is to remote wake up my home PC from web by use of WOL WakeOnLan. This script I found somewhere in the net and was not special written for umbraco. It uses IronPython network functions so it may be a hint for your problems.

    Immo

    The script goes here:

    import System.Web.HttpContext as HttpContext
    import socket
    import struct
    
    session = HttpContext.Current.Session
    
    pageElements = session['pageElements']
    if not pageElements:
        print "<h3>old Umbraco Version 3!</h3>"
        pageElements = session['page'].Elements
    macro = session['macro']
    args = session['args']
    
    print "Parameter 'value' has the content: " + args['value'] + "<br />"
    print "Page element 'pageName' is: " + pageElements['pageName'] + "<br />"
    print "This is the IronPython Macro with name: " + macro.Name + "<br />"
    
    macaddress = '01-23-45-67-89-00' # This is _not_ my real mac address!!!
    
    """ Switches on remote computers using WOL. """
    
    # Check macaddress format and try to compensate.
    if len(macaddress) == 12:
        pass
    elif len(macaddress) == 12 + 5:
        sep = macaddress[2]
        macaddress = macaddress.replace(sep, '')
    else:
        raise ValueError('Incorrect MAC address format')
    
    print "macaddress has the content: " + macaddress + "<br />"
    
    # Pad the synchronization stream.
    data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
    send_data = '' 
    
    # Split up the hex values and pack.
    for i in range(0, len(data), 2):
        send_data = ''.join([send_data,
                             struct.pack('B', int(data[i: i + 2], 16))])
    
    # Broadcast it to the WAN/LAN.
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    sock.sendto(send_data, ('iwache.dyndns.org', 9))
    

     

  • Immo Wache 69 posts 224 karma points
    Sep 20, 2009 @ 00:47
    Immo Wache
    0

    @Petr & @Niels

    IronPython in V3 is nice because one can write macro logic with full access to all the .net classes by writing a simple scipt in the umbraco backend. No need to use VS, compile a c# code and upload a dll. And the Python "print" function has some nice features, which I would prefer over the XSLT stuff in some cases.

    In V4 this all is much easier, writing some small c# scipts direct into a template is really cool. So the IronPython stuff is seldom useful now for me. May be it's a nice to have for web designers with only some basic programming knowledge in exactly this script language. But there are more buzz scipt languages out there usable in .net e.g. IronRuby, but currently not in Umbraco.

    Last days I found this blog post for IronRuby MVC by Phil Haack from the MS MVC Team:

    Scripting ASP.NET MVC Views Stored In The Database

    While trying and playing around with C# and ASP.NET MVC 1 within the current Umbraco 4 I thought by my self:

    Would'nt it be cool to have this Ruby stuff available in the Umbraco backend? Writing some simple controller, view and route scripts in Ruby inside the developer section and ready is your MVC macro?

    So I agree with Petr to remove Python from the Umbraco core, but one up for a (hopeful non experimental) plug in solution for script languages by use of packages.

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 21, 2009 @ 11:20
    Douglas Robar
    0

    @Immo, you can include .net classes in your xslt macros as well. (not often used... I should make a blog post about it)

    I know there are a few people who use the Python support so it would be unfortunate to remove that feature now that it is in use. On the other hand, it certainly doesn't come near the 80% rule for feature inclusion in umbraco. As many have said, a plug-in architecture to support IronPython (or other .net languages) would be a great way to return umbraco to its lean functionality without making it impossible for existing users to upgrade by losing functionality. Is this something that would be possible for umbraco 4.1, or is completely out of scope?

    cheers,
    doug.

  • dan 29 posts 53 karma points
    Sep 22, 2009 @ 18:06
    dan
    0

    Thanks a lot. Although this doesn't exactly answer my question. But since I can use .NET classes i think i can do something with that.


  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 22, 2009 @ 21:40
    Douglas Robar
    1

    Following up with a blog post about using .NET namespaces in your xslt macros... http://blog.percipientstudios.com/2009/9/21/advanced-xslt-with-net-namespaces.aspx

    cheers,
    doug.

  • Immo Wache 69 posts 224 karma points
    Sep 27, 2009 @ 13:15
    Immo Wache
    0

    @Doug, thanks alot for sharing  this cool tip. Good work! I like your solution alot :-)

  • montana 42 posts 63 karma points
    Oct 27, 2010 @ 00:09
    montana
    0

    I would say that being able to use python is one of the best features in this software, please for the love of all that is good and right with humanity do not disable it.

    IronPython does suck for sure, but it's better than no dynamic language at all [ !? ]. It also maybe allows developers from linux backgrounds to remain optimistic about this app. Why remove it and hose the people that like python?

    I honestly can say I know more people that use python than XSLT... jeez I hadn't even heard of anyone actually *using* XSLT since 2001 before I found this app. I thought for sure it had died/been abandoned. I think Python [even IronPython] has a bit brighter of a future just on a hunch.

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 27, 2010 @ 00:23
    Aaron Powell
    0

    You haven't checked out the latest version of Umbraco have you? We've kept DLR support and drastically improved it. We now have OOTB support with IronPython 2.6 and IronRuby ;)

  • montana 42 posts 63 karma points
    Oct 27, 2010 @ 04:47
    montana
    0

    No I have, for sure. I'm working with the latest revision now I believe. Just wanted to chime in an a year old thread [there appear to be lots of those when searching for python related topics =P ]

    The support for *some kind of a dynamic language* in .NYET, is awesome, although the future for these languages appears dim. [ http://www.ibtimes.com/articles/43073/20100812/microsoft.htm ]

     

  • Jonas Eriksson 930 posts 1825 karma points
    Oct 27, 2010 @ 06:01
    Jonas Eriksson
    0

    Hi Montana, its nice to see interest in Python within Umbraco. As you mention there's not much to be found about it here yet, I guess simply because very few use it. I started playing with IronPython this summer and found the 2.6 implementation in Umbraco to be very good. Perhaps you've already read this thread: http://our.umbraco.org/forum/developers/extending-umbraco/11296-IronPython-lab where the usefullness and some quirks of the current IronPython implementation (and Python itself) are discussed. I'd be very happy to see more Python-activity in the forums / wikis / packages. Especially from developers with earlier Python experience.

    Regards

    Jonas

  • montana 42 posts 63 karma points
    Oct 28, 2010 @ 03:28
    montana
    0

    cool beans, I love python. I'm actually working on moving all the xslt macros I have into python. I'll post some results as I work through some of the transition phase here.

    Thank you

     

  • Jonas Eriksson 930 posts 1825 karma points
    Oct 28, 2010 @ 11:48
    Jonas Eriksson
    0

    Great, looking forward to hear more from you about that.

    There's also a couple of snippets here: http://our.umbraco.org/wiki/reference/code-snippets/ironpython-samples

    Should be a new thread I guess, but anyways: I've been looking for a nice and clean way to do render my html with Python. Best way would perhaps be using a library like Jinja2 or Cheetah. But I havent succeeded using them in Umbraco IronPython. Did you try / do you intend to try that?

    Something like the following would be nice (in IronRuby with Erb template engine):

     

    require "erb"
     
    # Create ERB-template
     
    template = %{
         
    <h1>h1>
           
    <ul>
           

               
    <li>li>
           

           
    </ul>
      }.gsub(/
    ^  /, '')
      rhtml
    = ERB.new(template)
      rhtml
    .run(binding)

     

Please Sign in or register to post replies

Write your reply to:

Draft