From 0272b2abc484f15ab247c8a637288af3ca3575a7 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 1 Oct 2009 18:59:03 +0200 Subject: [PATCH] [entropy] more Python 2.6/3.x compat fixes --- client/equo.py | 26 ++++++++++++++------------ client/text_query.py | 2 +- libraries/entropy/db.py | 6 +++--- libraries/entropy/tools.py | 10 +++++++--- sulfur/src/sulfur/progress.py | 2 +- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/client/equo.py b/client/equo.py index ec6612cd5..5bc6acc6a 100644 --- a/client/equo.py +++ b/client/equo.py @@ -737,45 +737,46 @@ def main(): except OnlineMirrorError as e: - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(101) except RepositoryError as e: reset_cache() - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(101) except FtpError as e: - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(101) except PermissionDenied as e: - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(1) except FileNotFound as e: - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(1) except SPMError as e: - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(1) except dbapi2Exceptions['OperationalError'] as e: - if unicode(e).find("disk I/O error") == -1: + if str(e).find("disk I/O error") == -1: raise - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue. Your hard disk is probably faulty."),) )) + print_error("%s %s. %s." % (darkred(" * "), e, + _("Cannot continue. Your hard disk is probably faulty."),)) raise SystemExit(101) except SystemError as e: # becoming from entropy.db - print_error(darkred(" * ")+red(unicode(e)+". %s." % (_("Cannot continue"),) )) + print_error("%s %s. %s." % (darkred(" * "), e, _("Cannot continue"),)) raise SystemExit(1) except SystemExit: @@ -791,7 +792,8 @@ def main(): if e.errno == 28: entropyTools.print_exception() - print_error(darkred(_("Your hard drive is full! Next time remember to have a look at it before starting. I'm sorry, there's nothing I can do for you. It's your fault :-("))) + print_error("%s %s. %s." % (darkred(" * "), e, + _("Your hard drive is full! Next time remember to have a look at it before starting. I'm sorry, there's nothing I can do for you. It's your fault :-("),)) raise SystemExit(5) else: raise @@ -828,7 +830,7 @@ def main(): ferror = open("/tmp/equoerror.txt","aw") ferror.write("\n\n") for x in exception_data: - ferror.write(unicode(x)+"\n") + ferror.write("%s\n" % (e,)) ferror.flush() ferror.close() except Exception as e: @@ -859,7 +861,7 @@ def main(): "/sabayonlinux.org/handlers/http_error_report.php" error = ErrorReportInterface(post_url) - error.prepare(errorText, name, email, '\n'.join([unicode(x) for x in exception_data]), description) + error.prepare(errorText, name, email, '\n'.join([x for x in exception_data]), description) result = error.submit() if result: print_error(darkgreen(_("Thank you very much. The error has been reported and hopefully, the problem will be solved as soon as possible."))) diff --git a/client/text_query.py b/client/text_query.py index 303857f86..d8c7b9393 100644 --- a/client/text_query.py +++ b/client/text_query.py @@ -251,7 +251,7 @@ def search_changelog(atoms, dbconn = None, Equo = None): print_generic(_("No ChangeLog available")) else: print_generic(changelog) - print("="*80) + print_generic("="*80) return 0 diff --git a/libraries/entropy/db.py b/libraries/entropy/db.py index 308b1b484..9f1129091 100644 --- a/libraries/entropy/db.py +++ b/libraries/entropy/db.py @@ -1500,7 +1500,7 @@ class EntropyRepository: ) myidpackage_string = 'NULL' - if isinstance(idpackage, (int, long)): + if isinstance(idpackage, (int,)): manual_deps = self.retrieveManualDependencies(idpackage) @@ -4513,7 +4513,7 @@ class EntropyRepository: excluded_deptypes_query = "" if exclude_deptypes != None: for dep_type in exclude_deptypes: - if not isinstance(dep_type, (int, long)): + if not isinstance(dep_type, (int,)): # filter out crap continue excluded_deptypes_query += " AND dependencies.type != %s" % ( @@ -8376,7 +8376,7 @@ class EntropyRepository: atomUse = () atomSlot = self.entropyTools.dep_getslot(atom) atomRev = self.entropyTools.dep_get_entropy_revision(atom) - if isinstance(atomRev, (int, long)): + if isinstance(atomRev, (int,)): if atomRev < 0: atomRev = None # use match diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index 1c23a8ae2..f75994e52 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -608,7 +608,7 @@ def movefile(src, dest, src_basedir = None): # The utime can fail here with EPERM even though the move succeeded. # Instead of failing, use stat to return the mtime if possible. try: - long(os.stat(dest).st_mtime) + int(os.stat(dest).st_mtime) return True except OSError as e: print_generic("!!! Failed to stat in movefile()\n") @@ -2622,7 +2622,11 @@ def isnumber(x): @return: @rtype: """ - return isinstance(x, (long, int)) + try: + int(x) + return True + except ValueError: + return False def istextfile(filename, blocksize = 512): @@ -3515,7 +3519,7 @@ def is_valid_string(string): @return: @rtype: """ - invalid = [ord(x) for x in string if ord(x) not in range(32, 127)] + invalid = [ord(x) for x in string if ord(x) not in list(range(32, 127))] if invalid: return False return True diff --git a/sulfur/src/sulfur/progress.py b/sulfur/src/sulfur/progress.py index c3968ad7c..b3c92cc6b 100644 --- a/sulfur/src/sulfur/progress.py +++ b/sulfur/src/sulfur/progress.py @@ -80,7 +80,7 @@ class _Total: return self.gtk_loop() self.lastFrac = now+0.01 - percent = long(self._percent(1, now)) + percent = int(self._percent(1, now)) self.progress.set_fraction(now) if prefix: text = "%s : %3i%%" % (prefix, percent)