Ubuntu 12.10, python 3 and SABnzbd

Support for the Debian/Ubuntu package, created by JCFP.
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

FWIW:

It seems Ubuntu 12.10 Quantal Quetzal will be moving more into the direction of python 3, as https://wiki.ubuntu.com/QuantalQuetzal/ ... Python_3.0 says:
Python 3.0

For 12.10, we intend to ship only Python 3 with the Ubuntu desktop image, not Python 2. Alpha-1 begins this process, with the installer and some other applications ported to Python 3. There are still quite a few packages left to port, and so Python 2 and 3 are both installed for the time being.

If you have your own programs based on Python 2, fear not! Python 2 will continue to be available (as the python package) for the foreseeable future. However, to best support future versions of Ubuntu you should consider porting your code to Python 3. Python/3 has some advice and resources on this.
So that would mean 12.10 has - by default - only python 3.x installed, right?

As SABnzbd is not ready for Python 3 (AFAIK), I wonder what will happen when only Python 3 is installed: http://packages.ubuntu.com/quantal/sabnzbdplus says "python (>= 2.7.1-0ubuntu2)". Does that mean that if only Python 3, sabnzbdplus will try to use that?

I would say a requirement for sabnzbdplus is python 2.x. So something like "python >= 2.6 and < 3.x"?
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

FYI:

I just live-booted Quantal, and both python 2.7 and 3 are installed, and python 2.7 is even still the default python:

Code: Select all

ubuntu@ubuntu:~$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.10
DISTRIB_CODENAME=quantal
DISTRIB_DESCRIPTION="Ubuntu quantal (development branch)"
ubuntu@ubuntu:~$

ubuntu@ubuntu:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:44:07) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
ubuntu@ubuntu:~$ python3
Python 3.2.3 (default, May  3 2012, 15:54:42) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Removing python2.7 from Quantal is practically impossible; it warns a lot of internal programs depend on it.

So there is no problem at the moment, but I wonder what will happen with sabnzbdplus if indeed only python 3 is installed on a system
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

Funny:

Code: Select all

sander@quantal:~$ which sabnzbdplus 
/usr/bin/sabnzbdplus

sander@quantal:~$ python3 `which sabnzbdplus`
  File "/usr/bin/sabnzbdplus", line 21
    print "Sorry, requires Python 2.5 or higher."
                                                ^
SyntaxError: invalid syntax
sander@quantal:~$
So, the print command goes wrong because in python3 it needs (), and the message itself is not correct either: it should be "Sorry, requires Python 2.5, 2.6 or 2.7."
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by shypike »

Solved in 0.7.1, the message I mean.
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

shypike wrote:Opgelost in 0.7.1
It indeed is:

Code: Select all

sander@R540:~/SABnzbd-0.7.1RC3$ python3 SABnzbd.py 
  File "SABnzbd.py", line 20
    print "Sorry, requires Python 2.5, 2.6 or 2.7."
                                                  ^
SyntaxError: invalid syntax
sander@R540:~/SABnzbd-0.7.1RC3$ 
Thank you.


FYI: Python3 already fails on the first 'if' command with the print "" command:

Code: Select all

if sys.version_info < (2, 5):
    print "Sorry, requires Python 2.5, 2.6 or 2.7."
    sys.exit(1)
if sys.version_info >= (3, 0):
    print("Sorry, requires Python 2.5, 2.6 or 2.7.")
    sys.exit(1)

Reason: Python first check / byte-compiles the whole file and python 3 does not accept the print "..." command ...

So, the second 'if' will not be reached by python 3 ... ;)
I guess that's OK for now.

Just for information, there is a way to really solve this: Create a separate file like runSAB.py with these contents:

Code: Select all

#!/usr/bin/python -OO
import sys
if sys.version_info >= (3, 0):
    sys.stdout.write("Sorry, requires Python 2.x, not Python 3.x\n")
    sys.exit(1)

import SABnzbd
if __name__ == "__main__":
    SABnzbd.main()
The above code works both in python 2 and python 3.
SABnzbd.py and all other files stay unchanged. Then run runSAB.py. When you run it with pyhon3, this is the output:

Code: Select all

sander@R540:~/SABnzbd-0.7.1RC3$ python3 runSAB.py 
Sorry, requires Python 2.x, not Python 3.x
sander@R540:~/SABnzbd-0.7.1RC3$
I guess we can wait until distributions have "python" pointing to python 3. I really wonder whether people 'dare' to do this for Ubuntu 12.10. Let's wait and see ...
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

FWIW:

I did something else: I ran "2to3 -w SABnzbd.py" to convert SABnzbd.py to python3-compliant. There are two types of changes:
1) print "" commands changed to print()
2) "except socket.error, error:" is changed into "except socket.error as error:".

Ad 1:
I believe python 2.7 can handle print(). I don't know about 2.5 and 2.6.

Ad 2:
The real question is what is meant with "except socket.error, error:"? The website http://www.ibm.com/developerworks/linux ... exceptions has a nice article on this, with the qoute "So, to deal with the ambiguities, the comma (,) is substituted with the keyword as when you want to bind the exception object to another name. If you want to catch multiple exceptions, parentheses (()) are required. "
@shypike: which one is meant in SABnzbd.py? I guess it's multiple exceptions? If so, I wonder if python 2.x can handle () ...

Ignoring the Ad 2 stuff, running the 2to3'ed SABnzbd.py with python3 now results in a nice error message:

