2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# QTC device applauncher
5
# Copyright (C) 2014-2016 Canonical
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 3 as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
# Author: Benjamin Zeller <benjamin.zeller@canonical.com>
30
# register options to the argument parser
31
parser = argparse.ArgumentParser(description="SDK Scope launcher")
32
parser.add_argument('scope_ini', action="store")
33
parser.add_argument('--cppdebug', action='store',
35
help="Runs the app in gdbserver listening on specified port")
37
options = parser.parse_args()
39
if not os.path.isfile(options.scope_ini):
40
print("Scope ini file does not exist")
44
app_id = os.path.basename(options.scope_ini)[:-4]
46
regex = re.compile("_")
48
(packagename, hookname) = regex.split(app_id)
49
except ValueError as err:
50
print("Invalid Application ID "+app_id+" "+repr(err), file=sys.stderr)
53
# the scope tmpdir, as this is desktop its always unconfined (for now)
54
tmpdir = os.path.expanduser('~')+"/.local/share/unity-scopes/unconfined/"+packagename+"/"
56
if(not os.path.exists(tmpdir)):
59
print("ScopeRunner> Setting up environment")
60
print("ScopeRunner> TmpDir: "+tmpdir)
61
print("ScopeRunner> AppId: "+app_id)
63
command = shutil.which("unity-scope-tool")
66
print("ScopeRunner> unity-scope-tool was not found in the PATH. Please run \"apt-get install unity-scope-tool\"")
73
debug_file_name = tmpdir+app_id+"_debug.json"
75
needs_debug_conf=False
78
if options.gdbPort is not None:
81
print("Sdk-Launcher> Checking if gdbserver is installed...")
82
gdbserver_path = shutil.which("gdbserver")
83
if gdbserver_path is None:
84
print("Sdk-Launcher> gdbserver was not found in the PATH.")
85
print("Sdk-Launcher> Please install the gdbserver package on the phone.")
88
conf_obj['gdbPort'] = options.gdbPort
89
print("Sdk-Launcher> GDB Port"+options.gdbPort,flush=True)
91
#create the debug description file if required or delete it if not
94
f = open(debug_file_name, 'w')
98
#error we need to stop
99
print("Sdk-Launcher> Could not create the debug description file")
101
elif os.path.isfile(debug_file_name):
102
os.remove(debug_file_name)
104
print ("Debug-helper> Environment initialized, starting the application")
105
print ("Debug-helper> Executing "+command+" "+options.scope_ini)
107
#flush all descriptors
111
#replace us with the new process
112
os.execv(command,[command,options.scope_ini])