Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Simplify rho.translation module
Browse files Browse the repository at this point in the history
Instead of rho.translation exporting a function which then returns the
gettext lookup function, just have the module export the right
function.

Also do some minor cleanups in scancommand.py to fix lint errors.
  • Loading branch information
Noah Lavine committed Aug 7, 2017
1 parent d21d09c commit da517aa
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 55 deletions.
4 changes: 1 addition & 3 deletions rho/authaddcommand.py
Expand Up @@ -23,9 +23,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


def auth_exists(cred_list, auth_name):
Expand Down
4 changes: 1 addition & 3 deletions rho/authclearcommand.py
Expand Up @@ -20,9 +20,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class AuthClearCommand(CliCommand):
Expand Down
4 changes: 1 addition & 3 deletions rho/autheditcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


def optional_arg(arg_default):
Expand Down
4 changes: 1 addition & 3 deletions rho/authlistcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class AuthListCommand(CliCommand):
Expand Down
4 changes: 1 addition & 3 deletions rho/authshowcommand.py
Expand Up @@ -20,9 +20,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class AuthShowCommand(CliCommand):
Expand Down
3 changes: 0 additions & 3 deletions rho/cli.py
Expand Up @@ -31,9 +31,6 @@
from rho.profilelistcommand import ProfileListCommand # noqa
from rho.profileshowcommand import ProfileShowCommand # noqa
from rho.scancommand import ScanCommand # noqa
from rho.translation import get_translation

_ = get_translation()


class CLI(object):
Expand Down
4 changes: 1 addition & 3 deletions rho/clicommand.py
Expand Up @@ -15,9 +15,7 @@
from __future__ import print_function
import sys
from optparse import OptionParser # pylint: disable=deprecated-module
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class CliCommand(object):
Expand Down
4 changes: 1 addition & 3 deletions rho/profileaddcommand.py
Expand Up @@ -22,9 +22,7 @@
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.utilities import multi_arg, _check_range_validity, _read_in_file
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


def profile_exists(profile_list, profile_name):
Expand Down
4 changes: 1 addition & 3 deletions rho/profileclearcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class ProfileClearCommand(CliCommand):
Expand Down
4 changes: 1 addition & 3 deletions rho/profileeditcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.utilities import multi_arg, _check_range_validity, _read_in_file
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class ProfileEditCommand(CliCommand):
Expand Down
4 changes: 1 addition & 3 deletions rho/profilelistcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class ProfileListCommand(CliCommand):
Expand Down
4 changes: 1 addition & 3 deletions rho/profileshowcommand.py
Expand Up @@ -21,9 +21,7 @@
from rho import utilities
from rho.clicommand import CliCommand
from rho.vault import get_vault
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


class ProfileShowCommand(CliCommand):
Expand Down
11 changes: 5 additions & 6 deletions rho/scancommand.py
Expand Up @@ -24,9 +24,7 @@
from rho.clicommand import CliCommand
from rho.vault import get_vault_and_password
from rho.utilities import multi_arg, _read_in_file, str_to_ascii
from rho.translation import get_translation

_ = get_translation()
from rho.translation import _


# Read ssh key from file
Expand Down Expand Up @@ -101,11 +99,12 @@ def _create_ping_inventory(vault, vault_pass, profile_ranges, profile_port,
with open('data/ping_log', 'r') as ping_log:
out = ping_log.readlines()

for line, _ in enumerate(out):
if 'pong' in out[line]:
# pylint: disable=unused-variable
for linenum, line in enumerate(out):
if 'pong' in out[linenum]:
tup_auth_item = tuple(auth_item)
success_auths.add(tup_auth_item)
host_line = out[line - 2].replace('\x1b[0;32m', '')
host_line = out[linenum - 2].replace('\x1b[0;32m', '')
host_ip = host_line.split('|')[0].strip()
success_hosts.add(host_ip)
if host_ip not in mapped_hosts:
Expand Down
14 changes: 5 additions & 9 deletions rho/translation.py
Expand Up @@ -15,12 +15,8 @@

T = gettext.translation('rho', 'locale', fallback=True)


def get_translation():
"""Obtains the locale based translation setup for rho"""
if hasattr(T, 'ugettext'):
# pylint: disable=no-member
_ = T.ugettext
else:
_ = T.gettext
return _
if hasattr(T, 'ugettext'):
# pylint: disable=no-member
_ = T.ugettext
else:
_ = T.gettext
5 changes: 1 addition & 4 deletions rho/utilities.py
Expand Up @@ -14,7 +14,7 @@
import os
import sys
import re
from rho.translation import get_translation
from rho.translation import _

CREDENTIALS_PATH = 'data/credentials'
PROFILES_PATH = 'data/profiles'
Expand Down Expand Up @@ -112,9 +112,6 @@ def ensure_config_dir_exists():
os.makedirs('data')


_ = get_translation()


# pylint: disable=unused-argument
def multi_arg(option, opt_str, value, parser):
"""Call back function for arg-parse
Expand Down

0 comments on commit da517aa

Please sign in to comment.