Skip to content

Commit

Permalink
Improved output for non-ascii strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ykalchevskiy committed Jul 8, 2013
1 parent 69c9983 commit 67b2f71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions serverauditor_sshconfig/sa_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def is_exist(host):

def _choose_new_hosts(self):
def get_hosts_names():
return ['%s (#%d)' % (h, i) for i, h in enumerate(self._local_hosts)]
return ', '.join('%s (#%d)' % (h, i) for i, h in enumerate(self._local_hosts)) or '[]'

self._logger.log("The following new hosts have been founded in your ssh config:", sleep=0)
self._logger.log(get_hosts_names())
self._logger.log(get_hosts_names(), color='blue')

prompt = "You may confirm this list (press 'Enter'), add (enter '+') or remove (enter its number) host: "
while True:
Expand All @@ -84,25 +84,25 @@ def get_hosts_names():
break

if number == '+':
host = raw_input("Adding host: ")
host = raw_input("Enter host: ")
conf = self._config.get_host(host)
if conf.keys() == ['host']:
self._logger.log("There is no config for host %s!" % host, file=sys.stderr)
else:
self._local_hosts.append(host)

self._logger.log("Hosts:\n%s" % get_hosts_names())

else:
try:
number = int(number)
if number >= len(self._local_hosts) or number < 0:
raise IndexError
except (ValueError, IndexError):
self._logger.log("Incorrect index!", color='red', file=sys.stderr)
continue
else:
self._local_hosts.pop(number)
self._logger.log("Hosts:\n%s" % get_hosts_names())

self._logger.log(get_hosts_names(), color='blue')

self._logger.log("Ok!", color='green')
return
Expand Down Expand Up @@ -141,7 +141,7 @@ def main():
try:
app.run()
except (KeyboardInterrupt, EOFError):
pass
sys.exit(1)
return


Expand Down
8 changes: 4 additions & 4 deletions serverauditor_sshconfig/sa_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def get_connection_name(conn, number):
return '%s (#%d)' % (name, number)

def get_connections_names():
return [get_connection_name(c, i) for i, c in enumerate(self._sa_connections)]
return ', '.join(get_connection_name(c, i) for i, c in enumerate(self._sa_connections)) or '[]'

if not self._sa_connections:
self._logger.log("There are no new connections on ServerAuditor's servers.")
self._valediction()
sys.exit(0)

self._logger.log("The following new hosts have been founded on ServerAuditor's servers:", sleep=0)
self._logger.log(get_connections_names())
self._logger.log(get_connections_names(), color='blue')

prompt = "You may confirm this list (press 'Enter') or remove host (enter its number): "
while True:
Expand All @@ -104,7 +104,7 @@ def get_connections_names():
self._logger.log("Incorrect index!", color='red', file=sys.stderr)
else:
self._sa_connections.pop(number)
self._logger.log("Hosts:\n%s" % get_connections_names())
self._logger.log(get_connections_names(), color='blue')

self._logger.log("Ok!", color='green')
return
Expand Down Expand Up @@ -171,7 +171,7 @@ def main():
try:
app.run()
except (KeyboardInterrupt, EOFError):
pass
sys.exit(1)
return


Expand Down

0 comments on commit 67b2f71

Please sign in to comment.