Esempio n. 1
0
def glossary_push(command_options, args):
    """
    Usage: zanata glossary push [OPTIONS] GLOSSARY_POFILE

    Push glossary file in po/csv format to zanata server

    Options:
        --url: URL of zanata server
        --username: user name (defaults to zanata.ini value)
        --apikey: api key of user (defaults to zanata.ini value)
        --lang(po format): language of glossary file
        --sourcecommentsastarget(po format): treat extracted comments and references as target comments of term
                                  or treat as source reference of entry
        --commentcols(csv format): comments header of csv format glossary file
    """
    locale_map = []
    zanatacmd = ZanataCommand()
    optionsutil = OptionsUtil(command_options)
    url, username, apikey = optionsutil.apply_configfiles()
    get_version(url)
    log.info("Username: %s" % username)
 
    if args:
        path = os.path.join(os.getcwd(), args[0])
        if not os.path.isfile(path):
            log.error("Can not find glossary file %s under current path"%args[0])
            sys.exit(1)
    else:
        log.info("Please specify the file name of glossary file")
        sys.exit(1)   

    basename, extension = os.path.splitext(path)

    locale_map = optionsutil.get_localemap()

    log.info("pushing glossary document %s to server"%args[0]);

    if extension == '.po':  
        if command_options.has_key('lang'):
            lang = command_options['lang'][0]['value'].split(',')[0]
        else:
            log.error("Please specify the language with '--lang' option")
            sys.exit(1)

        if lang in locale_map:
            lang = locale_map[lang]

        if command_options.has_key('sourcecomments'):
            sourcecomments = True
        else:
            sourcecomments = False
        zanatacmd.poglossary_push(path, url, username, apikey, lang, sourcecomments)
    elif extension == '.csv':
        if command_options.has_key('comment_cols'):
            comments_header = command_options['comment_cols'][0]['value'].split(',')
        else:
            log.error("Please specify the comments header, otherwise processing will be fault")
            sys.exit(1)
        
        zanatacmd.csvglossary_push(path, url, username, apikey, locale_map, comments_header)
Esempio n. 2
0
def glossary_delete(command_options, args):
    lang = None
    optionsutil = OptionsUtil(command_options)
    url, username, apikey = optionsutil.apply_configfiles()
    get_version(url, command_options)
    log.info("Username: %s" % username)

    zanatacmd = ZanataCommand(url, username, apikey)

    if command_options.has_key('disablesslcert'):
        zanatacmd.disable_ssl_cert_validation()

    if command_options.has_key('lang'):
        lang = command_options['lang'][0]['value'].split(',')[0]
        log.info("Delete the glossary terms in %s on the server" % lang)
    else:
        log.info("Delete all the glossary terms on the server")

    zanatacmd.delete_glossary(url, username, apikey, lang)
Esempio n. 3
0
def glossary_delete(command_options, args):
    lang = None
    optionsutil = OptionsUtil(command_options)
    url, username, apikey = optionsutil.apply_configfiles()
    headers = http_headers(username, apikey,
                           'application/vnd.zanata.Version+json')
    get_version(url, command_options, headers)
    log.info("Username: %s" % username)

    zanatacmd = ZanataCommand(url, username, apikey)

    if command_options.has_key('disablesslcert'):
        zanatacmd.disable_ssl_cert_validation()

    if command_options.has_key('lang'):
        lang = command_options['lang'][0]['value'].split(',')[0]
        log.info("Delete the glossary terms in %s on the server" % lang)
    else:
        log.info("Delete all the glossary terms on the server")

    zanatacmd.delete_glossary(url, username, apikey, lang)
Esempio n. 4
0
def glossary_push(command_options, args):
    """
    Usage: zanata glossary push [OPTIONS] GLOSSARY_POFILE

    Push glossary file in po/csv format to zanata server

    Options:
        --url: URL of zanata server
        --username: user name (defaults to zanata.ini value)
        --apikey: api key of user (defaults to zanata.ini value)
        --lang(po format): language of glossary file
        --sourcecommentsastarget(po format): treat extracted comments and references as target comments of term
                                  or treat as source reference of entry
        --commentcols(csv format): comments header of csv format glossary file
        --disable-ssl-cert disable ssl certificate validation in 0.7.x python-httplib2
    """
    locale_map = []

    optionsutil = OptionsUtil(command_options)
    url, username, apikey = optionsutil.apply_configfiles()
    headers = http_headers(username, apikey,
                           'application/vnd.zanata.Version+json')
    get_version(url, command_options, headers)
    log.info("Username: %s" % username)
    headers = http_headers(username, apikey, 'application/json')
    zanatacmd = ZanataCommand(url, username, apikey, headers)

    if command_options.has_key('disablesslcert'):
        zanatacmd.disable_ssl_cert_validation()

    if args:
        path = os.path.join(os.getcwd(), args[0])
        if not os.path.isfile(path):
            log.error("Can not find glossary file %s under current path" %
                      args[0])
            sys.exit(1)
    else:
        log.info("Please specify the file name of glossary file")
        sys.exit(1)

    basename, extension = os.path.splitext(path)

    locale_map = optionsutil.get_localemap()

    log.info("pushing glossary document %s to server" % args[0])

    if extension == '.po':
        if command_options.has_key('lang'):
            lang = command_options['lang'][0]['value'].split(',')[0]
        else:
            log.error("Please specify the language with '--lang' option")
            sys.exit(1)

        if lang in locale_map:
            lang = locale_map[lang]

        if command_options.has_key('sourcecomments'):
            sourcecomments = True
        else:
            sourcecomments = False
        zanatacmd.poglossary_push(path, url, username, apikey, lang,
                                  sourcecomments)
    elif extension == '.csv':
        if command_options.has_key('comment_cols'):
            comments_header = command_options['comment_cols'][0][
                'value'].split(',')
        else:
            log.error(
                "Please specify the comments header, otherwise processing will be fault"
            )
            sys.exit(1)

        zanatacmd.csvglossary_push(path, url, username, apikey, locale_map,
                                   comments_header)