Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
/ hterm Public archive

Commit

Permalink
libdot/hterm: fix python-3 print func handling
Browse files Browse the repository at this point in the history
Use a print function to work with py2 & py3.

Change-Id: I50ae88d31dd47e846fa4ffac89f392dce2218ec1
Reviewed-on: https://chromium-review.googlesource.com/1018921
Reviewed-by: Vitaliy Shipitsyn <[email protected]>
Tested-by: Mike Frysinger <[email protected]>
  • Loading branch information
vapier committed Apr 27, 2018
1 parent 0b117ab commit 303647d
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions bin/vtscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import print_function

import atexit
import json
import os
Expand Down Expand Up @@ -151,7 +153,7 @@ def run(self):
command_line = raw_input(PROMPT)
except EOFError:
self.running = False
print 'exit'
print('exit')
return

if not command_line:
Expand Down Expand Up @@ -204,7 +206,7 @@ def find_next_chunk(self):
self.end_position = m.end()
else:
self.end_position = self.start_position + MAX_TEXT
print 'Unable to find end of escape sequence.'
print('Unable to find end of escape sequence.')

sequence = self.data[self.start_position + 1 : self.end_position]
return json.dumps(esc_name + ' ' + ' '.join(sequence))[1:-1]
Expand All @@ -227,9 +229,9 @@ def show_next_chunk(self):
snippet = self.find_next_chunk()

if snippet:
print 'Next up: offset %s, %s' % (self.start_position, snippet)
print('Next up: offset %s, %s' % (self.start_position, snippet))
else:
print 'End of data.'
print('End of data.')

def send(self, str):
"""Broadcast a string to all clients, removing any that appear to
Expand All @@ -240,7 +242,7 @@ def send(self, str):
try:
fd.send(str)
except IOError:
print 'Client #%s disconnected.' % i
print('Client #%s disconnected.' % i)
del self.clients[i - 1]

def broadcast_chunk(self):
Expand All @@ -266,7 +268,7 @@ def dispatch_command(self, command_line):

command_function = getattr(self, 'cmd_' + command_name, None)
if not command_function:
print 'Unknown command: "%s"' % command_name
print('Unknown command: "%s"' % command_name)
return

# Change this test to 'if False' to skip over the try/catch, making it
Expand All @@ -275,8 +277,8 @@ def dispatch_command(self, command_line):
try:
command_function(command_args)
except Exception as ex:
print 'Error executing %s: %s: %s' % \
(command_name, type(ex), ex)
print('Error executing %s: %s: %s' %
(command_name, type(ex), ex))
else:
command_function(command_args)

Expand All @@ -299,7 +301,7 @@ def cmd_accept(self, args):
"""

if not len(args):
print 'Missing argument.'
print('Missing argument.')
return

if args[0][0] == '+':
Expand All @@ -308,17 +310,17 @@ def cmd_accept(self, args):
count = int(args[0])
self.clients = []

print 'Listening on %s:%s' % (LISTEN_HOST, LISTEN_PORT)
print('Listening on %s:%s' % (LISTEN_HOST, LISTEN_PORT))
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((LISTEN_HOST, LISTEN_PORT))
sock.listen(1)

while len(self.clients) < count:
print 'Waiting for client %s/%s...' % (len(self.clients) + 1, count)
print('Waiting for client %s/%s...' % (len(self.clients) + 1, count))
(fd, addr) = sock.accept()
self.clients.append(fd)
print 'Remote connected by', addr
print('Remote connected by', addr)

sock.close()

Expand All @@ -342,7 +344,7 @@ def cmd_delay(self, args):
if len(args):
self.delay_ms = int(args[0])

print 'Delay is now: %s' % self.delay_ms
print('Delay is now: %s' % self.delay_ms)

def cmd_exit(self, args):
"""Exit vtscope.
Expand Down Expand Up @@ -393,7 +395,7 @@ def cmd_send(self, args):
else:
str += json.loads('"%s"' % arg)

print 'Sending %s' % json.dumps(str)
print('Sending %s' % json.dumps(str))
self.send(str)

def cmd_stops(self, args):
Expand All @@ -403,14 +405,14 @@ def cmd_stops(self, args):
"""

if not len(self.stops):
print 'No stop offsets found.'
print('No stop offsets found.')
return

for i in xrange(len(self.stops)):
offset = self.stops[i]
print '#%s offset: %s, lines: %s, cursor: %s,%s' % \
(i + 1, offset['offset'], offset['lines'], offset['row'],
offset['column'])
print('#%s offset: %s, lines: %s, cursor: %s,%s' %
(i + 1, offset['offset'], offset['lines'], offset['row'],
offset['column']))

def cmd_open(self, args):
"""Open a local file containing canned data.
Expand All @@ -431,14 +433,14 @@ def cmd_open(self, args):
if re.match(r'(#[^\n]*\n)*@@ HEADER_START', self.data):
m = re.search(r'@@ HEADER_END\r?\n', self.data, re.MULTILINE)
if not m:
print 'Unable to locate end of header.'
print('Unable to locate end of header.')
else:
end = m.end()
print 'Read %s bytes of header.' % end
print('Read %s bytes of header.' % end)
self.scan_header(self.data[0 : end])
self.data = self.data[end : ]

print 'Read %s bytes of playback.' % len(self.data)
print('Read %s bytes of playback.' % len(self.data))
self.cmd_reset([])

def cmd_reset(self, args):
Expand All @@ -465,17 +467,17 @@ def cmd_seek(self, args):
"""

if len(args) < 1:
print 'Missing argument'
print('Missing argument')
return

if not self.data:
print 'No data.'
print('No data.')
return

if args[0][0] == '#':
index = int(args[0][1:])
if index < 1 or index > len(self.stops):
print 'No such stop.'
print('No such stop.')
return

pos = self.stops[index - 1]['offset']
Expand All @@ -484,7 +486,7 @@ def cmd_seek(self, args):
pos = int(args[0])

if pos > len(self.data):
print 'Seek past end.'
print('Seek past end.')
return

if pos <= self.start_position:
Expand All @@ -501,7 +503,7 @@ def cmd_step(self, args):
"""

if self.start_position >= len(self.data):
print 'Already at end of data.'
print('Already at end of data.')
return

if len(args) > 0:
Expand Down

0 comments on commit 303647d

Please sign in to comment.