From 34399aba74430a906d3f27467c58029c2a8141ba Mon Sep 17 00:00:00 2001 From: James Ni Date: Tue, 24 May 2011 00:03:39 +0800 Subject: [PATCH] Add testcase and clean the code base on pylint --- test/__init__.py | 1 + test/flies.ini | 15 +++++ test/flies.xml | 25 +++++++++ test/po/test.po | 27 +++++++++ test/pot/test.pot | 22 ++++++++ test/test_parseconfig.py | 54 ++++++++++++++++++ test/test_publicanutil.py | 54 ++++++++++++++++++ test/test_zanata.py | 29 ++++++++++ test/test_zanatacmd.py | 71 ++++++++++++++++++++++++ zanataclient/command.py | 4 +- zanataclient/parseconfig.py | 27 +++++---- zanataclient/zanata.py | 14 +++-- zanataclient/zanatacmd.py | 39 ++++++++----- zanataclient/zanatalib/docservice.py | 30 +++++----- zanataclient/zanatalib/project.py | 4 -- zanataclient/zanatalib/projectservice.py | 12 ++-- zanataclient/zanatalib/versionservice.py | 5 +- 17 files changed, 374 insertions(+), 59 deletions(-) create mode 100644 test/__init__.py create mode 100644 test/flies.ini create mode 100644 test/flies.xml create mode 100644 test/po/test.po create mode 100644 test/pot/test.pot create mode 100644 test/test_parseconfig.py create mode 100644 test/test_publicanutil.py create mode 100644 test/test_zanata.py create mode 100644 test/test_zanatacmd.py diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/__init__.py @@ -0,0 +1 @@ + diff --git a/test/flies.ini b/test/flies.ini new file mode 100644 index 0000000..53dedb4 --- /dev/null +++ b/test/flies.ini @@ -0,0 +1,15 @@ +[flies] +url = http://hudson.englab.bne.redhat.com/flies/ +username = admin +key = b6d7044e9ee3b2447c28fb7c50d86d98 + +[defaults] +debug = false +#errors = true + +[servers] +local.url = http://localhost:8080/flies +local.username = username +local.key = key + + diff --git a/test/flies.xml b/test/flies.xml new file mode 100644 index 0000000..fd22a84 --- /dev/null +++ b/test/flies.xml @@ -0,0 +1,25 @@ + + + + + http://localhost:8080/flies/ + + test-project + 5.4 + + + zh-Hans-CN + + + diff --git a/test/po/test.po b/test/po/test.po new file mode 100644 index 0000000..7f9f2bd --- /dev/null +++ b/test/po/test.po @@ -0,0 +1,27 @@ +# translation of Acls.po to Traditional Chinese +# translation of Acls.po to +# Copyright (C) 2003, 2007 Free Software Foundation, Inc. +# +# Sarah Wang , 2003. +# Xi HUANG , 2007. +# Chester Cheng , 2007. +msgid "" +msgstr "" +"Project-Id-Version: Acls\n" +"Report-Msgid-Bugs-To: http://bugs.kde.org\n" +"POT-Creation-Date: 2001-02-09 01:25+0100\n" +"PO-Revision-Date: 2007-07-11 14:49+1000\n" +"Last-Translator: Chester Cheng \n" +"Language-Team: Traditional Chinese \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: KBabel 1.11.4\n" + +# EXACT MATCH +#. Tag: title +#: Acls.xml:8 +#, no-c-format +msgid "Access Control Lists" +msgstr "访问存取控制列表" + diff --git a/test/pot/test.pot b/test/pot/test.pot new file mode 100644 index 0000000..51e4e76 --- /dev/null +++ b/test/pot/test.pot @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR Free Software Foundation, Inc. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2001-02-09 01:25+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: application/x-xml2pot; charset=UTF-8\n" +"Content-Transfer-Encoding: ENCODING\n" + +#. Tag: title +#: Acls.xml:8 +#, no-c-format +msgid "Access Control Lists" +msgstr "" + diff --git a/test/test_parseconfig.py b/test/test_parseconfig.py new file mode 100644 index 0000000..9f0f58a --- /dev/null +++ b/test/test_parseconfig.py @@ -0,0 +1,54 @@ +# +# Flies Python Client +# +# Copyright (c) 2010 Jian Ni +# Copyright (c) 2010 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + +all__ = ( + "ConfigTest", + ) + +import unittest +import sys, os +sys.path.insert(0, os.path.abspath(__file__+"/../..")) + +from zanataclient.parseconfig import ZanataConfig + + +class ConfigTest(unittest.TestCase): + def setUp(self): + self.config = ZanataConfig() + + def test_user_config(self): + self.config.set_userconfig("./flies.ini") + server = self.config.get_server("http://localhost:8080/flies") + user_name = self.config.get_config_value("username", 'servers', server) + apikey = self.config.get_config_value("key", 'servers',server) + self.assertEqual(server, "local") + self.assertEqual(user_name, "username") + self.assertEqual(apikey, "key") + + def test_project_config(self): + project_config = self.config.read_project_config("./flies.xml") + self.assertEqual(project_config['project_url'], "http://localhost:8080/flies/") + self.assertEqual(project_config['project_id'], "test-project") + self.assertEqual(project_config['project_version'], "5.4") + self.assertEqual(project_config['locale_map'], {"zh-CN": "zh-Hans-CN"}) + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_publicanutil.py b/test/test_publicanutil.py new file mode 100644 index 0000000..d06dfb5 --- /dev/null +++ b/test/test_publicanutil.py @@ -0,0 +1,54 @@ +# +# Zanata Python Client +# +# Copyright (c) 2011 Jian Ni +# Copyright (c) 2011 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + +all__ = ( + "PublicanUtilityTest", + ) + +import unittest +import sys, os +sys.path.insert(0, os.path.abspath(__file__+"/../..")) + +from zanataclient.publicanutil import PublicanUtility + + +class PublicanUtilityTest(unittest.TestCase): + def setUp(self): + self.publican = PublicanUtility() + + def test_strippath(self): + filename = self.publican.strip_path("./pot/test.pot", "./pot") + self.assertEqual(filename, "test") + + def test_potfiletojson(self): + body, filename = self.publican.potfile_to_json("./pot/test.pot", "./pot") + expect = """{"lang": "en-US", "extensions": [{"comment": "SOME DESCRIPTIVE TITLE.\\nCopyright (C) YEAR Free Software Foundation, Inc.\\nFIRST AUTHOR , YEAR.\\n", "object-type": "po-header", "entries": [{"value": "PACKAGE VERSION", "key": "Project-Id-Version"}, {"value": "2001-02-09 01:25+0100", "key": "POT-Creation-Date"}, {"value": "YEAR-MO-DA HO:MI+ZONE", "key": "PO-Revision-Date"}, {"value": "FULL NAME ", "key": "Last-Translator"}, {"value": "LANGUAGE ", "key": "Language-Team"}, {"value": "1.0", "key": "MIME-Version"}, {"value": "application/x-xml2pot; charset=UTF-8", "key": "Content-Type"}, {"value": "ENCODING", "key": "Content-Transfer-Encoding"}]}], "contentType": "application/x-gettext", "name": "test", "textFlows": [{"lang": "en-US", "content": "Access Control Lists", "extensions": [{"object-type": "comment", "value": "Tag: title", "space": "preserve"}, {"object-type": "pot-entry-header", "references": ["Acls.xml:8"], "flags": ["no-c-format"], "context": "", "extractedComment": ""}], "id": "782f49c4e93c32403ba0b51821b38b90", "revision": 1}]}""" + self.assertEqual(expect, body) + self.assertEqual(filename, "test") + + def test_pofiletojson(self): + body = self.publican.pofile_to_json("./po/test.po") + expect = """{"textFlowTargets": [{"content": "\\u8bbf\\u95ee\\u5b58\\u53d6\\u63a7\\u5236\\u5217\\u8868", "extensions": [{"object-type": "comment", "value": "Tag: title", "space": "preserve"}], "state": "Approved", "resId": "782f49c4e93c32403ba0b51821b38b90"}], "extensions": [{"comment": "translation of Acls.po to Traditional Chinese\\ntranslation of Acls.po to\\nCopyright (C) 2003, 2007 Free Software Foundation, Inc.\\n\\nSarah Wang , 2003.\\nXi HUANG , 2007.\\nChester Cheng , 2007.", "object-type": "po-target-header", "entries": [{"value": "Acls", "key": "Project-Id-Version"}, {"value": "http://bugs.kde.org", "key": "Report-Msgid-Bugs-To"}, {"value": "2001-02-09 01:25+0100", "key": "POT-Creation-Date"}, {"value": "2007-07-11 14:49+1000", "key": "PO-Revision-Date"}, {"value": "Chester Cheng ", "key": "Last-Translator"}, {"value": "Traditional Chinese ", "key": "Language-Team"}, {"value": "1.0", "key": "MIME-Version"}, {"value": "text/plain; charset=UTF-8", "key": "Content-Type"}, {"value": "8bit", "key": "Content-Transfer-Encoding"}, {"value": "KBabel 1.11.4", "key": "X-Generator"}]}], "links": []}""" + self.assertEqual(expect, body) + +if __name__ == '__main__': + unittest.main() + diff --git a/test/test_zanata.py b/test/test_zanata.py new file mode 100644 index 0000000..323804c --- /dev/null +++ b/test/test_zanata.py @@ -0,0 +1,29 @@ +''' +Created on May 20, 2011 + +@author: jamesni +''' +import unittest +import sys, os +sys.path.insert(0, os.path.abspath(__file__+"/../..")) + +from zanataclient import zanata + + +class ZanataTest(unittest.TestCase): + def setup(self): + pass + + def test_convert_serverversion(self): + server_version = "1.3.3" + version_number = zanata.convert_serverversion(server_version) + self.assertEqual(version_number, 1.3) + + def test_seachfile(self): + path = "./po" + result = zanata.search_file(path, "test.po") + self.assertEqual(result, "./po/test.po") + +if __name__ == '__main__': + unittest.main() + \ No newline at end of file diff --git a/test/test_zanatacmd.py b/test/test_zanatacmd.py new file mode 100644 index 0000000..ce40833 --- /dev/null +++ b/test/test_zanatacmd.py @@ -0,0 +1,71 @@ +# +# Flies Python Client +# +# Copyright (c) 2010 Jian Ni +# Copyright (c) 2010 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + +all__ = ( + "CommandlineTest", + ) + +import unittest +import sys, os +from minimock import Mock +sys.path.insert(0, os.path.abspath(__file__+"/../..")) + +from zanataclient.zanatacmd import ZanataCommand +from zanataclient.zanatalib import ZanataResource +from zanataclient.zanatalib.project import Project + + +class CommandlineTest(unittest.TestCase): + def setUp(self): + self.zanatacmd = ZanataCommand() + + def test_list_projects(self): + projects = [] + project_data = {'id':"test-project", 'name':"Test Project", 'type':"IterationProject", 'links':[]} + projects.append(Project(project_data)) + + url = "http://localhost" + zanata = ZanataResource(url) + zanata.projects = Mock(url) + zanata.projects.list.mock_returns = projects + result = self.zanatacmd.list_projects(zanata) + self.assertEqual(result[0].id, 'test-project') + + def test_project_info(self): + pass + + def test_version_info(self): + pass + + def test_create_project(self): + pass + + def test_create_version(self): + pass + + def test_pull_command(self): + pass + + def test_push_command(self): + pass + +if __name__ == '__main__': + unittest.main() diff --git a/zanataclient/command.py b/zanataclient/command.py index d72791f..5858c4d 100644 --- a/zanataclient/command.py +++ b/zanataclient/command.py @@ -26,9 +26,7 @@ import getopt import sys -import logging -import os -import inspect + class OptionConfigurationError(Exception): pass diff --git a/zanataclient/parseconfig.py b/zanataclient/parseconfig.py index 9521fa0..c6553a7 100644 --- a/zanataclient/parseconfig.py +++ b/zanataclient/parseconfig.py @@ -30,12 +30,17 @@ project_config = {'project_url':'', 'project_id':'', 'project_version':'', 'locale_map':{}} + class ZanataConfig: - def set_userconfig(self, path): + def __init__(self): + self.configparser = "" + self._config = "" + + def set_userconfig(self, path): self.configparser = ConfigParser.ConfigParser() self._config = self.configparser.read(['zanata.ini', path]) - def get_server(self, url): + def get_server(self, url): if self._config: try: item_list = self.configparser.items('servers') @@ -49,24 +54,24 @@ def get_server(self, url): if url == address: server = item[0][:-4] return server - except ConfigParser.NoOptionError, NoSectionError: + except ConfigParser.NoOptionError, ConfigParser.NoSectionError: raise else: return None - def get_config_value(self, name, section, server): + def get_config_value(self, name, section, server): if self._config: try: value = self.configparser.get(section, server+'.'+name) return value - except ConfigParser.NoOptionError, NoSectionError: + except ConfigParser.NoOptionError, ConfigParser.NoSectionError: raise else: return None - def read_project_config(self, filename): + def read_project_config(self, filename): log = Logger() - project_config={'project_url':'', 'project_id':'', 'project_version':'', 'locale_map':{}} + if os.path.getsize(filename) == 0: log.info('The project xml: flies.xml is empty, need command line options') return project_config @@ -111,11 +116,11 @@ def read_project_config(self, filename): for node in locale.childNodes: if node.nodeType == node.TEXT_NODE: if locale.getAttribute("map-from"): - map = {locale.getAttribute("map-from"):node.data} - project_config['locale_map'].update(map) + locale_map = {locale.getAttribute("map-from"):node.data} + project_config['locale_map'].update(locale_map) else: - map = {node.data:node.data} - project_config['locale_map'].update(map) + locale_map = {node.data:node.data} + project_config['locale_map'].update(locale_map) return project_config diff --git a/zanataclient/zanata.py b/zanataclient/zanata.py index 3e0eec6..74fa60d 100644 --- a/zanataclient/zanata.py +++ b/zanataclient/zanata.py @@ -446,6 +446,12 @@ def search_file(path, filename): raise NoSuchFileException('Error 404', 'File %s not found' % filename) +def convert_serverversion(server_version): + version = str(server_version.split('-')[0]) + main_ver = version[:3] + version_number = string.atof(main_ver) + return version_number + ################################# # # Command Handler @@ -525,7 +531,7 @@ def version_info(command_options, args): iteration_id = project_config['project_version'] url = process_url(project_config, command_options) - username, apikey = read_user_config(url, command_options) + get_version(url) if command_options.has_key('project_id'): @@ -633,15 +639,15 @@ def create_version(command_options, args): version_desc = command_options['version_desc'][0]['value'] if server_version: - version = str(server_version.split('-')[0]) - server_version_number = string.atof(version) + version_number = convert_serverversion(server_version) - if server_version_number <= 1.2 and not version_name: + if version_number <= 1.2 and not version_name: version_name = args[0] else: if not version_name: version_name = args[0] + zanata = generate_zanataresource(url, username, apikey) zanatacmd = ZanataCommand() zanatacmd.create_version(zanata, project_id, version_id, version_name, version_desc) diff --git a/zanataclient/zanatacmd.py b/zanataclient/zanatacmd.py index 4d21172..4c2aee4 100644 --- a/zanataclient/zanatacmd.py +++ b/zanataclient/zanatacmd.py @@ -23,10 +23,19 @@ import sys import os -from zanatalib import * -from zanatalib.error import * -from parseconfig import ZanataConfig from publicanutil import PublicanUtility +from zanatalib.project import Project +from zanatalib.project import Iteration +from zanatalib.outpututil import Logger +from zanatalib.error import NoSuchProjectException +from zanatalib.error import UnAuthorizedException +from zanatalib.error import UnAvaliableResourceException +from zanatalib.error import BadRequestBodyException +from zanatalib.error import InvalidPOTFileException +from zanatalib.error import SameNameDocumentException +from zanatalib.error import InvalidOptionException +from zanatalib.error import NotAllowedException +from zanatalib.error import ProjectExistException class ZanataCommand: def __init__(self): @@ -119,8 +128,6 @@ def del_server_content(self, zanata, tmlfolder, project_id, iteration_id, push_f else: self.log.error("Please enter yes(y) or no(n)") - - for name in filelist: if ',' in name: request = name.replace(',', '\,') @@ -158,6 +165,8 @@ def list_projects(self, zanata): print ("Project Name: %s")%project.name print ("Project Type: %s")%project.type print ("Project Links: %s\n")%[{'href':link.href, 'type':link.type, 'rel':link.rel} for link in project.links] + + return projects def project_info(self, zanata, project_id): """ @@ -169,9 +178,9 @@ def project_info(self, zanata, project_id): print ("Project Name: %s")%p.name print ("Project Type: %s")%p.type print ("Project Description: %s")%p.description - except NoSuchProjectException, e: + except NoSuchProjectException: self.log.error("There is no Such Project on the server") - except InvalidOptionException, e: + except InvalidOptionException: self.log.error("Options are not valid") def version_info(self, zanata, project_id, iteration_id): @@ -186,7 +195,7 @@ def version_info(self, zanata, project_id, iteration_id): print ("Version Name: %s")%iteration.name if hasattr(iteration, 'description'): print ("Version Description: %s")%iteration.description - except NoSuchProjectException, e: + except NoSuchProjectException: self.log.error("There is no such project or version on the server") def create_project(self, zanata, project_id, project_name, project_desc): @@ -319,18 +328,18 @@ def pull_command(self, zanata, locale_map, project_id, iteration_id, filelist, l """ publicanutil = PublicanUtility() #if file no specified, retrieve all the files of project - for file in filelist: + for file_item in filelist: pot = "" result = "" folder = "" - if '/' in file: - name = file.split('/')[-1] - folder = file.split('/')[0] - request_name = file.replace('/', ',') + if '/' in file_item: + name = file_item.split('/')[-1] + folder = file_item.split('/')[0] + request_name = file_item.replace('/', ',') else: - name = file - request_name = file + name = file_item + request_name = file_item self.log.info("\nFetching the content of %s from Zanata/Flies server: "%name) diff --git a/zanataclient/zanatalib/docservice.py b/zanataclient/zanatalib/docservice.py index 29b6fa2..d4c22e4 100644 --- a/zanataclient/zanatalib/docservice.py +++ b/zanataclient/zanatalib/docservice.py @@ -25,14 +25,16 @@ "DocumentService", ) -import os try: import json except ImportError: import simplejson as json -import sys -from rest.client import RestClient -from error import * +from error import InternalServerError +from error import UnAuthorizedException +from error import BadRequestBodyException +from error import SameNameDocumentException +from error import UnAvaliableResourceException + class DocumentService: def __init__(self, projects): @@ -42,18 +44,18 @@ def get_file_list(self, projectid, iterationid): res, content = self.projects.restclient.request_get('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r'%(projectid, iterationid)) if res['status'] == '200' or res['status'] == '304': - list = json.loads(content) - filelist = [file.get('name') for file in list] + files = json.loads(content) + filelist = [item.get('name') for item in files] return filelist elif res['status'] == '500': raise InternalServerError('Error 500', 'An internal server error happens') - def update_template(self, projectid, iterationid, file, resources, copytrans): + def update_template(self, projectid, iterationid, file_id, resources, copytrans): headers = {} headers['X-Auth-User'] = self.projects.username headers['X-Auth-Token'] = self.projects.apikey - res, content = self.projects.restclient.request_put('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid,iterationid,file), args=resources, headers=headers, copytrans=copytrans) + res = self.projects.restclient.request_put('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid,iterationid,file_id), args=resources, headers=headers, copytrans=copytrans) if res['status'] == '201' or res['status'] == '200': return True @@ -90,12 +92,12 @@ def commit_template(self, projectid, iterationid, resources, copytrans): elif res['status'] == '409': raise SameNameDocumentException('Error 409', content) - def delete_template(self, projectid, iterationid, file): + def delete_template(self, projectid, iterationid, file_id): headers = {} headers['X-Auth-User'] = self.projects.username headers['X-Auth-Token'] = self.projects.apikey - res, content = self.projects.restclient.request_delete('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid, iterationid, file), headers=headers) + res, content = self.projects.restclient.request_delete('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid, iterationid, file_id), headers=headers) if res['status'] == '200' or res['status'] == '304': return content @@ -104,8 +106,8 @@ def delete_template(self, projectid, iterationid, file): elif res['status'] == '401': raise UnAuthorizedException('Error 401', 'This operation is not authorized, please check username and apikey') - def retrieve_template(self, projectid, iterationid, file): - res, content = self.projects.restclient.request_get('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid, iterationid, file)) + def retrieve_template(self, projectid, iterationid, file_id): + res, content = self.projects.restclient.request_get('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s'%(projectid, iterationid, file_id)) headers = {} headers['X-Auth-User'] = self.projects.username headers['X-Auth-Token'] = self.projects.apikey @@ -117,7 +119,7 @@ def retrieve_template(self, projectid, iterationid, file): elif res['status'] == '401': raise UnAuthorizedException('Error 401', 'This operation is not authorized, please check username and apikey') - def retrieve_translation(self, lang, projectid, iterationid, file): + def retrieve_translation(self, lang, projectid, iterationid, file_id): """ Get translation content of file from Flies server @param lang: language @@ -132,7 +134,7 @@ def retrieve_translation(self, lang, projectid, iterationid, file): headers['X-Auth-User'] = self.projects.username headers['X-Auth-Token'] = self.projects.apikey - res, content = self.projects.restclient.request_get('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s/translations/%s'%(projectid, iterationid, file, lang)) + res, content = self.projects.restclient.request_get('/seam/resource/restv1/projects/p/%s/iterations/i/%s/r/%s/translations/%s'%(projectid, iterationid, file_id, lang)) if res['status'] == '200' or res['status'] == '304': return content diff --git a/zanataclient/zanatalib/project.py b/zanataclient/zanatalib/project.py index b4ad22d..8de7f0f 100644 --- a/zanataclient/zanatalib/project.py +++ b/zanataclient/zanatalib/project.py @@ -24,10 +24,6 @@ __all__ = ( "Project","Iteration" ) -try: - import json -except ImportError: - import simplejson as json class Link(object): diff --git a/zanataclient/zanatalib/projectservice.py b/zanataclient/zanatalib/projectservice.py index 73d505b..28d54e9 100644 --- a/zanataclient/zanatalib/projectservice.py +++ b/zanataclient/zanatalib/projectservice.py @@ -24,7 +24,6 @@ "ProjectService", ) -import sys try: import json except ImportError: @@ -32,7 +31,12 @@ from rest.client import RestClient from project import Project from project import Iteration -from error import * +from error import ProjectExistException +from error import NoSuchProjectException +from error import UnAuthorizedException +from error import BadRequestException +from error import NotAllowedException + class ProjectService: """ @@ -84,15 +88,13 @@ def create(self, project): @raise UnAuthorizedException: @raise BadRequestException: """ - exist = False headers = {} headers['X-Auth-User'] = self.username headers['X-Auth-Token'] = self.apikey try: self.get(project.id) + except ProjectExistException: raise ProjectExistException('Status 200', 'The project is already exist') - except NoSuchProjectException: - exist = False body ='''{"name":"%s","id":"%s","description":"%s","type":"IterationProject"}'''%(project.name,project.id,project.desc) res, content = self.restclient.request_put('/seam/resource/restv1/projects/p/%s'%project.id, args=body, headers=headers) diff --git a/zanataclient/zanatalib/versionservice.py b/zanataclient/zanatalib/versionservice.py index 587411e..e92f28e 100644 --- a/zanataclient/zanatalib/versionservice.py +++ b/zanataclient/zanatalib/versionservice.py @@ -25,14 +25,13 @@ "VersionService", ) -import os try: import json except ImportError: import simplejson as json -import sys from rest.client import RestClient -from error import * +from error import UnAvaliableResourceException + class VersionService: def __init__(self, base_url):