summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-03-27 13:27:07 +0200
committerKali Kaneko <kali@leap.se>2018-03-28 23:51:25 +0200
commitdcbbda4dbd442340cbc46e2f1a476cb21e12ca0f (patch)
tree549bb1e573ad231043045e5cdd820d1327233420 /src/leap
parent8a89b36026b0866625bbff805c16b489f3670b2b (diff)
[refactor] move platform constants into leap.bitmask
The IS_${platform} constants are used in more places than the vpn module. Let's define them in leap.bitmask.
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/bitmask/core/uuid_map.py5
-rw-r--r--src/leap/bitmask/gui/app.py2
-rw-r--r--src/leap/bitmask/system.py30
-rw-r--r--src/leap/bitmask/vpn/_checks.py3
-rw-r--r--src/leap/bitmask/vpn/_config.py2
-rw-r--r--src/leap/bitmask/vpn/autostart.py2
-rw-r--r--src/leap/bitmask/vpn/constants.py13
-rw-r--r--src/leap/bitmask/vpn/fw/firewall.py2
-rw-r--r--src/leap/bitmask/vpn/helpers/__init__.py4
-rw-r--r--src/leap/bitmask/vpn/launcher.py4
-rw-r--r--src/leap/bitmask/vpn/launchers/linux.py3
-rw-r--r--src/leap/bitmask/vpn/privilege.py4
-rw-r--r--src/leap/bitmask/vpn/process.py2
-rw-r--r--src/leap/bitmask/vpn/service.py2
-rw-r--r--src/leap/bitmask/vpn/tunnel.py2
-rw-r--r--src/leap/bitmask/vpn/utils.py2
16 files changed, 46 insertions, 36 deletions
diff --git a/src/leap/bitmask/core/uuid_map.py b/src/leap/bitmask/core/uuid_map.py
index e7d02a31..d5ddbda0 100644
--- a/src/leap/bitmask/core/uuid_map.py
+++ b/src/leap/bitmask/core/uuid_map.py
@@ -21,13 +21,10 @@ UUID Map: a persistent mapping between user-ids and uuids.
import base64
import os
import re
-import platform
-
import scrypt
from leap.common.config import get_path_prefix
-
-IS_WIN = platform.system() == "Windows"
+from leap.bitmask.system import IS_WIN
if IS_WIN:
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index f22292b7..20942294 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -30,6 +30,7 @@ import webbrowser
from functools import partial
from multiprocessing import Process
+from leap.bitmask.system import IS_WIN
from leap.bitmask.core.launcher import run_bitmaskd, pid
from leap.bitmask.gui import app_rc
from leap.bitmask.gui.systray import WithTrayIcon
@@ -69,7 +70,6 @@ else:
from PyQt5.QtWebKit import QWebSettings
-IS_WIN = platform.system() == "Windows"
DEBUG = os.environ.get("DEBUG", False)
BITMASK_URI = 'http://localhost:7070/'
diff --git a/src/leap/bitmask/system.py b/src/leap/bitmask/system.py
new file mode 100644
index 00000000..f4a520ce
--- /dev/null
+++ b/src/leap/bitmask/system.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# platform.py
+# Copyright (C) 2018 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""
+System constants
+"""
+import os
+import platform
+
+_system = platform.system()
+
+IS_LINUX = _system == "Linux"
+IS_MAC = _system == "Darwin"
+IS_UNIX = IS_MAC or IS_LINUX
+IS_WIN = _system == "Windows"
+IS_SNAP = os.environ.get('SNAP')
diff --git a/src/leap/bitmask/vpn/_checks.py b/src/leap/bitmask/vpn/_checks.py
index 2549e366..b4fadb78 100644
--- a/src/leap/bitmask/vpn/_checks.py
+++ b/src/leap/bitmask/vpn/_checks.py
@@ -4,12 +4,11 @@ from datetime import datetime
from time import mktime
from twisted.logger import Logger
+from leap.bitmask.system import IS_LINUX
from leap.bitmask.vpn.privilege import is_pkexec_in_system, NoPkexecAvailable
from leap.common.certs import get_cert_time_boundaries
from leap.common.config import get_path_prefix
-from .constants import IS_LINUX
-
log = Logger()
diff --git a/src/leap/bitmask/vpn/_config.py b/src/leap/bitmask/vpn/_config.py
index 5bb61e78..63b57a78 100644
--- a/src/leap/bitmask/vpn/_config.py
+++ b/src/leap/bitmask/vpn/_config.py
@@ -1,7 +1,7 @@
import os.path
import pkg_resources
-from .constants import IS_LINUX
+from leap.bitmask.system import IS_LINUX
from leap.bitmask.util import STANDALONE, here
if IS_LINUX:
diff --git a/src/leap/bitmask/vpn/autostart.py b/src/leap/bitmask/vpn/autostart.py
index 0572e9d5..1c361d82 100644
--- a/src/leap/bitmask/vpn/autostart.py
+++ b/src/leap/bitmask/vpn/autostart.py
@@ -1,7 +1,7 @@
import os
import os.path
-from leap.bitmask.vpn.constants import IS_LINUX, IS_MAC
+from leap.bitmask.system import IS_LINUX, IS_MAC
from leap.bitmask.util import STANDALONE
from leap.common.config import get_path_prefix
diff --git a/src/leap/bitmask/vpn/constants.py b/src/leap/bitmask/vpn/constants.py
index 868ac193..dce5e81c 100644
--- a/src/leap/bitmask/vpn/constants.py
+++ b/src/leap/bitmask/vpn/constants.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# constants.py
-# Copyright (C) 2015-2017 LEAP
+# Copyright (C) 2015-2018 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,16 +18,7 @@
"""
System constants
"""
-import os
-import platform
-
-_system = platform.system()
-
-IS_LINUX = _system == "Linux"
-IS_MAC = _system == "Darwin"
-IS_UNIX = IS_MAC or IS_LINUX
-IS_WIN = _system == "Windows"
-IS_SNAP = os.environ.get('SNAP')
+from leap.bitmask.system import IS_LINUX
if IS_LINUX:
BITMASK_ROOT_SYSTEM = '/usr/sbin/bitmask-root'
diff --git a/src/leap/bitmask/vpn/fw/firewall.py b/src/leap/bitmask/vpn/fw/firewall.py
index d5b1f018..98b317b0 100644
--- a/src/leap/bitmask/vpn/fw/firewall.py
+++ b/src/leap/bitmask/vpn/fw/firewall.py
@@ -25,7 +25,7 @@ import subprocess
from twisted.logger import Logger
-from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX
+from leap.bitmask.system import IS_MAC, IS_LINUX
from leap.common.events import catalog, emit_async
from leap.bitmask.vpn.launchers import darwin
diff --git a/src/leap/bitmask/vpn/helpers/__init__.py b/src/leap/bitmask/vpn/helpers/__init__.py
index 54b29cb0..e932422d 100644
--- a/src/leap/bitmask/vpn/helpers/__init__.py
+++ b/src/leap/bitmask/vpn/helpers/__init__.py
@@ -7,15 +7,13 @@ from hashlib import sha512
from twisted.logger import Logger
-from leap.bitmask.vpn.constants import IS_LINUX, IS_MAC
from leap.bitmask.vpn import _config
+from leap.bitmask.system import IS_LINUX, IS_MAC, IS_SNAP
from leap.bitmask.util import STANDALONE
log = Logger()
-IS_SNAP = os.environ.get('SNAP')
-
if IS_LINUX:
from leap.bitmask.vpn.constants import BITMASK_ROOT_SYSTEM
diff --git a/src/leap/bitmask/vpn/launcher.py b/src/leap/bitmask/vpn/launcher.py
index 890e1862..93be5fe7 100644
--- a/src/leap/bitmask/vpn/launcher.py
+++ b/src/leap/bitmask/vpn/launcher.py
@@ -27,14 +27,12 @@ from twisted.logger import Logger
from abc import ABCMeta, abstractmethod
-from leap.bitmask.vpn.constants import IS_MAC
+from leap.bitmask.system import IS_MAC, IS_SNAP
from leap.bitmask.vpn.utils import force_eval
log = Logger()
-IS_SNAP = os.environ.get('SNAP')
-
class VPNLauncherException(Exception):
pass
diff --git a/src/leap/bitmask/vpn/launchers/linux.py b/src/leap/bitmask/vpn/launchers/linux.py
index 5e05bea4..748fe858 100644
--- a/src/leap/bitmask/vpn/launchers/linux.py
+++ b/src/leap/bitmask/vpn/launchers/linux.py
@@ -28,6 +28,7 @@ from twisted.internet import defer, reactor
from twisted.internet.endpoints import clientFromString, connectProtocol
from twisted.logger import Logger
+from leap.bitmask.system import IS_SNAP
from leap.bitmask.vpn.utils import first, force_eval
from leap.bitmask.vpn import constants
from leap.bitmask.vpn import _config
@@ -35,8 +36,6 @@ from leap.bitmask.vpn.privilege import LinuxPolicyChecker
from leap.bitmask.vpn.management import ManagementProtocol
from leap.bitmask.vpn.launcher import VPNLauncher
-IS_SNAP = os.environ.get('SNAP')
-
TERMINATE_MAXTRIES = 10
TERMINATE_WAIT = 1 # secs
RESTART_WAIT = 2 # secs
diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py
index 8a922cfe..528e3551 100644
--- a/src/leap/bitmask/vpn/privilege.py
+++ b/src/leap/bitmask/vpn/privilege.py
@@ -29,11 +29,9 @@ from twisted.logger import Logger
from twisted.python.procutils import which
from leap.bitmask.util import STANDALONE, here
-from .constants import IS_LINUX
+from leap.bitmask.system import IS_LINUX, IS_SNAP
from . import polkit
-IS_SNAP = os.environ.get('SNAP')
-
log = Logger()
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index 35ccf9f6..17d8fddc 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -37,7 +37,7 @@ from zope.interface import implementer
from leap.bitmask.vpn.utils import get_vpn_launcher
from leap.bitmask.vpn.management import ManagementProtocol
from leap.bitmask.vpn.launchers import darwin
-from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX
+from leap.bitmask.system import IS_MAC, IS_LINUX
from leap.common.events import catalog, emit_async
from zope.interface import Interface
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index 78443323..95751ca0 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -38,9 +38,9 @@ from leap.bitmask.vpn._checks import (
cert_expires
)
+from leap.bitmask.system import IS_LINUX
from leap.bitmask.vpn import privilege, helpers
from leap.bitmask.vpn import autostart
-from leap.bitmask.vpn.constants import IS_LINUX
from leap.common.config import get_path_prefix
from leap.common.files import check_and_fix_urw_only
from leap.common.events import catalog, emit_async
diff --git a/src/leap/bitmask/vpn/tunnel.py b/src/leap/bitmask/vpn/tunnel.py
index f2bd20a1..9904b365 100644
--- a/src/leap/bitmask/vpn/tunnel.py
+++ b/src/leap/bitmask/vpn/tunnel.py
@@ -25,8 +25,8 @@ import tempfile
from twisted.internet import reactor, defer
from twisted.logger import Logger
+from leap.bitmask.system import IS_WIN
from ._config import _TempVPNConfig, _TempProviderConfig
-from .constants import IS_WIN
from .process import VPNProcess
diff --git a/src/leap/bitmask/vpn/utils.py b/src/leap/bitmask/vpn/utils.py
index 8fa51783..98332fe2 100644
--- a/src/leap/bitmask/vpn/utils.py
+++ b/src/leap/bitmask/vpn/utils.py
@@ -57,7 +57,7 @@ def get_vpn_launcher():
"""
Return the VPN launcher for the current platform.
"""
- from leap.bitmask.vpn.constants import IS_LINUX, IS_MAC, IS_WIN
+ from leap.bitmask.system import IS_LINUX, IS_MAC, IS_WIN
if not (IS_LINUX or IS_MAC or IS_WIN):
error_msg = "VPN Launcher not implemented for this platform."