python3: Fix incompatible prints and exceptions

Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Signed-off-by: Jiri Kastner <jkastner@redhat.com>
diff --git a/pchrt.py b/pchrt.py
index c590b37..ddb1265 100755
--- a/pchrt.py
+++ b/pchrt.py
@@ -14,13 +14,14 @@
 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 #   General Public License for more details.
 
+from __future__ import print_function
 import os
 import schedutils
 import sys
 
 
 def usage():
-    print '''pchrt (python-schedutils)
+    print('''pchrt (python-schedutils)
 usage: pchrt [options] [prio] [pid | cmd [args...]]
 manipulate real-time attributes of a process
   -b, --batch                        set policy to SCHED_BATCH
@@ -35,16 +36,16 @@
 
 You must give a priority if changing policy.
 
-Report bugs and send patches to <tuna-devel@lists.fedorahosted.org>'''
+Report bugs and send patches to <tuna-devel@lists.fedorahosted.org>''')
     return
 
 
 def show_priority_limits(policy):
-    print "%-32.32s: %d/%d" % (
+    print("%-32.32s: %d/%d" % (
         "%s min/max priority" % schedutils.schedstr(policy),
         schedutils.get_priority_min(policy),
         schedutils.get_priority_max(policy)
-    )
+    ))
 
 
 def show_all_priority_limits():
@@ -60,14 +61,15 @@
     reset_on_fork = ""
     if policy & schedutils.SCHED_RESET_ON_FORK:
         reset_on_fork = "|SCHED_RESET_ON_FORK"
-    print '''pid %d's current scheduling policy: %s%s
-pid %d's current scheduling priority: %d''' % (pid, spolicy, reset_on_fork, pid, rtprio)
+    print('''pid %d's current scheduling policy: %s%s
+pid %d's current scheduling priority: %d''' % (pid, spolicy, reset_on_fork,
+                                               pid, rtprio))
 
 
 def valid_policy_flag(policy, policy_flag):
     if policy_flag == schedutils.SCHED_RESET_ON_FORK and \
        policy not in (schedutils.SCHED_RR, schedutils.SCHED_FIFO):
-        print "SCHED_RESET_ON_FORK flag is supported for SCHED_FIFO and SCHED_RR policies only"
+        print("SCHED_RESET_ON_FORK flag is supported for SCHED_FIFO and SCHED_RR policies only")
         return False
     return True
 
@@ -75,9 +77,9 @@
 def change_settings(pid, policy, policy_flag, rtprio):
     try:
         schedutils.set_scheduler(pid, policy | policy_flag, rtprio)
-    except SystemError, err:
-        print "sched_setscheduler: %s" % err[1]
-        print "failed to set pid %d's policy" % pid
+    except SystemError as err:
+        print("sched_setscheduler: %s" % err[1])
+        print("failed to set pid %d's policy" % pid)
 
 
 def main():
diff --git a/ptaskset.py b/ptaskset.py
index de925a9..56fe7af 100755
--- a/ptaskset.py
+++ b/ptaskset.py
@@ -14,19 +14,20 @@
 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 #   General Public License for more details.
 
+from __future__ import print_function
 import os
 import schedutils
 import sys
 
 
 def usage():
-    print '''ptaskset (python-schedutils)
+    print('''ptaskset (python-schedutils)
 usage: ptaskset [options] [mask | cpu-list] [pid | cmd [args...]]
 set or get the affinity of a process
 
   -p, --pid                  operate on existing given pid
   -c, --cpu-list             display and specify cpus in list format
-  -h, --help                 display this help'''
+  -h, --help                 display this help''')
 
     return
 
@@ -103,7 +104,7 @@
         if len(ends) > 2:
             raise "Syntax error"
         if len(ends) == 2:
-            cpu_list += range(int(ends[0]), int(ends[1]) + 1)
+            cpu_list += list(range(int(ends[0]), int(ends[1]) + 1))
         else:
             cpu_list += [int(ends[0])]
     return list(set(cpu_list))
@@ -115,7 +116,7 @@
         mask = ",".join([str(a) for a in affinity])
     else:
         mask = ",".join(["%x" % a for a in hexbitmask(affinity)])
-    print "pid %d's %s affinity mask: %s" % (pid, when, mask)
+    print("pid %d's %s affinity mask: %s" % (pid, when, mask))
 
 
 def change_settings(pid, affinity, cpu_list_mode):
@@ -129,9 +130,9 @@
 
     try:
         schedutils.set_affinity(pid, affinity)
-    except SystemError, err:
-        print "sched_setaffinity: %s" % err[1]
-        print "failed to set pid %d's affinity" % pid
+    except SystemError as err:
+        print("sched_setaffinity: %s" % err[1])
+        print("failed to set pid %d's affinity" % pid)
 
 
 def main():