From 68258ec233909c9f64b8fea84d2e1ecd2bfe989e Mon Sep 17 00:00:00 2001 From: Phillip Heller Date: Wed, 23 Nov 2011 20:42:04 -0500 Subject: [PATCH] Fix recognition of Mac OS X based systems Previously, Mac OS X was recognized during py2app invocation, as well as runtime by comparison of os.name with 'macos'. The value of os.name reports as 'posix' under more recent version of Python built on Mac OS X. Now, the recognition is instead done by comparing sys.platform with 'darwin'. issue2258 review171004 (transplanted from d2d9d6ec6da433a5d7df4b07e089f21536b9e4fb) --- setup.py | 6 ++---- tryton/common/common.py | 3 +-- tryton/config.py | 3 +-- tryton/gui/main.py | 5 ++--- tryton/gui/window/view_form/view/list.py | 7 ++----- tryton/translate.py | 4 ++-- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index af297feeb0..34fdc3833b 100644 --- a/setup.py +++ b/setup.py @@ -89,8 +89,7 @@ if os.name == 'nt': args['windows'][0]['other_resources'] = [(24, 1, manifest)] -elif os.name == 'mac' \ - or (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): +elif sys.platform == 'darwin': import py2app from modulegraph.find_modules import PY_SUFFIXES PY_SUFFIXES.append('') @@ -253,8 +252,7 @@ if os.name == 'nt': Popen([makensis, "/DVERSION=" + VERSION, str(os.path.join(os.path.dirname(__file__), 'setup-single.nsi'))]).wait() -elif os.name == 'mac' \ - or (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): +elif sys.platform == 'darwin': def find_gtk_dir(): for directory in os.environ['PATH'].split(':'): if not os.path.isdir(directory): diff --git a/tryton/common/common.py b/tryton/common/common.py index ab0e4df1bb..4b09ed71e6 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -376,8 +376,7 @@ def file_open(filename, type, parent, print_p=False): save_p.close() file_p.close() return - elif os.name == 'mac' or \ - (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): + elif sys.platform == 'darwin': pid = os.fork() if not pid: pid = os.fork() diff --git a/tryton/config.py b/tryton/config.py index 32098f7765..2c3f532aed 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -30,8 +30,7 @@ if not os.path.isdir(get_config_dir()): def find_path(progs, args): if os.name == 'nt': return '' - if os.name == 'mac' or \ - (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): + if sys.platform == 'darwin': return '' paths = [x for x in os.environ['PATH'].split(':') if os.path.isdir(x)] diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 134079728b..3098966d21 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -87,7 +87,7 @@ class Main(object): gtk.gdk.CONTROL_MASK) gtk.accel_map_add_entry('/File/Quit', gtk.keysyms.Q, gtk.gdk.CONTROL_MASK) - if os.name != 'mac': + if sys.platform != 'darwin': gtk.accel_map_add_entry('/User/Menu Reload', gtk.keysyms.T, gtk.gdk.MOD1_MASK) gtk.accel_map_add_entry('/User/Menu Toggle', gtk.keysyms.T, @@ -191,8 +191,7 @@ class Main(object): self.sig_toolbar_show() self.sig_statusbar_show() - if os.name in ('nt', 'mac') or \ - (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): + if os.name == 'nt' or sys.platform == 'darwin': # Disable actions, on win32 we use os.startfile # and on mac we use /usr/bin/open self.menuitem_actions.set_sensitive(False) diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index 36e047ff68..ff459af822 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -351,9 +351,7 @@ class ViewList(ParserView): elif self.widget_tree.sequence: dnd = True # Disable DnD on mac until it is fully supported - if os.name == 'mac': - dnd = False - elif hasattr(os, 'uname') and os.uname()[0] == 'Darwin': + if sys.platform == 'darwin': dnd = False if screen.readonly: dnd = False @@ -480,8 +478,7 @@ class ViewList(ParserView): # Don't use set_with_data on mac see: # http://bugzilla.gnome.org/show_bug.cgi?id=508601 if selection.count_selected_rows() < 100 \ - or os.name == 'mac' \ - or (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): + or sys.platform == 'darwin': data = [] selection.selected_foreach(self.copy_foreach, data) clipboard.set_text('\n'.join(data)) diff --git a/tryton/translate.py b/tryton/translate.py index b5a0ad94a5..54654d09c6 100644 --- a/tryton/translate.py +++ b/tryton/translate.py @@ -8,6 +8,7 @@ from version import PACKAGE from tryton.client import CURRENT_DIR, PREFIX import logging import gtk +import sys _ = gettext.gettext @@ -169,8 +170,7 @@ def setlang(lang=None, locale_dict=None): lang2 = lang if os.name == 'nt': lang2 = _LOCALE2WIN32.get(lang, lang) - elif os.name == 'mac' or \ - (hasattr(os, 'uname') and os.uname()[0] == 'Darwin'): + elif sys.platform == 'darwin': encoding = 'UTF-8' # ensure environment variable are str lang, lang2, encoding = str(lang), str(lang2), str(encoding)