Skip to content

Commit

Permalink
add --version and -V option for display version info, remove python c…
Browse files Browse the repository at this point in the history
…lient specific options from zanata.xml
  • Loading branch information
jamesni committed Aug 23, 2011
1 parent f9a3081 commit 14f6833
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
22 changes: 18 additions & 4 deletions zanataclient/command.py
Expand Up @@ -26,7 +26,7 @@

import getopt
import sys

import os

class OptionConfigurationError(Exception):
pass
Expand Down Expand Up @@ -203,9 +203,8 @@ def _parse_command_line(option_sets, subcmds=None, sys_args=None):
print "Unknown command!"
sys.exit(1)
else:
command = orig_command
# print "Please complete the command!"
# sys.exit(1)
print "Please complete the command!"
sys.exit(1)

if orig_command == name and not subcmd:
command = orig_command
Expand Down Expand Up @@ -283,6 +282,21 @@ def handle_program(
}
)
sys.exit(0)
elif program_options.has_key('client_version'):
#Retrieve the version of client
version_number = ""
path = os.path.dirname(os.path.realpath(__file__))
version_file = os.path.join(path, 'VERSION-FILE')
try:
version = open(version_file, 'rb')
client_version = version.read()
version.close()
version_number = client_version.rstrip().strip('version: ')
except IOError:
log.error("Please run VERSION-GEN or 'make install' to generate VERSION-FILE")
version_number = "UNKNOWN"

print "zanata python client version: %s"%version_number
else:
if not command:
raise getopt.GetoptError("No command specified.")
Expand Down
12 changes: 1 addition & 11 deletions zanataclient/parseconfig.py
Expand Up @@ -28,7 +28,7 @@
from zanatalib.logger import Logger
from xml.dom import minidom

project_config = {'project_url':'', 'project_id':'', 'project_version':'', 'project_srcdir':'', 'locale_map':{}}
project_config = {'project_url':'', 'project_id':'', 'project_version':'', 'locale_map':{}}


class ZanataConfig:
Expand Down Expand Up @@ -108,16 +108,6 @@ def read_project_config(self, filename):
rc = rc + node.data
project_config['project_version'] = rc

if xmldoc.getElementsByTagName("python-client"):
python_config = xmldoc.getElementsByTagName("python-client")[0]
srcdir = python_config.getElementsByTagName("dir")
rc = ""
for folder in srcdir:
for node in folder.childNodes:
if node.nodeType in ( node.TEXT_NODE, node.CDATA_SECTION_NODE):
rc = rc + node.data
project_config['project_srcdir'] = rc

#Read the locale map
if xmldoc.getElementsByTagName("locales"):
locales = xmldoc.getElementsByTagName("locales")[0]
Expand Down
48 changes: 12 additions & 36 deletions zanataclient/zanata.py
Expand Up @@ -188,6 +188,13 @@
long=['--project-type'],
metavar='PROJECTTYPE',
),
],
'client_version': [
dict(
type='program',
long=['--version'],
short=['-V'],
),
]
}

Expand Down Expand Up @@ -220,6 +227,10 @@
push Push the content of software project/docbook project to Zanata server
pull Pull the content of software project/docbook project from Zanata server
available system options:
--help Display this help or detail usage of commands
--version Display python client version
Use 'zanata help' for the full list of commands
Use 'zanata help <command>, zanata <command> --help or zanata <command> -h' for detail usage of commands
"""
Expand Down Expand Up @@ -1023,8 +1034,6 @@ def push(command_options, args, project_type = None):
#Disable dir option for generic push command
if command_options.has_key('dir'):
log.warn("dir option is disabled in push command, please use --srcdir and --transdir, or specify value in zanata.xml")
if project_config.has_key('project_srcdir'):
default_folder = project_config['project_srcdir']
else:
default_folder = None

Expand Down Expand Up @@ -1152,9 +1161,6 @@ def pull(command_options, args, project_type = None):
#Disable dir option for generic pull command
if command_options.has_key('dir'):
log.warn("dir option is disabled in pull command, please use --transdir, or specify value in zanata.xml")

if project_config.has_key('project_srcdir'):
output_folder = project_config['project_srcdir']
else:
output_folder = None

Expand All @@ -1166,35 +1172,6 @@ def pull(command_options, args, project_type = None):

zanatacmd = ZanataCommand()
zanatacmd.pull_command(zanata, locale_map, project_id, iteration_id, filelist, lang_list, outpath, command_type)

def version(command_options, args):
"""
Usage: zanata version
Display version of zanata python client, if running command from git repo, it will also show the latest commit id
"""

#Retrieve the version of client
version_number = ""
path = os.path.dirname(os.path.realpath(__file__))
version_file = os.path.join(path, 'VERSION-FILE')
try:
version = open(version_file, 'rb')
client_version = version.read()
version.close()
version_number = client_version.rstrip().strip('version: ')
except IOError:
log.error("Please run VERSION-GEN or 'make install' to generate VERSION-FILE")
version_number = "UNKNOWN"

log.info("zanata python client version: %s"%version_number)

p = subprocess.Popen('/usr/bin/git rev-parse HEAD', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
output = p.stdout.readline()
if output != '':
commit_id = output.rstrip()
log.info("commit id: %s"%commit_id)

command_handler_factories = {
'help': makeHandler(help_info),
Expand All @@ -1208,8 +1185,7 @@ def version(command_options, args):
'publican_pull': makeHandler(publican_pull),
'publican_push': makeHandler(publican_push),
'push': makeHandler(push),
'pull': makeHandler(pull),
'version': makeHandler(version)
'pull': makeHandler(pull)
}

def signal_handler(signal, frame):
Expand Down

0 comments on commit 14f6833

Please sign in to comment.