~ubuntu-sdk-team/ubuntu-sdk-tools/trunk

« back to all changes in this revision

Viewing changes to usdk-scope-runner/usdk-scope-runner

  • Committer: Benjamin Zeller
  • Date: 2016-06-08 16:25:47 UTC
  • mfrom: (18.1.9 ubuntu-sdk-tools)
  • Revision ID: benjamin.zeller@canonical.com-20160608162547-7vlh1odtnlvbgfmj
Remove usdk-scope-runner since its delivered with the IDE

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
 
#
4
 
# QTC device applauncher
5
 
# Copyright (C) 2014-2016 Canonical
6
 
#
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.
10
 
#
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.
15
 
#
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/>.
18
 
#
19
 
# Author: Benjamin Zeller <benjamin.zeller@canonical.com>
20
 
 
21
 
import json
22
 
import os
23
 
import os.path
24
 
import subprocess
25
 
import argparse
26
 
import shutil
27
 
import sys
28
 
import re
29
 
 
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',
34
 
                    dest='gdbPort',
35
 
                    help="Runs the app in gdbserver listening on specified port")
36
 
 
37
 
options = parser.parse_args()
38
 
 
39
 
if not os.path.isfile(options.scope_ini):
40
 
    print("Scope ini file does not exist")
41
 
    sys.exit(1)
42
 
 
43
 
# remove the .ini
44
 
app_id = os.path.basename(options.scope_ini)[:-4]
45
 
 
46
 
regex = re.compile("_")
47
 
try:
48
 
    (packagename, hookname) = regex.split(app_id)
49
 
except ValueError as err:
50
 
    print("Invalid Application ID "+app_id+" "+repr(err), file=sys.stderr)
51
 
    sys.exit(1)
52
 
 
53
 
# the scope tmpdir, as this is desktop its always unconfined (for now)
54
 
tmpdir = os.path.expanduser('~')+"/.local/share/unity-scopes/unconfined/"+packagename+"/"
55
 
 
56
 
if(not os.path.exists(tmpdir)):
57
 
    os.makedirs(tmpdir)
58
 
 
59
 
print("ScopeRunner> Setting up environment")
60
 
print("ScopeRunner> TmpDir:      "+tmpdir)
61
 
print("ScopeRunner> AppId:       "+app_id)
62
 
 
63
 
command = shutil.which("unity-scope-tool")
64
 
 
65
 
if command is None:
66
 
    print("ScopeRunner> unity-scope-tool was not found in the PATH. Please run \"apt-get install unity-scope-tool\"")
67
 
    sys.exit(1)
68
 
 
69
 
if app_id is None:
70
 
    sys.exit(1)
71
 
 
72
 
# the config file
73
 
debug_file_name = tmpdir+app_id+"_debug.json"
74
 
 
75
 
needs_debug_conf=False
76
 
conf_obj={}
77
 
 
78
 
if options.gdbPort is not None:
79
 
    needs_debug_conf=True
80
 
 
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.")
86
 
        sys.exit(1)
87
 
 
88
 
    conf_obj['gdbPort'] = options.gdbPort
89
 
    print("Sdk-Launcher> GDB Port"+options.gdbPort,flush=True)
90
 
 
91
 
#create the debug description file if required or delete it if not
92
 
if needs_debug_conf:
93
 
    try:
94
 
        f = open(debug_file_name, 'w')
95
 
        json.dump(conf_obj,f)
96
 
        f.close()
97
 
    except OSError:
98
 
        #error we need to stop
99
 
        print("Sdk-Launcher> Could not create the debug description file")
100
 
        sys.exit(1)
101
 
elif os.path.isfile(debug_file_name):
102
 
    os.remove(debug_file_name)
103
 
 
104
 
print ("Debug-helper> Environment initialized, starting the application")
105
 
print ("Debug-helper> Executing "+command+" "+options.scope_ini)
106
 
 
107
 
#flush all descriptors
108
 
sys.stdout.flush()
109
 
sys.stderr.flush()
110
 
 
111
 
#replace us with the new process
112
 
os.execv(command,[command,options.scope_ini])