fix gui/portable for pull request #903

This commit is contained in:
Andy Kittner 2013-10-12 21:30:34 +02:00 committed by Norman Jäckel
parent c63b7f995f
commit 21a1d77e29
2 changed files with 38 additions and 23 deletions

View File

@ -15,7 +15,17 @@ import threading
import wx import wx
import openslides import openslides
import openslides.main from openslides.utils.main import (
filesystem2unicode,
is_portable,
detect_openslides_type,
get_win32_portable_path,
)
from openslides.__main__ import (
get_port,
get_default_settings_path
)
# NOTE: djangos translation module can't be used here since it requires # NOTE: djangos translation module can't be used here since it requires
# a defined settings module # a defined settings module
@ -25,7 +35,7 @@ ungettext = lambda msg1, msg2, n: _translations.ungettext(msg1, msg2, n)
def get_data_path(*args): def get_data_path(*args):
path = openslides.main.fs2unicode(__file__) path = filesystem2unicode(__file__)
return os.path.join(os.path.dirname(path), "data", *args) return os.path.join(os.path.dirname(path), "data", *args)
@ -81,7 +91,7 @@ class RunCommandControl(wx.Panel):
if self.is_alive(): if self.is_alive():
raise ValueError("already running a command") raise ValueError("already running a command")
cmd = [sys.executable, "-u", "-m", "openslides.main"] cmd = [sys.executable, "-u", "-m", "openslides"]
cmd.extend(args) cmd.extend(args)
# XXX: subprocess on windows only handles byte strings # XXX: subprocess on windows only handles byte strings
@ -336,12 +346,12 @@ class MainWindow(wx.Frame):
self.SetIcons(icons) self.SetIcons(icons)
self.server_running = False self.server_running = False
if openslides.main.is_portable(): openslides_type = detect_openslides_type()
self.gui_settings_path = openslides.main.get_portable_path( # XXX: this works, but I'd prefer keeping get_user_config_path
"openslides", "gui_settings.json") # it was much clearer what path was intended IMHO ...
else: self.gui_settings_path = os.path.join(
self.gui_settings_path = openslides.main.get_user_config_path( os.path.dirname(get_default_settings_path(openslides_type)),
"openslides", "gui_settings.json") "gui_settings.json")
self.backupdb_enabled = False self.backupdb_enabled = False
self.backupdb_destination = "" self.backupdb_destination = ""
@ -417,9 +427,8 @@ class MainWindow(wx.Frame):
self.bt_server.Bind(wx.EVT_BUTTON, self.on_start_server_clicked) self.bt_server.Bind(wx.EVT_BUTTON, self.on_start_server_clicked)
server_box.Add(self.bt_server, flag=wx.EXPAND) server_box.Add(self.bt_server, flag=wx.EXPAND)
host, port = openslides.main.detect_listen_opts() self.host = "0.0.0.0"
self.host = host self.port = unicode(get_port(self.host, 80))
self.port = unicode(port)
# "action" buttons # "action" buttons
action_vbox = wx.BoxSizer(wx.VERTICAL) action_vbox = wx.BoxSizer(wx.VERTICAL)
@ -568,9 +577,8 @@ class MainWindow(wx.Frame):
def do_backup(self): def do_backup(self):
cmd = [ cmd = [
sys.executable, "-u", "-m", "openslides.main", sys.executable, "-u", "-m", "openslides", "backupdb",
"--no-run", self.backupdb_destination,
"--backupdb={0}".format(self.backupdb_destination),
] ]
p = subprocess.Popen( p = subprocess.Popen(
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
@ -593,11 +601,11 @@ class MainWindow(wx.Frame):
def on_syncdb_clicked(self, evt): def on_syncdb_clicked(self, evt):
self.cmd_run_ctrl.append_message(_("Syncing database...")) self.cmd_run_ctrl.append_message(_("Syncing database..."))
self.cmd_run_ctrl.run_command("--no-run", "--syncdb") self.cmd_run_ctrl.run_command("syncdb")
def on_reset_admin_clicked(self, evt): def on_reset_admin_clicked(self, evt):
self.cmd_run_ctrl.append_message(_("Resetting admin user...")) self.cmd_run_ctrl.append_message(_("Resetting admin user..."))
self.cmd_run_ctrl.run_command("--no-run", "--reset-admin") self.cmd_run_ctrl.run_command("createsuperuser")
def on_about_clicked(self, evt): def on_about_clicked(self, evt):
info = wx.AboutDialogInfo() info = wx.AboutDialogInfo()
@ -624,11 +632,13 @@ class MainWindow(wx.Frame):
args = ["--port", self._port] args = ["--port", self._port]
else: else:
args = ["--address", self._host, "--port", self._port] args = ["--address", self._host, "--port", self._port]
if not self.cb_start_browser.GetValue():
args.append("--no-browser") # XXX: --no-browser is missing
#if not self.cb_start_browser.GetValue():
# args.append("--no-browser")
self.server_running = True self.server_running = True
self.cmd_run_ctrl.run_command(*args) self.cmd_run_ctrl.run_command("start", *args)
# initiate backup_timer if backup is enabled # initiate backup_timer if backup is enabled
self.apply_backup_settings() self.apply_backup_settings()
@ -702,7 +712,7 @@ def main():
lang = locale.getdefaultlocale()[0] lang = locale.getdefaultlocale()[0]
if lang: if lang:
global _translations global _translations
localedir = openslides.main.fs2unicode(openslides.__file__) localedir = filesystem2unicode(openslides.__file__)
localedir = os.path.dirname(localedir) localedir = os.path.dirname(localedir)
localedir = os.path.join(localedir, "locale") localedir = os.path.join(localedir, "locale")
_translations = gettext.translation( _translations = gettext.translation(

View File

@ -13,12 +13,15 @@
import os import os
import sys import sys
import ctypes import ctypes
import tempfile
UNIX_VERSION = 'Unix Version' UNIX_VERSION = 'Unix Version'
WINDOWS_VERSION = 'Windows Version' WINDOWS_VERSION = 'Windows Version'
WINDOWS_PORTABLE_VERSION = 'Windows Portable Version' WINDOWS_PORTABLE_VERSION = 'Windows Portable Version'
class PortableDirNotWritable(Exception):
pass
def filesystem2unicode(path): def filesystem2unicode(path):
""" """
@ -92,8 +95,10 @@ def get_win32_portable_path():
try: try:
fd, test_file = tempfile.mkstemp(dir=portable_path) fd, test_file = tempfile.mkstemp(dir=portable_path)
except OSError: except OSError:
raise Exception('Portable directory is not writeable. Please choose another directory for settings and local files.') raise PortableDirNotWritable(
finally: 'Portable directory is not writeable. '
'Please choose another directory for settings and local files.')
else:
os.close(fd) os.close(fd)
os.unlink(test_file) os.unlink(test_file)
return portable_path return portable_path