Skip to content

Commit

Permalink
Merge pull request #154 from transifex/lint_errors
Browse files Browse the repository at this point in the history
Lint errors
  • Loading branch information
Konstantinos Bairaktaris authored Jan 25, 2017
2 parents b16abbf + 520a9b4 commit 9d015b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 29 deletions.
Binary file added txclib/.project.py.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions txclib/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def main(argv=None):
try:
utils.exec_command(cmd, args[1:], path_to_tx)
except SSLError as e:
logger.error("SSl error %s" % e)
sys.exit(1)
except utils.UnknownCommandError:
logger.error("tx: Command %s not found" % cmd)
Expand All @@ -118,6 +119,7 @@ def main(argv=None):
logger.error(formatted_lines[-1])
sys.exit(1)


# Run baby :) ... run
if __name__ == "__main__":
# sys.argv[0] is the name of the script that we’re running.
Expand Down
22 changes: 6 additions & 16 deletions txclib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import re
import shutil
import sys
from optparse import OptionParser, OptionGroup

try:
import configparser
Expand All @@ -28,7 +27,6 @@
from six.moves import input

from txclib import utils, project
from txclib.utils import parse_json, compile_json, files_in_project
from txclib.config import OrderedRawConfigParser
from txclib.exceptions import UnInitializedError
from txclib.parsers import delete_parser, help_parser, parse_csv_option, \
Expand All @@ -50,13 +48,10 @@ def cmd_init(argv, path_to_tx):

if os.path.isdir(os.path.join(path_to_tx, ".tx")):
logger.info("tx: There is already a tx folder!")
reinit = input("Do you want to delete it and "
"reinit the project? [y/N]: ")
while (reinit != 'y' and reinit != 'Y' and reinit != 'N'
and reinit != 'n' and reinit != ''):
reinit = input("Do you want to delete it and "
"reinit the project? [y/N]: ")
if not reinit or reinit in ['N', 'n', 'NO', 'no', 'No']:
if not utils.confirm(
prompt='Do you want to delete it and reinit the project?',
default=False
):
return
# Clean the old settings
# FIXME: take a backup
Expand All @@ -67,11 +62,6 @@ def cmd_init(argv, path_to_tx):
logger.info("Creating .tx folder...")
os.mkdir(os.path.join(path_to_tx, ".tx"))

# Handle the credentials through transifexrc
home = os.path.expanduser("~")
txrc = os.path.join(home, ".transifexrc")
config = OrderedRawConfigParser()

default_transifex = "https://www.transifex.com"
transifex_host = options.host or input("Transifex instance [%s]: " %
default_transifex)
Expand All @@ -85,6 +75,7 @@ def cmd_init(argv, path_to_tx):
if not os.path.exists(config_file):
# The path to the config file (.tx/config)
logger.info("Creating skeleton...")
# Handle the credentials through transifexrc
config = OrderedRawConfigParser()
config.add_section('main')
config.set('main', 'host', transifex_host)
Expand Down Expand Up @@ -213,7 +204,7 @@ def _auto_local(path_to_tx, resource, source_language, expression,
# First, let's construct a dictionary of all matching files.
# Note: Only the last matching file of a language will be stored.
translation_files = {}
for f_path in files_in_project(curpath):
for f_path in utils.files_in_project(curpath):
match = expr_rec.match(posix_path(f_path))
if match:
lang = match.group(1)
Expand All @@ -240,7 +231,6 @@ def _auto_local(path_to_tx, resource, source_language, expression,
'file': os.path.relpath(source_file, curpath)})

prj = project.Project(path_to_tx)
root_dir = os.path.abspath(path_to_tx)

if execute:
try:
Expand Down
2 changes: 0 additions & 2 deletions txclib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
from txclib.paths import posix_path, native_path, posix_sep




class ProjectNotInit(Exception):
pass

Expand Down
18 changes: 7 additions & 11 deletions txclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
import urllib3
import collections
import six
import ssl

try:
from json import loads as parse_json, dumps as compile_json
from json import loads as parse_json
except ImportError:
from simplejson import loads as parse_json, dumps as compile_json
from simplejson import loads as parse_json

from email.parser import Parser
from urllib3.exceptions import SSLError
from six.moves import input
from txclib.urls import API_URLS
from txclib.exceptions import UnknownCommandError, HttpNotFound, HttpNotAuthorized
from txclib.exceptions import (
UnknownCommandError, HttpNotFound, HttpNotAuthorized
)
from txclib.paths import posix_path, native_path, posix_sep
from txclib.web import user_agent_identifier, certs_file
from txclib.log import logger
Expand Down Expand Up @@ -186,7 +187,6 @@ def make_request(method, host, url, username, password, fields=None,
def get_details(api_call, username, password, *args, **kwargs):
"""
Get the tx project info through the API.
This function can also be used to check the existence of a project.
"""
url = API_URLS[api_call] % kwargs
Expand All @@ -203,7 +203,6 @@ def get_details(api_call, username, password, *args, **kwargs):
def valid_slug(slug):
"""
Check if a slug contains only valid characters.
Valid chars include [-_\w]
"""
try:
Expand Down Expand Up @@ -261,18 +260,17 @@ def mkdir_p(path):
def confirm(prompt='Continue?', default=True):
"""
Prompt the user for a Yes/No answer.
Args:
prompt: The text displayed to the user ([Y/n] will be appended)
default: If the default value will be yes or no
"""
valid_yes = ['Y', 'y', 'Yes', 'yes', ]
valid_no = ['N', 'n', 'No', 'no', ]
if default:
prompt = prompt + '[Y/n]'
prompt = prompt + ' [Y/n]: '
valid_yes.append('')
else:
prompt = prompt + '[y/N]'
prompt = prompt + ' [y/N]: '
valid_no.append('')

ans = input(prompt)
Expand All @@ -297,7 +295,6 @@ def color_text(text, color_name, bold=False):
This command can be used to colorify command line output. If the shell
doesn't support this or the --disable-colors options has been set, it just
returns the plain text.
Usage:
print "%s" % color_text("This text is red", "RED")
"""
Expand All @@ -311,7 +308,6 @@ def color_text(text, color_name, bold=False):
def files_in_project(curpath):
"""
Iterate over the files in the project.
Return each file under ``curpath`` with its absolute name.
"""
visited = set()
Expand Down

0 comments on commit 9d015b8

Please sign in to comment.