Skip to content
Snippets Groups Projects
Commit eebcf962 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

merge scripts and check if app is frozen

parent 3cc90557
No related branches found
No related tags found
No related merge requests found
......@@ -18,17 +18,28 @@ from agkyra.protocol import SessionHelper, launch_server
from agkyra.config import AGKYRA_DIR
from agkyra.syncer import utils
import subprocess
import sys
import os
import stat
import json
import logging
CURPATH = os.path.dirname(os.path.abspath(__file__))
if getattr(sys, 'frozen', False):
# we are running in a |PyInstaller| bundle
BASEDIR = sys._MEIPASS
ISFROZEN = True
else:
# we are running in a normal Python environment
BASEDIR = os.path.dirname(os.path.realpath(__file__))
ISFROZEN = False
RESOURCES = os.path.join(BASEDIR, 'resources')
LOG = logging.getLogger(__name__)
OSX_DEFAULT_NW_PATH = os.path.join(
CURPATH, 'nwjs', 'nwjs.app', 'Contents', 'MacOS', 'nwjs')
STANDARD_DEFAULT_NW_PATH = os.path.join(CURPATH, 'nwjs', 'nw')
RESOURCES, 'nwjs', 'nwjs.app', 'Contents', 'MacOS', 'nwjs')
STANDARD_DEFAULT_NW_PATH = os.path.join(RESOURCES, 'nwjs', 'nw')
DEFAULT_NW_PATH = OSX_DEFAULT_NW_PATH if utils.isosx() \
else STANDARD_DEFAULT_NW_PATH
......@@ -45,7 +56,7 @@ class GUI(WebSocketBaseClient):
'session_file', os.path.join(AGKYRA_DIR, 'session.info'))
self.start = self.connect
self.nw = kwargs.get('nw', DEFAULT_NW_PATH)
self.gui_code = kwargs.get('gui_code', os.path.join(CURPATH, 'nwgui'))
self.gui_code = kwargs.get('gui_code', os.path.join(RESOURCES, 'nwgui'))
assert not self._gui_running(session), (
'Failed to initialize GUI, because another GUI is running')
self._dump_session_file(session)
......@@ -85,9 +96,9 @@ class GUI(WebSocketBaseClient):
LOG.debug('GUI finished, close GUI wrapper connection')
def run():
def run(callback):
"""Prepare SessionHelper and GUI and run them in the proper order"""
launch_server()
launch_server(callback)
LOG.info('Client blocks until session is ready')
session = SessionHelper().wait_session_to_load()
assert session, 'UI server failed to load...'
......
......@@ -22,6 +22,7 @@ from threading import Thread
import sqlite3
import time
import os
import sys
import json
import logging
import subprocess
......@@ -29,13 +30,21 @@ from agkyra.syncer import (
syncer, setup, pithos_client, localfs_client, messaging, utils)
from agkyra.config import AgkyraConfig, AGKYRA_DIR
if getattr(sys, 'frozen', False):
# we are running in a |PyInstaller| bundle
BASEDIR = sys._MEIPASS
ISFROZEN = True
else:
# we are running in a normal Python environment
BASEDIR = os.path.dirname(os.path.realpath(__file__))
ISFROZEN = False
CURPATH = os.path.dirname(os.path.abspath(__file__))
RESOURCES = os.path.join(BASEDIR, 'resources')
LOG = logging.getLogger(__name__)
SYNCERS = utils.ThreadSafeDict()
with open(os.path.join(CURPATH, 'ui_data/common_en.json')) as f:
with open(os.path.join(RESOURCES, 'ui_data/common_en.json')) as f:
COMMON = json.load(f)
STATUS = COMMON['STATUS']
......@@ -702,14 +711,13 @@ class WebSocketProtocol(WebSocket):
self.terminate()
def launch_server():
def launch_server(callback):
"""Launch the server in a separate process"""
LOG.info('Start SessionHelper session')
server_path = os.path.join(CURPATH, 'scripts', 'server.py')
if utils.iswin():
subprocess.Popen(["pythonw.exe", server_path],
subprocess.Popen([callback, "server"],
close_fds=True)
else:
pid = os.fork()
if not pid:
os.execlp("python", "python", server_path)
os.execlp(callback, callback, "server")
#!/usr/bin/env python
# Copyright (C) 2015 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
......@@ -16,13 +17,12 @@
import os
import sys
SCRIPTSPATH = os.path.dirname(os.path.realpath(__file__))
AGKYRAPATH = os.path.dirname(SCRIPTSPATH)
LIBPATH = os.path.dirname(AGKYRAPATH)
try:
from agkyra import config
except ImportError:
sys.path.insert(0, "lib")
from agkyra import config
sys.path.insert(0, LIBPATH)
from agkyra import config
AGKYRA_DIR = config.AGKYRA_DIR
import logging
......@@ -35,8 +35,9 @@ HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.INFO)
CALLBACK = os.path.realpath(sys.argv[0])
def main():
def run_server():
from agkyra.protocol import SessionHelper
LOGGER.debug('Start the session helper')
helper = SessionHelper()
......@@ -45,9 +46,25 @@ def main():
helper.start()
else:
LOGGER.info('Another session is running, aborting')
exit(1)
return
LOGGER.debug('Session Helper is now down')
def run_gui():
from agkyra import gui
gui.run(callback=CALLBACK)
DISPATCH = {
'server': run_server,
'gui': run_gui,
}
def main():
if len(sys.argv) > 1:
arg = sys.argv[1]
else:
arg = 'gui'
DISPATCH[arg]()
if __name__ == "__main__":
main()
#!/usr/bin/env python
# Copyright (C) 2015 GRNET S.A.
#
# 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/>.
import os
import sys
PATH = os.path.dirname(os.path.realpath(__file__))
LIBPATH = os.path.join(PATH, "lib")
sys.path.insert(0, LIBPATH)
from agkyra import config
AGKYRA_DIR = config.AGKYRA_DIR
import logging
LOGFILE = os.path.join(AGKYRA_DIR, 'agkyra.log')
LOGGER = logging.getLogger('agkyra')
HANDLER = logging.FileHandler(LOGFILE)
FORMATTER = logging.Formatter(
"%(name)s:%(lineno)s %(levelname)s:%(asctime)s:%(message)s")
HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(HANDLER)
LOGGER.setLevel(logging.INFO)
def main():
from agkyra import gui
gui.run()
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment