Skip to content

Commit

Permalink
Merge pull request #39 from sundeep-co-in/master
Browse files Browse the repository at this point in the history
backport: python 2.6 support
  • Loading branch information
definite committed Jan 20, 2016
2 parents 68a9879 + 270ee39 commit e307c96
Show file tree
Hide file tree
Showing 33 changed files with 356 additions and 308 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: python
python:
- "2.6"
- "2.7"
# command to install dependencies
install: "pip install -r requirements.txt"
install: "pip install -r requirements-dev.txt"
# command to run tests
script: make flake8 test
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Wed Jan 20 2016 Sundeep Anand <suanand@redhat.com> - 1.4.2
- Python 2.6 Support

* Tue Jan 12 2016 Sundeep Anand <suanand@redhat.com> - 1.4.1
- Implemented zanata init (ZNTA-780)
- Bug ZNTA-853 - Crash when pushing local translations
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lint-report:
pylint --reports=n zanata zanataclient

flake8:
flake8 --ignore=E501,F403,W601,F841,F401,E711,E712 zanataclient test
flake8 --ignore=E501,F403,F841,F401 zanataclient test

test:
(cd test; python test_all.py)
Expand Down
13 changes: 13 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-r requirements.txt
flake8==2.4.1
funcsigs==0.4
linecache2==1.0.0
mccabe==0.3.1
MiniMock==1.2.8
mock==1.3.0
pbr==1.8.1
pep8==1.5.7
pyflakes==0.8.1
six==1.10.0
traceback2==1.4.0
unittest2==1.1.0
15 changes: 3 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
flake8==2.4.1
funcsigs==0.4
httplib2==0.9.2
ipdb==0.8.1
mccabe==0.3.1
MiniMock==1.2.8
mock==1.3.0
pbr==1.8.1
pep8==1.5.7
polib==1.0.7
pyflakes==0.8.1
six==1.10.0
httplib2
polib
ordereddict
16 changes: 12 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import subprocess


def read(fname):
return (open(os.path.join(os.path.dirname(__file__), fname), 'rb')
.read().decode('utf-8'))


def get_client_version():
number = ""
path = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -40,15 +45,16 @@ def get_client_version():

return number

requirements = read('requirements.txt').splitlines() + [
'setuptools',
]

setup(
name="zanata-python-client",
version=get_client_version(),
packages=find_packages(),
include_package_data=True,
install_requires=[
'polib',
'httplib2'
],
install_requires=requirements,
description="Zanata Python Client.",
author='Jian Ni, Ding-Yi Chen, Anish Patil',
author_email='jni@redhat.com, dchen@redhat.com, apatil@redhat.com',
Expand Down Expand Up @@ -77,5 +83,7 @@ def get_client_version():
'License :: OSI Approved :: GNU Lesser General Public License (LGPL)',
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
],
)
15 changes: 9 additions & 6 deletions test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def setUp(self):
self.init_context = ProjectContext(command_options, 'init')

def test_command_options(self):
command_options_keys = ['project_type', 'comment_cols', 'user_config', 'project_config']
self.assertEqual(self.context.command_options.keys(), command_options_keys)
command_options_keys = ['project_type', 'project_config', 'comment_cols', 'user_config']
self.assertTrue(list(self.context.command_options.keys())[0] in command_options_keys)
self.assertTrue(list(self.context.command_options.keys())[1] in command_options_keys)
self.assertTrue(list(self.context.command_options.keys())[2] in command_options_keys)
self.assertTrue(list(self.context.command_options.keys())[3] in command_options_keys)
self.assertEqual(
self.context.command_dict,
{'project_config': './testfiles/zanata.xml', 'comment_cols': 'en-US,es,pos,description',
Expand All @@ -94,8 +97,8 @@ def test_build_local_config(self):
self.context.local_config['http_headers'],
{'Accept': 'application/json', 'X-Auth-User': 'username', 'X-Auth-Token': 'key'}
)
self.assertIn('client_version', self.context.local_config,
'local_config should contain client_version')
self.assertTrue('client_version' in self.context.local_config,
'local_config should contain client_version')

@mock.patch('zanataclient.zanatalib.projectservice.LocaleService.get_locales')
@mock.patch('zanataclient.zanatalib.versionservice.VersionService.get_server_version')
Expand Down Expand Up @@ -163,8 +166,8 @@ def test_process_locales(self):

def test_init_context(self):
context_data = self.init_context.get_context_data()
self.assertIn('servers', context_data)
self.assertIn('http://localhost:8080/zanata', context_data['servers'])
self.assertTrue('servers' in context_data)
self.assertTrue('http://localhost:8080/zanata' in context_data['servers'])

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion test/test_parseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_user_config(self):
user_name = self.config.get_config_value("username", 'servers', server)
apikey = self.config.get_config_value("key", 'servers', server)
servers = self.config.get_servers()
self.assertIn('http://localhost:8080/zanata', servers)
self.assertTrue('http://localhost:8080/zanata' in servers)
self.assertEqual(server, "local")
self.assertEqual(user_name, "username")
self.assertEqual(apikey, "key")
Expand Down
9 changes: 8 additions & 1 deletion test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
"ServiceTest",
)

