当前位置: 首页>>代码示例>>Python>>正文


Python POHandler.contents_check方法代码示例

本文整理汇总了Python中transifex.resources.formats.pofile.POHandler.contents_check方法的典型用法代码示例。如果您正苦于以下问题:Python POHandler.contents_check方法的具体用法?Python POHandler.contents_check怎么用?Python POHandler.contents_check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transifex.resources.formats.pofile.POHandler的用法示例。


在下文中一共展示了POHandler.contents_check方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import contents_check [as 别名]
    def handle(self, *args, **options):

        # OMG!1! Dirty fix for circular importing issues. Didn't want to dig
        # into it because it's probably not worth, once it's a tmp code.
        from transifex.resources.formats import get_i18n_type_from_file
        from transifex.resources.formats.pofile import POHandler
        from transifex.languages.models import Language
        from transifex.projects.models import Project
        from transifex.resources.models import Resource

        force = options.get('force')

        if settings.DEBUG:
            msg = "You are running this command with DEBUG=True. Please " \
                "change it to False in order to avoid problems with " \
                "allocating memory."
            raise CommandError(msg)

        msg = None
        if len(args) == 0:
            jsonmaps = JSONMap.objects.all()
        else:
            jsonmaps = JSONMap.objects.filter(project__slug__in=args)
            if not jsonmaps:
                msg = "No mapping found for given project slug(s): %s" % ', '.join(args)

        if not jsonmaps:
            raise CommandError(msg or "No mapping found in the database.")

        for jsonmap in jsonmaps:
            jm = jsonmap.loads(True)

            # Check whether the map was already migrated or not
            if jm['meta'].get('_migrated', None) and not force:
                logger.debug("Project '%s' was already migrated." % jsonmap.project)
                continue

            for r in jm['resources']:
                logger.debug("Pushing resource: %s" % r.get('resource_slug'))

                project = jsonmap.project

                # Path for cached files of project.component
                path = os.path.join(settings.MSGMERGE_DIR,
                    '%s.%s' % (project.slug, jsonmap.slug))

                if os.path.exists(path):

                    resource_slug = r['resource_slug']
                    language = Language.objects.by_code_or_alias_or_none(
                        r['source_lang'])

                    # Create resource and load source language
                    if language:
                        resource, created = Resource.objects.get_or_create(
                                slug = resource_slug,
                                source_language = language,
                                project = project)

                        if created:
                            resource.name = '%s - %s' % (jsonmap.slug,
                                r['source_file'])

                        source_file = os.path.join(path, r['source_file'])
                        resource.i18n_type = get_i18n_type_from_file(source_file)
                        resource.save()

                        resource.url_info = URLInfo(source_file_url=r['autofetch_url'])

                        logger.debug("Inserting source strings from %s (%s) to "
                            "'%s'." % (r['source_file'], language.code,
                            resource.full_name))

                        fhandler = POHandler(filename=source_file)
                        fhandler.bind_resource(resource)
                        fhandler.set_language(language)

                        try:
                            fhandler.contents_check(fhandler.filename)
                            fhandler.parse_file(True)
                            strings_added, strings_updated = fhandler.save2db(True)
                        except Exception, e:
                            resource.delete()
                            sys.stdout.write((u"Resource not created! Could not import "
                                "file '%s': %s.\n" % (source_file, str(e))).encode('UTF-8'))
                            # Skip adding translations, as the resource
                            # wasn't created.
                            continue

                        logger.debug("Inserting translations for '%s' (%s)."
                            % (resource.slug, project))

                        # Load translations
                        for code, f in r['translations'].items():
                            language = Language.objects.by_code_or_alias_or_none(code)
                            if language:
                                translation_file = os.path.join(path, f['file'])
                                try:
                                    fhandler = POHandler(filename=translation_file)
                                    fhandler.set_language(language)
#.........这里部分代码省略.........
开发者ID:hfeeki,项目名称:transifex,代码行数:103,代码来源:txmigratemap.py


注:本文中的transifex.resources.formats.pofile.POHandler.contents_check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。