From 1de4608f658cf6357d624f5cb749af625fdd7a8d Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 4 Feb 2010 19:34:50 +0100 Subject: [PATCH] [equo] warn user if equo/entropy version mismatch --- client/equo.py | 22 ++++++++++++++++++---- client/text_tools.py | 23 ++++++++++++++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/client/equo.py b/client/equo.py index c7f05b0ff..e08a3c9ab 100644 --- a/client/equo.py +++ b/client/equo.py @@ -24,8 +24,8 @@ from entropy.exceptions import SystemDatabaseError, OnlineMirrorError, \ SPMError, IncorrectParameter from entropy.output import red, darkred, darkgreen, TextInterface, \ print_generic, print_error, print_warning, readtext, nocolor, \ - is_stdout_a_tty -from text_tools import print_menu, print_bascomp + is_stdout_a_tty, bold, purple, blue +from text_tools import print_menu, print_bascomp, read_equo_release from entropy.const import etpConst, etpUi, const_convert_to_rawstring import entropy.tools try: @@ -762,7 +762,8 @@ if (not options) or ("--help" in options): # print version if options[0] == "--version": - print_generic("equo: "+etpConst['entropyversion']) + print_generic("entropy: "+etpConst['entropyversion']) + print_generic("equo: "+read_equo_release()) raise SystemExit(0) elif options[0] == "--info": import text_rescue @@ -923,10 +924,23 @@ def install_exception_handler(): def uninstall_exception_handler(): sys.excepthook = sys.__excepthook__ - +def warn_version_mismatch(): + equo_ver = read_equo_release() + entropy_ver = etpConst['entropyversion'] + if equo_ver != entropy_ver: + print_warning("") + print_warning("%s: %s" % ( + bold(_("Entropy/Equo version mismatch")), + purple(_("it could make your system explode!")),)) + print_warning("(%s [equo] & %s [entropy])" % ( + blue(equo_ver), + blue(entropy_ver),)) + print_warning("") def main(): + warn_version_mismatch() + install_exception_handler() rc = -10 diff --git a/client/text_tools.py b/client/text_tools.py index 4ca170921..e399afd8e 100644 --- a/client/text_tools.py +++ b/client/text_tools.py @@ -251,4 +251,25 @@ def enlightenatom(atom): rev = '-%s' % (rev,) return "%s%s%s%s%s%s%s" % (purple(operator), teal(cat + "/"), darkgreen(name), purple("-"+pv), purple(rev), brown(entropy_tag), - teal(entropy_rev),) \ No newline at end of file + teal(entropy_rev),) + +def read_equo_release(): + """ + Read Equo release. + + @rtype: None + @return: None + """ + # handle Entropy Version + revision_file = "../client/revision" + if not os.path.isfile(revision_file): + revision_file = os.path.join(etpConst['installdir'], + 'client/revision') + if os.path.isfile(revision_file) and \ + os.access(revision_file, os.R_OK): + + with open(revision_file, "r") as rev_f: + myrev = rev_f.readline().strip() + return myrev + + return "0" \ No newline at end of file