import unittest
import sys
import os
sys.path.insert(0, os.path.abspath(__file__ + "/../.."))
from zanataclient.zanatalib.service import Service
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest


# test data
Expand Down Expand Up @@ -66,6 +69,10 @@ def test_messages_status_201(self):
result_set = self.service.messages(SERVICE_RESPONSE_201, RESPONSE_CONTENT)
self.assertTrue(result_set)

@unittest.skipIf(
sys.version_info < (2, 7),
'https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises'
)
def test_messages_status_401_503(self):
with self.assertRaises(SystemExit):
self.service.messages(SERVICE_RESPONSE_401, RESPONSE_CONTENT)
Expand Down
6 changes: 3 additions & 3 deletions zanataclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

from parseconfig import *
from publicanutil import *
from zanata import *
from .parseconfig import *
from .publicanutil import *
from .zanata import *
50 changes: 25 additions & 25 deletions zanataclient/cmdbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import sys
import string

from zanatalib.error import NoSuchFileException
from zanatacmd import ZanataCommand
from publicanutil import PublicanUtility
from zanatalib.logger import Logger
from .zanatalib.error import NoSuchFileException
from .zanatacmd import ZanataCommand
from .publicanutil import PublicanUtility
from .zanatalib.logger import Logger

log = Logger()

Expand All @@ -38,7 +38,7 @@ class CommandsInit(object):
def __init__(self, *args, **kargs):
for name, val in zip(self._fields, args):
setattr(self, name, val)
for key, value in kargs.iteritems():
for key, value in kargs.items():
setattr(self, key, value)

def check_essential(self, item, message):
Expand All @@ -61,7 +61,7 @@ def create_zanatacmd(self):
self.context_data.get('url'),
self.context_data.get('http_headers')
)
if self.context_data.has_key('disablesslcert'):
if 'disablesslcert' in self.context_data:
zanatacmd.disable_ssl_cert_validation()
return zanatacmd

Expand Down Expand Up @@ -190,7 +190,7 @@ def run(self):
if lang in locale_map:
lang = locale_map[lang]

if self.context_data.has_key('sourcecomments'):
if 'sourcecomments' in self.context_data:
sourcecomments = True
else:
sourcecomments = False
Expand Down Expand Up @@ -261,8 +261,8 @@ def __init__(self, *args, **kargs):
self.plural_support = self.check_plural_support(server_version)
self.log_message(self.project_id, self.version_id, username)
self.zanatacmd.verify_project(self.project_id, self.version_id)
if self.context_data.has_key('copytrans'):
if self.context_data.has_key('nocopytrans'):
if 'copytrans' in self.context_data:
if 'nocopytrans' in self.context_data:
log.error("--copytrans option cannot be used with --no-copytrans. Aborting.")
sys.exit(1)
else:
Expand All @@ -283,7 +283,7 @@ def get_files(self):
log.error("The project type is not correct, please use 'podir' and 'gettext' as project type")
sys.exit(1)

