예제 #1
0
def put_po_files_in_mongo(path, username, status, source_language,
                          target_language, db_host, db_port, db_name):
    '''go through directories and write the po file to mongo
    :param string path: the path to the po_files
    :param string username: the username of the translator
    :param string status: the status of the translations
    :param string source_language: The source_language of the translations
    :param string target_language: The target_language of the translations
    :param string db_host: the hostname of the database
    :param int db_port: the port of the database
    :param string db_name: the name of the database
    '''

    if not os.path.exists(path):
        err = path + "doesn't exist"
        logger.error(err)
        raise TypeError(err)

    db = MongoClient(db_host, db_port)[db_name]
    userID = db['users'].find_one({'username': username})[u'_id']

    logger.info("walking directory " + path)
    file_list = get_file_list(path, ["po", "pot"])
    if len(file_list) == 1:
        path = os.path.dirname(path)

    for fn in file_list:
        po = polib.pofile(fn)
        rel_fn = os.path.relpath(fn, path)
        rel_fn = os.path.splitext(rel_fn)[0]
        write_po_file_to_mongo(fn, po, userID, status, source_language,
                               target_language, db)
예제 #2
0
def put_po_files_in_mongo(path, username, status, source_language, target_language, db_host, db_port, db_name):
    '''go through directories and write the po file to mongo
    :param string path: the path to the po_files
    :param string username: the username of the translator
    :param string status: the status of the translations
    :param string source_language: The source_language of the translations
    :param string target_language: The target_language of the translations
    :param string db_host: the hostname of the database
    :param int db_port: the port of the database
    :param string db_name: the name of the database
    '''

    if not os.path.exists(path):
        err = path + "doesn't exist"
        logger.error(err)
        raise TypeError(err)

    db = MongoClient(db_host, db_port)[db_name]
    userID = db['users'].find_one({'username': username})[u'_id']

    logger.info("walking directory " + path)
    file_list = get_file_list(path, ["po", "pot"])
    if len(file_list) == 1:
        path = os.path.dirname(path)

    for fn in file_list:
        po = polib.pofile(fn)
        rel_fn = os.path.relpath(fn, path)
        rel_fn = os.path.splitext(rel_fn)[0]
        write_po_file_to_mongo(fn, po, userID, status, source_language,
                               target_language, db)
예제 #3
0
def write_mongo_to_po_files(path, source_language, target_language, db_host, db_port, db_name, is_all):
    ''' goes through directory tree and writes po files to mongo
    :param string path: the path to the top level directory of the po_files
    :param string source_language: language to translate from 
    :param string target_language: language to translate to 
    :param string db_host: the hostname of the database
    :param int db_port: the port of the database
    :param string db_name: the name of the database
    :param boolean is_all: whether or not you want all or just approved translations
    '''

    if not os.path.exists(path):
        logger.error("{0} doesn't exist".format(path))
        return

    db = MongoClient(db_host, db_port)[db_name]

    logger.info("walking directory " + path)
    file_list = get_file_list(path, ["po", "pot"])

    for fn in file_list:
        write_po_file(fn, source_language, target_language, db, is_all)
예제 #4
0
def write_mongo_to_po_files(path, source_language, target_language, db_host,
                            db_port, db_name, is_all):
    ''' goes through directory tree and writes po files to mongo
    :param string path: the path to the top level directory of the po_files
    :param string source_language: language to translate from 
    :param string target_language: language to translate to 
    :param string db_host: the hostname of the database
    :param int db_port: the port of the database
    :param string db_name: the name of the database
    :param boolean is_all: whether or not you want all or just approved translations
    '''

    if not os.path.exists(path):
        logger.error("{0} doesn't exist".format(path))
        return

    db = MongoClient(db_host, db_port)[db_name]

    logger.info("walking directory " + path)
    file_list = get_file_list(path, ["po", "pot"])

    for fn in file_list:
        write_po_file(fn, source_language, target_language, db, is_all)