summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2012-08-23 23:18:17 +0300
committerAlon Levy <alevy@redhat.com>2012-08-23 23:18:17 +0300
commit21e3219d8d6707a135820465e2ec434398bad061 (patch)
tree016176ca377f089a2d9c87539107d8d132378092
parent8bb9cbe6d81cd086607d9f2217ae3b5dbb717b77 (diff)
xspice: some cleanup (I hope)
-rwxr-xr-xxspice35
1 files changed, 14 insertions, 21 deletions
diff --git a/xspice b/xspice
index 179e360..8e73995 100755
--- a/xspice
+++ b/xspice
@@ -12,6 +12,7 @@ import os
import subprocess
import time
import atexit
+import argparse
processes = []
def launch(*args, **kw):
@@ -36,7 +37,8 @@ def cleanup(*args):
atexit.register(cleanup)
VALGRIND=None
-#VALGRIND=valgrind --trace-children=yes --tool=callgrind
+#VALGRIND="valgrind --leak-check=full --track-origins=yes --log-file=/tmp/xspice.valgrind.log".split()
+#--trace-children=yes --tool=callgrind
def which(x):
return subprocess.check_output(['which', x]).strip()
@@ -44,17 +46,17 @@ def which(x):
###################################
os.system("xspice-local-xkbcomp")
-def launch_xspice(dnum, port):
+def launch_xspice(dnum, port, args):
display = ":%(dnum)s.0" % locals()
which_python = which('python')
which_Xspice = which('Xspice')
cmd = [x % locals() for x in ["%(which_python)s",
"%(which_Xspice)s", display, "--port", "%(port)s", "--disable-ticketing",
- ]] + sys.argv[1:]
+ ]] + args
TLS_PORT_PARAMS = ["--tls-port", "0"]
if VALGRIND:
- cmd = [VALGRIND] + cmd
+ cmd = VALGRIND + cmd
print ' '.join(cmd)
logfile = open(os.path.expanduser('~/.Xspice.%(dnum)s.log' % locals()), 'w+')
@@ -106,22 +108,17 @@ def wait_for_xspice_load(xspice):
raise Exception("Xspice died")
def test_xspice():
- spiceqxl, Xspice = launch_xspice(':10.0')
+ spiceqxl, Xspice = launch_xspice(':10.0', args = [])
def main(wait=True):
- PORT=15000
- DNUM=10
- if len(sys.argv) > 1:
- DNUM=sys.argv[1]
- del sys.argv[1]
-
- if len(sys.argv) > 1:
- PORT=sys.argv[1]
- del sys.argv[1]
-
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--num', type=int, default=10)
+ args, rest = parser.parse_known_args(sys.argv[1:])
+ DNUM = args.num
+ PORT = 15000 + DNUM
print "%s %s" % (DNUM, PORT)
- Xspice = launch_xspice(dnum=DNUM, port=PORT)
+ Xspice = launch_xspice(dnum=DNUM, port=PORT, args=rest)
spiceqxl = Xspice.spiceqxl
display = Xspice.display
seconds_ago = time.time() - os.stat(spiceqxl).st_ctime
@@ -146,8 +143,4 @@ def main(wait=True):
# and quit
if __name__ == '__main__':
- if sys.argv.__len__() == 2 and sys.argv[1] == 'test':
- del sys.argv[1]
- main(False)
- else:
- main()
+ main()