Skip to content

Commit

Permalink
Merge pull request #231 from transifex/typo-fixes
Browse files Browse the repository at this point in the history
Fix a series of typos and flake8 errors
  • Loading branch information
rigaspapas authored May 14, 2018
2 parents b8746bc + 55539b1 commit 58259ab
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 43 deletions.
4 changes: 2 additions & 2 deletions txclib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def __init__(self, token=None, username=None, password=None,

def get(self, api_call, *args, **kwargs):
"""
Performs the GET api call specified by api_call and
Performs the GET API call specified by api_call and
parses the response
"""
# mock response
if api_call not in self.VALID_CALLS:
raise Exception(
"Tried to perform unsupported api call {}".format(
"Tried to perform unsupported API call {}".format(
api_call
)
)
Expand Down
1 change: 0 additions & 1 deletion txclib/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def main(argv=None):
sys.exit(1)


# Run baby :) ... run
if __name__ == "__main__":
# sys.argv[0] is the name of the script that we’re running.
main()
35 changes: 19 additions & 16 deletions txclib/commands.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# -*- coding: utf-8 -*-
"""In this file we have all the top level commands for the transifex client.
Since we're using a way to automatically list them and execute them, when
adding code to this file you must take care of the following:
"""
In this file we have all the top level commands for the Transifex client. Since
we're using a way to automatically list them and execute them, when adding code
to this file you must take care of the following:
* Added functions must begin with 'cmd_' followed by the actual name of the
command being used in the command line (eg cmd_init)
command being used in the command line (e.g. cmd_init)
* The description for each function that we display to the user is read from
the func_doc attribute which reads the doc string. So, when adding
docstring to a new function make sure you add an oneliner which is
docstring to a new function make sure you add an one-liner which is
descriptive and is meant to be seen by the user.
* When including libraries, it's best if you include modules instead of
functions because that way our function resolution will work faster and the
chances of overlapping are minimal
* All functions should use the OptionParser and should have a usage and
descripition field.
description field.
"""
import os
import sys
Expand All @@ -35,7 +36,7 @@


def cmd_init(argv, path_to_tx):
"""Initialize a new transifex project."""
"""Initialize a new Transifex project."""
parser = init_parser()
options = parser.parse_args(argv)
path_to_tx = options.path_to_tx or os.getcwd()
Expand Down Expand Up @@ -89,14 +90,16 @@ def cmd_init(argv, path_to_tx):


def cmd_set(argv, path_to_tx):
"""Add local or remote files under transifex. Warning: \
This command will be deprecated in a future release of the \
client. You should use the `tx config` command."""
"""
Add local or remote files under Transifex. Warning: This command will be
deprecated in a future release of the client. You should use the
`tx config` command.
"""
cmd_config(argv, path_to_tx, is_legacy=True)


def cmd_config(argv, path_to_tx, is_legacy=False):
"""Add local or remote files under transifex"""
"""Add local or remote files under Transifex"""
from_wizard = False
if len(argv) == 0:
# since interactive wizard should be equivalent to auto-local
Expand Down Expand Up @@ -219,7 +222,7 @@ def _print_instructions(resource, path_to_tx):


def subcommand_mapping_bulk(path_to_tx, options, **kwargs):
"""Add local files for multiple resources under transifex"""
"""Add local files for multiple resources under Transifex"""

if not options.file_extension.startswith('.'):
file_extension = '.{}'.format(options.file_extension)
Expand Down Expand Up @@ -321,7 +324,7 @@ def _auto_local(path_to_tx, resource, source_language, expression,
if execute:
logger.info("Updating file expression for resource %s ( %s )." % (
resource, expression))
# Eval file_filter relative to root dir
# Evaluate file_filter relative to root dir
file_filter = posix_path(
os.path.relpath(os.path.join(curpath, expression), path_to_tx)
)
Expand Down Expand Up @@ -590,7 +593,7 @@ def cmd_help(argv, path_to_tx):
# or print summary of all commands

# the code below will only be executed if the KeyError exception is thrown
# becuase in all other cases the function called with --help will exit
# because in all other cases the function called with --help will exit
# instead of return here
keys = list(fns.keys())
keys.sort()
Expand Down Expand Up @@ -620,7 +623,7 @@ def _go_to_dir(path):
argument.
Args:
path: The path to chdor to.
path: The path to chdir to.
Raises:
UnInitializedError, in case the directory has not been initialized.
"""
Expand Down Expand Up @@ -651,7 +654,7 @@ def _set_type(resource, value, path_to_tx):


def _set_project_option(resource, name, value, path_to_tx, func_name):
"""Save the option to the project config file."""
"""Save the option to the project configuration file."""
if value is None:
return
if not resource:
Expand Down
12 changes: 7 additions & 5 deletions txclib/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ def help_parser():

def init_parser():
"""Return the command-line parser for the init command."""
description = "This command initializes a new project for use with "\
"Transifex. It is recommended to execute this command in the "\
"top level directory of your project so that you can include "\
"all files under it in transifex. If no path is provided, the "\
"current working dir will be used."
description = (
"This command initializes a new project for use with Transifex. It "
"is recommended to execute this command in the top level directory "
"of your project so that you can include all files under it in "
"Transifex. If no path is provided, the current working directory"
"will be used."
)
parser = ArgumentParser(description=description)
parser.add_argument("--host", action="store", dest="host", default=None,
help="Specify a default Transifex host.")
Expand Down
30 changes: 16 additions & 14 deletions txclib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@


class Project(object):
"""Represent an association between the local and
remote project instances.
"""
Represent an association between the local and remote project instances.
"""

SKIP_DECODE_I18N_TYPES = ['DOCX', 'XLSX']
Expand Down Expand Up @@ -113,7 +113,8 @@ def getset_host_credentials(self, host, username=None, password=None,
# User api info from environment variable
password = os.environ['TX_TOKEN']
username = API_USERNAME
"""We need to check if hostname info exists in the .transifexrc file
"""
We need to check if hostname info exists in the .transifexrc file
If not, it means that this is the first time this function runs, so
we need to create its data.
"""
Expand Down Expand Up @@ -163,7 +164,7 @@ def getset_host_credentials(self, host, username=None, password=None,
# api we can only use a token and not a password so we do an extra
# validation and prompt the use for a token if the validation fails
if only_token and not self.validate_credentials(username, password):
logger.info("You need a valid api token to proceed")
logger.info("You need a valid API token to proceed")
username = API_USERNAME
password = self._token_prompt(host)
save = True
Expand Down Expand Up @@ -205,7 +206,7 @@ def _token_prompt(self, host):

def set_remote_resource(self, resource, source_lang, i18n_type, host,
file_filter=None):
"""Method to handle the add/conf of a remote resource."""
"""Method to handle the addition/configuration of a remote resource."""
if file_filter is None:
file_filter = self.FILE_FILTER

Expand Down Expand Up @@ -287,7 +288,7 @@ def get_source_file(self, resource):
def get_resource_files(self, resource, xliff=False):
"""Get a dict for all files assigned to a resource.
First we calculate the files matching the file expression and
then we apply all translation excpetions.
then we apply all translation exceptions.
The resulting dict will be in this format:
{ 'en': 'path/foo/en/bar.po',
Expand Down Expand Up @@ -349,7 +350,7 @@ def get_resource_option(self, resource, option):
return None

def get_resource_list(self, project=None):
"""Parse config file and return tuples with the following format
"""Parse configuration file and return tuples with the following format
[ (project_slug, resource_slug), (..., ...)]
"""
Expand All @@ -366,8 +367,9 @@ def get_resource_list(self, project=None):
return resource_list

def save(self):
"""Store the config dictionary
in the .tx/config file of the project.
"""
Store the configuration dictionary in the .tx/config file of the
project.
"""
utils.save_tx_config(self.config_file, self.config)
utils.save_txrc_file(self.txrc_file, self.txrc)
Expand Down Expand Up @@ -1274,10 +1276,10 @@ def get_chosen_resources(self, resources):
return selected_resources

def _languages_to_pull(self, languages, files, lang_map, stats, force):
"""Get a set of langauges to pull.
"""Get a set of languages to pull.
Args:
languages: A list of languages the user selected in cmd.
languages: A list of languages the user selected in command.
files: A dictionary of current local translation files.
Returns:
A tuple of a set of existing languages and new translations.
Expand Down Expand Up @@ -1383,7 +1385,7 @@ def _create_resource(self, resource, pslug, fileinfo, filename, **kwargs):
return r

def _get_url_by_pull_mode(self, mode):
"""Get the url by the pull mode.
"""Get the URL by the pull mode.
If the pull mode is not valid, the default pull mode will be used.
"""
Expand All @@ -1399,7 +1401,7 @@ def _get_url_by_pull_mode(self, mode):
return DEFAULT_PULL_URL

def _get_option(self, resource, option):
"""Get the value for the option in the config file.
"""Get the value for the option in the configuration file.
If the option is not in the resource section, look for it in
the project.
Expand Down Expand Up @@ -1429,7 +1431,7 @@ def set_default_mode(self, resources, mode):
self._set_resource_option(resources, key='mode', value=mode)

def _set_resource_option(self, resources, key, value):
"""Set options in the config file.
"""Set options in the configuration file.
If resources is empty. set the option globally.
"""
Expand Down
8 changes: 4 additions & 4 deletions txclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def parse_tx_url(url):
if m:
return type_, m.groupdict()
raise Exception(
"tx: Malformed url given."
"tx: Malformed URL given."
" Please refer to our docs: http://bit.ly/txcconfig"
)

Expand Down Expand Up @@ -440,7 +440,7 @@ def confirm(prompt='Continue?', default=True):

def color_text(text, color_name, bold=False):
"""
This command can be used to colorify command line output. If the shell
This command can be used to colorize 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:
Expand Down Expand Up @@ -582,7 +582,7 @@ def get_tx_dir_path(path_to_tx):


def read_config_file(config_file):
"""Parse the config file and return its contents."""
"""Parse the configuration file and return its contents."""
config = OrderedRawConfigParser()
try:
config.read(config_file)
Expand Down Expand Up @@ -659,7 +659,7 @@ def get_transifex_file(directory=None):


def save_tx_config(config_file, config):
"""Save the local config file."""
"""Save the local configuration file."""
fh = open(config_file, "w")
config.write(fh)
fh.close()
Expand Down
2 changes: 1 addition & 1 deletion txclib/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import platform
from pkg_resources import resource_filename, resource_string
from pkg_resources import resource_filename
import txclib


Expand Down

0 comments on commit 58259ab

Please sign in to comment.