if self.context_data.has_key('srcfile'):
if 'srcfile' in self.context_data:
if project_type == 'gettext':
tmlfolder, import_file = self.process_srcfile()
filelist.append(import_file)
Expand All @@ -297,7 +297,7 @@ def get_files(self):
try:
full_path = self.search_file(tmlfolder, self.args[0])
filelist.append(full_path)
except NoSuchFileException, e:
except NoSuchFileException as e:
log.error(e.msg)
sys.exit(1)
else:
Expand All @@ -314,7 +314,7 @@ def get_files(self):
def process_merge(self):
merge = ""

if self.context_data.has_key('merge'):
if 'merge' in self.context_data:
merge = self.context_data.get('merge')
if merge != 'auto' and merge != 'import':
log.info("merge option %s is not recognized, assuming default value 'auto'" % merge)
Expand All @@ -328,9 +328,9 @@ def process_merge(self):

def get_lang_list(self):
lang_list = []
if self.context_data.has_key('lang'):
if 'lang' in self.context_data:
lang_list = self.context_data.get('lang').split(',')
elif self.context_data.has_key('locale_map'):
elif 'locale_map' in self.context_data:
lang_list = self.context_data.get('locale_map').keys()
else:
log.error("Please specify the language with '--lang' option or in zanata.xml")
Expand All @@ -341,9 +341,9 @@ def get_lang_list(self):
def process_srcdir_withsub(self):
tmlfolder = ""

if self.context_data.has_key('srcdir'):
if 'srcdir' in self.context_data:
tmlfolder = self.context_data.get('srcdir')
elif self.context_data.has_key('dir'):
elif 'dir' in self.context_data:
# Keep dir option for publican/po push
tmlfolder = self.context_data.get('dir')
else:
Expand All @@ -360,7 +360,7 @@ def process_srcdir_withsub(self):
def process_srcdir(self):
tmlfolder = ""

if self.context_data.has_key('srcdir'):
if 'srcdir' in self.context_data:
tmlfolder = self.context_data.get('srcdir')
else:
tmlfolder = os.path.abspath(os.getcwd())
Expand All @@ -372,7 +372,7 @@ def process_srcfile(self):
tmlfolder = ""
file_path = ""

if self.context_data.has_key('srcfile'):
if 'srcfile' in self.context_data:
path = self.context_data.get('srcfile')
file_path = os.path.abspath(path)
tmlfolder = file_path[0:file_path.rfind('/')]
Expand All @@ -382,7 +382,7 @@ def process_srcfile(self):
def process_transdir(self, src_folder):
trans_folder = ""

if self.context_data.has_key('transdir'):
if 'transdir' in self.context_data:
trans_folder = self.context_data.get('transdir')
elif src_folder:
trans_folder = src_folder
Expand All @@ -393,7 +393,7 @@ def process_transdir(self, src_folder):
return trans_folder

def create_outpath(self, output_folder):
if self.context_data.has_key('transdir'):
if 'transdir'in self.context_data:
output = self.context_data.get('transdir')
elif output_folder:
output = output_folder
Expand All @@ -419,7 +419,7 @@ def search_file(self, path, filename):
raise NoSuchFileException('Error 404', 'File %s not found' % filename)

def check_plural_support(self, server_version):
if server_version == None:
if not server_version:
return False

version = str(server_version.split('-')[0])
Expand All @@ -434,9 +434,9 @@ def check_plural_support(self, server_version):
def get_importpo(self):
importpo = False

if self.context_data.has_key('importpo'):
if 'importpo' in self.context_data:
importpo = True
elif self.context_data.has_key('pushtrans'):
elif 'pushtrans' in self.context_data:
importpo = True
log.info("please use --import-po for old publican push command")

Expand All @@ -445,9 +445,9 @@ def get_importpo(self):
def get_pushtrans(self):
pushtrans = False

if self.context_data.has_key('pushtrans'):
if 'pushtrans' in self.context_data:
pushtrans = True
elif self.context_data.has_key('importpo'):
elif 'importpo' in self.context_data:
pushtrans = True
log.info("--import-po option is deprecated, please use '--push-type both' instead")

Expand Down
Loading

0 comments on commit e307c96

Please sign in to comment.