]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Make omkbuild Python 3 compatible
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 8 Sep 2014 22:48:51 +0000 (00:48 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 8 Sep 2014 23:21:28 +0000 (01:21 +0200)
omkbuild.py

index f4095637e98d59985aa3ad53198f5566002ca35e..b1c0a1231ce0f6362affe11c27ee3306e4db690c 100755 (executable)
@@ -39,7 +39,6 @@ from optparse import OptionParser
 import os
 import os.path
 import sys
-import string
 import re
 
 rulesDir = "rules"
@@ -136,15 +135,15 @@ class Snippet:
         s = "<Snippet: %s>" % self.name
         return s
 
-    def __cmp__(self, other):
-        ret = cmp(self.name, other.name)
-        if ret != 0: return ret
-        ret = cmp(self.legal, other.legal)
-        if ret != 0: return ret
-        ret = cmp(self.doc, other.doc)
-        if ret != 0: return ret
-        ret = cmp(self.code, other.code)
-        return ret
+    def __eq__(self, other):
+        return \
+            self.name == other.name and \
+            self.legal == other.legal and \
+            self.doc == other.doc and \
+            self.code == other.code
+
+    def __ne__(self, other):
+        return not self == other
 
     def __getitem__(self, key):
         return {
@@ -179,8 +178,11 @@ class Snippets:
     def __iter__(self):
         return iter(self._order)
 
-    def __cmp__(self, other):
-        return cmp(self._snippets, other._snippets)
+    def __eq__(self, other):
+        return self._snippets == other._snippets
+
+    def __ne__(self, other):
+        return not self == other
 
     def loadFromFiles(self, fnames):
         """Reads the snippets from several files and adds them to itself."""
@@ -241,9 +243,9 @@ class MakefileRules(LineList):
                 # Add this line to rules
                 if addMarker:
                     if addMarker==1:
-                        line = string.rstrip(line).ljust(80)+" #OMK:%s@%s\n"%(filename,baseFileName)
+                        line = line.rstrip().ljust(80)+" #OMK:%s@%s\n"%(filename,baseFileName)
                     elif addMarker==2:
-                        line = string.rstrip(line).ljust(80)+" #OMK:%s\n"%(filename)
+                        line = line.rstrip().ljust(80)+" #OMK:%s\n"%(filename)
                     addMarker = 0
                 if not onlyLoadSnippets:
                     self.rules += [line]
@@ -261,7 +263,7 @@ class MakefileRules(LineList):
             for snip in self.snippets:
                 lines = snip[type]
                 if len(lines) == 0: continue
-                firstLine = string.rstrip(lines[0])
+                firstLine = lines[0].rstrip()
                 self.rules += [firstLine.ljust(80)+" #OMK:%s\n"%snip.name]
                 self.rules += lines[1:]
                 #self.rules += ['a'] # test error
@@ -371,7 +373,7 @@ def splitRules(rulesFN, output):
     for snip in rules.snippets:
         if snip.name[0:2] == "__":
             continue
-        print snip.name
+        print(snip.name)
         f = None
         if output == "-": f = sys.stdout
         else: f = open(snip.name, "w+")