Skip to content

Commit

Permalink
Merge pull request #228 from transifex/TX-9464-no-interactive-on-pull
Browse files Browse the repository at this point in the history
Add the no-interactive flag to the pull command
  • Loading branch information
rigaspapas authored Apr 30, 2018
2 parents bdcb556 + 1992576 commit c7b0173
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
19 changes: 17 additions & 2 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_pull_branch_git_repo(self, project_mock, log_mock, bmock):
branch='a-branch', fetchall=False, fetchsource=False,
force=False, languages=[], minimum_perc=None, mode=None,
overwrite=True, pseudo=False, resources=[], skip=False,
xliff=False, parallel=False
xliff=False, parallel=False, no_interactive=False
)
pr_instance.pull.assert_has_calls([pull_call])

Expand All @@ -182,10 +182,25 @@ def test_pull_with_branch_and_branchname_option(
branch='somebranch', fetchall=False, fetchsource=False,
force=False, languages=[], minimum_perc=None, mode=None,
overwrite=True, pseudo=False, resources=[], skip=False,
xliff=False, parallel=False
xliff=False, parallel=False, no_interactive=False
)
pr_instance.pull.assert_has_calls([pull_call])

@patch('txclib.commands.project')
def test_pull_with_no_interactive(self, project_mock):
pr_instance = MagicMock()
pr_instance.pull.return_value = True
project_mock.Project.return_value = pr_instance
cmd_pull(['--no-interactive'], '.')
pull_call = call(
fetchall=False, force=False, minimum_perc=None,
skip=False, no_interactive=True, resources=[], pseudo=False,
languages=[], fetchsource=False, mode=None, branch=None,
xliff=False, parallel=False, overwrite=True
)
self.assertEqual(pr_instance.pull.call_count, 1)
pr_instance.pull.assert_has_calls([pull_call])


class TestConfigCommand(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion txclib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def cmd_pull(argv, path_to_tx):
fetchall=options.fetchall, fetchsource=options.fetchsource,
force=options.force, skip=skip, minimum_perc=minimum_perc,
mode=options.mode, pseudo=pseudo, xliff=xliff, branch=branch,
parallel=parallel,
parallel=parallel, no_interactive=options.no_interactive,
)
logger.info("Done.")

Expand Down
3 changes: 3 additions & 0 deletions txclib/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ def pull_parser():
"file as xliff.")
parser.add_argument("--parallel", action="store_true", default=False,
help="perform push/pull requests in parallel")
parser.add_argument("--no-interactive", action="store_true",
dest="no_interactive", default=False,
help="Don't require user input.")
return parser


Expand Down
22 changes: 15 additions & 7 deletions txclib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def getset_host_credentials(self, host, username=None, password=None,
if not (username and password) and not \
(config_username and config_password):
username = API_USERNAME
password = self._token_prompt(host)
if not no_interactive:
password = self._token_prompt(host)
save = True
elif config_username and config_password:
if username == config_username and password == config_password:
Expand Down Expand Up @@ -391,7 +392,7 @@ def _slug_with_branch(self, resource_slug, branch):
def pull(self, languages=None, resources=None, overwrite=True,
fetchall=False, fetchsource=False, force=False, skip=False,
minimum_perc=0, mode=None, pseudo=False, xliff=False, branch=None,
parallel=False):
parallel=False, no_interactive=False):
"""Pull all translations file from Transifex server."""
languages = languages or []
resources = resources or []
Expand Down Expand Up @@ -422,7 +423,9 @@ def pull(self, languages=None, resources=None, overwrite=True,
logger.debug("URL data are: %s" % self.url_info)

try:
stats = self._get_stats_for_resource()
stats = self._get_stats_for_resource(
no_interactive=no_interactive
)
details_response, _ = self.do_url_request('resource_details')
except Exception as e:
if isinstance(e, HttpNotAuthorized):
Expand Down Expand Up @@ -916,14 +919,17 @@ def _delete_translation(self, project_details, resource, stats, language):

def do_url_request(self, api_call, multipart=False, data=None,
files=None, method="GET", skip_decode=False,
params=None, parallel=False, **kwargs):
params=None, parallel=False, no_interactive=False,
**kwargs):
"""Issues a url request."""
files = files or []
params = params or {}

# Read the credentials from the config file (.transifexrc)
host = self.url_info['host']
username, passwd = self.getset_host_credentials(host)
username, passwd = self.getset_host_credentials(
host, no_interactive=no_interactive
)
try:
hostname = self.txrc.get(host, 'hostname')
except configparser.NoSectionError:
Expand Down Expand Up @@ -1223,10 +1229,12 @@ def _new_translations_to_add(self, files, slang, lang_map,
new_translations.append(lang)
return set(new_translations)

def _get_stats_for_resource(self):
def _get_stats_for_resource(self, no_interactive=False):
"""Get the statistics information for a resource."""
try:
r, charset = self.do_url_request('resource_stats')
r, charset = self.do_url_request(
'resource_stats', no_interactive=no_interactive
)
logger.debug("Statistics response is %s" % r)
stats = utils.parse_json(r)
except utils.HttpNotFound:
Expand Down

0 comments on commit c7b0173

Please sign in to comment.