sander@R540:~/SABnzbd-0.7.1RC3$ python3 SABnzbd.py
Sorry, requires Python 2.5, 2.6 or 2.7.
sander@R540:~/SABnzbd-0.7.1RC3$

Running with python2 results in a normally running SABnzbd (as far as I can see; not tested for the try/except stuff).
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by shypike »

The install.txt already states that Python 3.0 doesn't work.
I'll change the order of the test, maybe that will help.
Other than that, what were the Py3 designers smoking when they thought this up...
It's just too much work to support Python3 as well.
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

shypike wrote:The install.txt already states that Python 3.0 doesn't work.
I'll change the order of the test, maybe that will help.
Nope, it won't. I already tried all kinds of things. >:(
shypike wrote: Other than that, what were the Py3 designers smoking when they thought this up...
It's just too much work to support Python3 as well.
You're referring to Python 3 not being compatible with Python 2? Yep, nasty indeed. So let's see whether Ubuntu 12.04 really uses Python 3 as default or as only Python ...
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

@shypike:

Can you explain what SABnzbd.py means/wants with "except socket.error, error:"? Does it mean to catch both errors (that's my guess), or does it mean to 'cast'/assign the first error into the second (not likely, as 'error' is not used in the following lines)?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by shypike »

sander wrote:So let's see whether Ubuntu 12.04 really uses Python 3 as default or as only Python ...
3.0 as the only Python in Ubuntu.
Yeah right, like they're going to port all of their scripting.

"except socket.error, error:" is correct. The first part is the exception type, the second one is the variable
in which additional information will be available.
The confusion addressed in the IBM article is about this statement:
except IndexError, KeyError
where the intention was
except (IndexError, KeyError)
For multiple socket errors you would use:
except (socket.error, socket.error2), error
So, for an unambiguous statement you would use:
except (socket.error, ), error

I hope you're not wasting your time with porting to 3.0?
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

shypike wrote:
I hope you're not wasting your time with porting to 3.0?
No, no, certainly not ... Just wasting my time on making the file SABnzbd.py readable for Python 2.5 - Python 3.x. ;-)

As said, there seems to be just two types of commands in SABnzbd.py that need a different syntax to make it pyhton3 compatible:

Changing print "" into print("") is no problem for Python 2.5, 2.7 and 3.x

Changing the "except IOError, error:" into "except IOError as error:" is OK for Python 2.7 and Python 3.x, however not OK for Python 2.5.

Question: where is the value of 'error' used? I tried to find it, but I'm not sure: Bail_Out uses 'err' not 'error'. The only occurrence where it is used, is " if str(error) == 'Port not bound.':" ... is that it? Or is it used outside SABnzbd.py?

EDIT: Let me explain the previous paragraph a bit better:

This part is clear:

Code: Select all

    try:
        cherrypy.process.servers.check_port(browserhost, cherryport)
    except IOError, error:
        if str(error) == 'Port not bound.':
            pass
but why the 'error' here:

Code: Select all

            try:
                cherrypy.process.servers.check_port(cherryhost, https_port)
            except IOError, error:
                Bail_Out(browserhost, cherryport)
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

Note to myself:

The universal method for Python 2.5 - Python 3.2 to put the exception error value into variable "error" is:

Code: Select all

except ZeroDivisionError:
	_, error, _ = sys.exc_info()
So, in SABnzbd.py. replace each:

print "..." with print("..."),
", error:" with ": <newline + tabs> _, error, _ = sys.exc_info()"

and SABnzbd.py itself can be read by python 2.5, 2.7 and 3.2. :-)

And now wait for Ubuntu 12.10 and see how bold the Ubuntu / Canonical devs are about Python 3 ...
User avatar
jcfp
Release Testers
Release Testers
Posts: 989
Joined: February 7th, 2008, 12:45 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by jcfp »

sander wrote:
[...]If you have your own programs based on Python 2, fear not! Python 2 will continue to be available (as the python package) for the foreseeable future [...]
So that would mean 12.10 has - by default - only python 3.x installed, right?

As SABnzbd is not ready for Python 3 (AFAIK), I wonder what will happen when only Python 3 is installed: http://packages.ubuntu.com/quantal/sabnzbdplus says "python (>= 2.7.1-0ubuntu2)". Does that mean that if only Python 3, sabnzbdplus will try to use that?

I would say a requirement for sabnzbdplus is python 2.x. So something like "python >= 2.6 and < 3.x"?
Nope. Debian packaging considers python 2 and python 3 as two separate programs. The 'python' package is python 2 only, while version 3 comes in the form of the 'python3' package. Hence, there's no need to impose an upper version limit (of < 3) on the dependency.

The possibility of python v. 2 possibly no longer being installed by default isn't very relevant either. If it's not yet installed, the installation of the sab package will just pull it in like any other dependency. So as long as it's available somewhere, there should be no issue here.
User avatar
sander
Release Testers
Release Testers
Posts: 8839
Joined: January 22nd, 2008, 2:22 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by sander »

FWIW: http://www.h-online.com/open/news/item/ ... 54180.html

"Ubuntu 12.10 Alpha 3 includes ... Python 3 (Python 2 is available from the repositories but will not be installed by default), "

If this really happens, I expect no problems based on jcfp's last message, but let keeps on eye on it.
zoggy
Release Testers
Release Testers
Posts: 75
Joined: February 8th, 2011, 3:08 pm

Re: Ubuntu 12.10, python 3 and SABnzbd

Post by zoggy »

Post Reply