[pitivi] system: Fix detection of Mac and Windows
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] system: Fix detection of Mac and Windows
- Date: Thu, 5 May 2016 19:54:37 +0000 (UTC)
commit d30f7e003089b5488a75ee4f477c251f164a80ad
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Mon May 2 22:58:26 2016 +0200
system: Fix detection of Mac and Windows
Differential Revision: https://phabricator.freedesktop.org/D983
pitivi/application.py | 4 +-
pitivi/utils/system.py | 58 ++++++++++++++++++++++++-----------------------
tests/test_system.py | 4 +-
3 files changed, 34 insertions(+), 32 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index e3f8769..b1df9e5 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -47,7 +47,7 @@ from pitivi.utils.loggable import Loggable
from pitivi.utils.misc import path_from_uri
from pitivi.utils.misc import quote_uri
from pitivi.utils.proxy import ProxyManager
-from pitivi.utils.system import getSystem
+from pitivi.utils.system import get_system
from pitivi.utils.threads import ThreadMaster
from pitivi.utils.timeline import Zoomable
@@ -143,7 +143,7 @@ class Pitivi(Gtk.Application, Loggable):
self.threads = ThreadMaster()
self.effects = EffectsManager()
self.proxy_manager = ProxyManager(self)
- self.system = getSystem()
+ self.system = get_system()
self.project_manager.connect(
"new-project-loading", self._newProjectLoadingCb)
diff --git a/pitivi/utils/system.py b/pitivi/utils/system.py
index e7eb8b6..00ea12c 100644
--- a/pitivi/utils/system.py
+++ b/pitivi/utils/system.py
@@ -20,6 +20,7 @@ import datetime
import multiprocessing
import os
import resource
+import sys
from gi.repository import GObject
@@ -209,6 +210,8 @@ class GnomeSystem(FreedesktopOrgSystem):
def __init__(self):
FreedesktopOrgSystem.__init__(self)
+
+ import dbus
self.bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
# connect to gnome sessionmanager
@@ -221,12 +224,6 @@ class GnomeSystem(FreedesktopOrgSystem):
self.connect('update-power-inhibition', self._updatePowerInhibitionCb)
- def screensaver_is_blockable(self):
- return True
-
- def sleep_is_blockable(self):
- return True
-
def _updatePowerInhibitionCb(self, unused_system):
# there are two states we want the program to be in, with regards to
# power saving, the screen saver is inhibited when the viewer is watched.
@@ -271,34 +268,39 @@ class GnomeSystem(FreedesktopOrgSystem):
self.debug("already uninhibited")
-system_ = None
+class DarwinSystem(System):
+
+ """Apple OS X"""
+
+ def __init__(self):
+ System.__init__(self)
+
-# attempts to identify the System, import dependencies and overide system_
-if os.name == 'posix':
- if 'GNOME_DESKTOP_SESSION_ID' in os.environ:
- try:
- import dbus
- system_ = GnomeSystem
- except:
- pass
+class WindowsSystem(System):
- if system_ is None:
- system_ = FreedesktopOrgSystem
-elif os.name == 'nt':
- pass
-elif os.name == 'mac':
- pass
+ """Microsoft Windows"""
+ def __init__(self):
+ System.__init__(self)
-def getSystem():
- system = None
- if system_ is not None:
- system = system_()
- if system is None:
- system = System()
+def get_system():
+ """
+ Create a System object.
- return system
+ Returns:
+ System: A System object.
+ """
+ if os.name == 'posix':
+ if sys.platform == 'darwin':
+ return DarwinSystem()
+
+ if 'GNOME_DESKTOP_SESSION_ID' in os.environ:
+ return GnomeSystem()
+ return FreedesktopOrgSystem()
+ if os.name == 'nt':
+ return WindowsSystem()
+ return System()
class CPUUsageTracker(object):
diff --git a/tests/test_system.py b/tests/test_system.py
index 885792e..3d07e8c 100644
--- a/tests/test_system.py
+++ b/tests/test_system.py
@@ -21,7 +21,7 @@
# Boston, MA 02110-1301, USA.
from unittest import TestCase
-from pitivi.utils.system import getSystem
+from pitivi.utils.system import get_system
from pitivi.utils.system import GnomeSystem
from pitivi.utils.system import INHIBIT_LOGOUT
from pitivi.utils.system import INHIBIT_SESSION_IDLE
@@ -92,7 +92,7 @@ class TestSystem(TestCase):
class TestGnomeSystem(TestCase):
def setUp(self):
- self.system = getSystem()
+ self.system = get_system()
def testPowerInhibition(self):
if not isinstance(self.system, GnomeSystem):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]