Esempio n. 1
0
def export_to_api(lang, status, today, cur_json):
    global unfoldingWord_dir, lang_cat, github_org, pages

    print('Getting Github credentials...', end=' ')
    try:
        github_org = None
        if os.path.isfile('/root/.github_pass'):
            # noinspection PyTypeChecker
            pw = open('/root/.github_pass', 'r').read().strip()
            g_user = githubLogin('dsm-git', pw)
            github_org = getGithubOrg('unfoldingword', g_user)
        else:
            print('none found...', end=' ')
    except GithubException as e:
        print_error('Problem logging into Github: {0}'.format(e))
        sys.exit(1)
    print('finished.')

    print('Loading the uw catalog...', end=' ')
    uw_cat_path = os.path.join(unfoldingWord_dir, 'obs-catalog.json')
    uw_catalog = load_json_object(uw_cat_path, [])
    uw_cat_langs = [x['language'] for x in uw_catalog]
    print('finished')

    unfolding_word_lang_dir = os.path.join(unfoldingWord_dir, lang)
    if 'checking_level' in status and 'publish_date' in status:
        if status.checking_level in ['1', '2', '3']:

            front_json = OBS.get_front_matter(pages, lang, today)
            back_json = OBS.get_back_matter(pages, lang, today)

            print('Exporting {0}...'.format(lang), end=' ')
            export_unfolding_word(status, unfolding_word_lang_dir, cur_json,
                                  lang, github_org, front_json, back_json)
            if lang in uw_cat_langs:
                uw_catalog.pop(uw_cat_langs.index(lang))
                uw_cat_langs.pop(uw_cat_langs.index(lang))
            uw_catalog.append(lang_cat)

            uw_cat_json = json.dumps(uw_catalog,
                                     sort_keys=True,
                                     cls=OBSEncoder)
            write_file(uw_cat_path, uw_cat_json)

            # update uw_admin status page
            ObsPublishedLangs.update_page(ObsPublishedLangs.cat_url,
                                          ObsPublishedLangs.uw_stat_page)

            print('finished.')
        else:
            print_error('The `checking_level` is invalid.')
            sys.exit(1)
    else:
        print_error(
            'The status is missing `checking_level` or `publish_date`.')
        sys.exit(1)
def export_to_api(lang, status, today, cur_json):
    global unfoldingWord_dir, lang_cat, github_org, pages

    print('Getting Github credentials...', end=' ')
    try:
        github_org = None
        if os.path.isfile('/root/.github_pass'):
            # noinspection PyTypeChecker
            pw = open('/root/.github_pass', 'r').read().strip()
            g_user = githubLogin('dsm-git', pw)
            github_org = getGithubOrg('unfoldingword', g_user)
        else:
            print('none found...', end=' ')
    except GithubException as e:
        print_error('Problem logging into Github: {0}'.format(e))
        sys.exit(1)
    print('finished.')

    print('Loading the uw catalog...', end=' ')
    uw_cat_path = os.path.join(unfoldingWord_dir, 'obs-catalog.json')
    uw_catalog = load_json_object(uw_cat_path, [])
    uw_cat_langs = [x['language'] for x in uw_catalog]
    print('finished')

    unfolding_word_lang_dir = os.path.join(unfoldingWord_dir, lang)
    if 'checking_level' in status and 'publish_date' in status:
        if status.checking_level in ['1', '2', '3']:

            front_json = OBS.get_front_matter(pages, lang, today)
            back_json = OBS.get_back_matter(pages, lang, today)

            print('Exporting {0}...'.format(lang), end=' ')
            export_unfolding_word(status, unfolding_word_lang_dir, cur_json,
                                  lang, github_org, front_json, back_json)
            if lang in uw_cat_langs:
                uw_catalog.pop(uw_cat_langs.index(lang))
                uw_cat_langs.pop(uw_cat_langs.index(lang))
            uw_catalog.append(lang_cat)

            uw_cat_json = json.dumps(uw_catalog, sort_keys=True, cls=OBSEncoder)
            write_file(uw_cat_path, uw_cat_json)

            # update uw_admin status page
            ObsPublishedLangs.update_page(ObsPublishedLangs.cat_url, ObsPublishedLangs.uw_stat_page)

            print('finished.')
        else:
            print_error('The `checking_level` is invalid.')
            sys.exit(1)
    else:
        print_error('The status is missing `checking_level` or `publish_date`.')
        sys.exit(1)
                updated = True

    print('finished.')

    print('Writing the OBS file to the exports directory...', end=' ')
    cur_json = json.dumps(obs_obj, sort_keys=True, cls=OBSEncoder)

    if updated:
        ([x for x in catalog if x['language'] == lang][0]['date_modified']) = today
        write_page(json_lang_file_path, cur_json)
    print('finished.')

    if test_export:
        print('Testing {0} export...'.format(lang), end=' ')
        front_json = OBS.get_front_matter(pages, lang, today)
        back_json = OBS.get_back_matter(pages, lang, today)
        if not uw_qa(obs_obj, lang, status):
            print('---> QA Failed.')
            sys.exit(1)
        print('---> QA Passed.')
        sys.exit()

    if uw_export:
        print('Getting Github credentials...', end=' ')
        try:
            github_org = None
            if os.path.isfile('/root/.github_pass'):
                pw = open('/root/.github_pass', 'r').read().strip()
                g_user = githubLogin('dsm-git', pw)
                github_org = getGithubOrg('unfoldingword', g_user)
            else:
    print('finished.')

    print('Writing the OBS file to the exports directory...', end=' ')
    cur_json = json.dumps(obs_obj, sort_keys=True, cls=OBSEncoder)

    if updated:
        ([x for x in catalog
          if x['language'] == lang][0]['date_modified']) = today
        write_page(json_lang_file_path, cur_json)
    print('finished.')

    if test_export:
        print('Testing {0} export...'.format(lang), end=' ')
        front_json = OBS.get_front_matter(pages, lang, today)
        back_json = OBS.get_back_matter(pages, lang, today)
        if not uw_qa(obs_obj, lang, status):
            print('---> QA Failed.')
            sys.exit(1)
        print('---> QA Passed.')
        sys.exit()

    if uw_export:
        print('Getting Github credentials...', end=' ')
        try:
            github_org = None
            if os.path.isfile('/root/.github_pass'):
                pw = open('/root/.github_pass', 'r').read().strip()
                g_user = githubLogin('dsm-git', pw)
                github_org = getGithubOrg('unfoldingword', g_user)
            else: