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


Python VirtualFolder.description方法代码示例

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


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

示例1: handle

# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import description [as 别名]
    def handle(self, *args, **options):
        """Add virtual folders from file."""

        if not args:
            raise CommandError("You forgot to provide the mandatory filename.")

        try:
            inputfile = open(args[0], "r")
            vfolders = json.load(inputfile)
            inputfile.close()
        except IOError as e:
            raise CommandError(e)
        except ValueError as e:
            raise CommandError("Please check if the JSON file is malformed. "
                               "Original error:\n%s" %e)

        added_count = 0
        updated_count = 0
        errored_count = 0

        for vfolder_item in vfolders:
            vfolder_item['name'] = vfolder_item['name'].lower()

            # Put all the files for each virtual folder as a list and save it
            # as its filter rules.
            try:
                vfolder_item['filter_rules'] = ','.join(vfolder_item['filters']['files'])
            except KeyError:
                vfolder_item['filter_rules'] = ''

            if 'filters' in vfolder_item:
                del vfolder_item['filters']

            # Now create or update the virtual folder.
            try:
                # Retrieve the virtual folder if it exists.
                vfolder = VirtualFolder.objects.get(
                    name=vfolder_item['name'],
                    location=vfolder_item['location'],
                )
            except VirtualFolder.DoesNotExist:
                # If the virtual folder doesn't exist yet then create it.
                try:
                    vfolder = VirtualFolder(**vfolder_item)
                    vfolder.save()
                except ValidationError as e:
                    errored_count += 1
                    logging.error(e.message)
                else:
                    added_count += 1
            else:
                # Update the already existing virtual folder.
                changed = False

                if vfolder.filter_rules != vfolder_item['filter_rules']:
                    vfolder.filter_rules = vfolder_item['filter_rules']
                    changed = True
                    logging.info("Filter rules for virtual folder '%s' will "
                                 "be changed.", vfolder.name)

                if ('priority' in vfolder_item and
                    vfolder.priority != vfolder_item['priority']):

                    vfolder.priority = vfolder_item['priority']
                    changed = True
                    logging.info("Priority for virtual folder '%s' will be "
                                 "changed to %f.", vfolder.name,
                                 vfolder.priority)

                if ('is_browsable' in vfolder_item and
                    vfolder.is_browsable != vfolder_item['is_browsable']):

                    vfolder.is_browsable = vfolder_item['is_browsable']
                    changed = True
                    logging.info("is_browsable status for virtual folder '%s' "
                                 "will be changed.", vfolder.name)

                if ('description' in vfolder_item and
                    vfolder.description.raw != vfolder_item['description']):

                    vfolder.description = vfolder_item['description']
                    changed = True
                    logging.info("Description for virtual folder '%s' will be "
                                 "changed.", vfolder.name)

                if changed:
                    try:
                        vfolder.save()
                    except ValidationError as e:
                        errored_count += 1
                        logging.error(e.message)
                    else:
                        updated_count += 1

        logging.info("\nErrored: %d\nAdded: %d\nUpdated: %d\nUnchanged: %d",
                     errored_count, added_count, updated_count,
                     len(vfolders)-errored_count-added_count-updated_count)
开发者ID:actsgo,项目名称:pootle,代码行数:99,代码来源:add_vfolders.py

示例2: handle

# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import description [as 别名]
    def handle(self, **options):
        """Add virtual folders from file."""

        try:
            with open(options['vfolder'][0], "r") as inputfile:
                vfolders = json.load(inputfile)
        except IOError as e:
            raise CommandError(e)
        except ValueError as e:
            raise CommandError("Please check if the JSON file is malformed. "
                               "Original error:\n%s" % e)

        for vfolder_item in vfolders:
            try:
                temp = ','.join(vfolder_item['filters']['files'])
                if not temp:
                    raise ValueError
            except (KeyError, ValueError):
                raise CommandError("Virtual folder '%s' has no filtering "
                                   "rules." % vfolder_item['name'])

        self.stdout.write("Importing virtual folders...")

        added_count = 0
        updated_count = 0
        errored_count = 0

        for vfolder_item in vfolders:
            vfolder_item['name'] = vfolder_item['name'].lower()

            # Put all the files for each virtual folder as a list and save it
            # as its filter rules.
            vfolder_item['filter_rules'] = ','.join(
                vfolder_item['filters']['files'])

            if 'filters' in vfolder_item:
                del vfolder_item['filters']

            # Now create or update the virtual folder.
            try:
                # Retrieve the virtual folder if it exists.
                vfolder = VirtualFolder.objects.get(
                    name=vfolder_item['name'],
                    location=vfolder_item['location'],
                )
            except VirtualFolder.DoesNotExist:
                # If the virtual folder doesn't exist yet then create it.
                try:
                    self.stdout.write(u'Adding new virtual folder %s...' %
                                      vfolder_item['name'])
                    vfolder = VirtualFolder(**vfolder_item)
                    vfolder.save()
                except ValidationError as e:
                    errored_count += 1
                    self.stdout.write('FAILED')
                    self.stderr.write(e)
                else:
                    self.stdout.write('DONE')
                    added_count += 1
            else:
                # Update the already existing virtual folder.
                changed = False

                if vfolder.filter_rules != vfolder_item['filter_rules']:
                    vfolder.filter_rules = vfolder_item['filter_rules']
                    changed = True
                    logging.debug("Filter rules for virtual folder '%s' will "
                                  "be changed.", vfolder.name)

                if ('priority' in vfolder_item and
                    vfolder.priority != vfolder_item['priority']):

                    vfolder.priority = vfolder_item['priority']
                    changed = True
                    logging.debug("Priority for virtual folder '%s' will be "
                                  "changed to %f.", vfolder.name,
                                  vfolder.priority)

                if ('is_public' in vfolder_item and
                    vfolder.is_public != vfolder_item['is_public']):

                    vfolder.is_public = vfolder_item['is_public']
                    changed = True
                    logging.debug("is_public status for virtual folder "
                                  "'%s' will be changed.", vfolder.name)

                if ('description' in vfolder_item and
                    vfolder.description.raw != vfolder_item['description']):

                    vfolder.description = vfolder_item['description']
                    changed = True
                    logging.debug("Description for virtual folder '%s' will "
                                  "be changed.", vfolder.name)

                if changed:
                    try:
                        self.stdout.write(u'Updating virtual folder %s...' %
                                          vfolder_item['name'])
                        vfolder.save()
                    except ValidationError as e:
#.........这里部分代码省略.........
开发者ID:AlfredWei,项目名称:pootle,代码行数:103,代码来源:add_vfolders.py

示例3: handle

# 需要导入模块: from virtualfolder.models import VirtualFolder [as 别名]
# 或者: from virtualfolder.models.VirtualFolder import description [as 别名]

#.........这里部分代码省略.........
        errored_count = 0

        for vfolder_item in vfolders:
            vfolder_item["name"] = vfolder_item["name"].strip().lower()

            # Put all the files for each virtual folder as a list and save it
            # as its filter rules.
            languages, projects, new_rules = self.parse_vfolder_rules(
                vfolder_item["location"].strip(), vfolder_item["filters"]["files"]
            )

            vfolder_item["filter_rules"] = new_rules

            if "filters" in vfolder_item:
                del vfolder_item["filters"]

            # Now create or update the virtual folder.
            try:
                # Retrieve the virtual folder if it exists.
                vfolder = VirtualFolder.objects.get(name=vfolder_item["name"])
            except VirtualFolder.DoesNotExist:
                # If the virtual folder doesn't exist yet then create it.
                try:
                    self.stdout.write(u"Adding new virtual folder %s..." % vfolder_item["name"])
                    vfolder_item["all_projects"] = not projects
                    vfolder_item["all_languages"] = not languages
                    vfolder = VirtualFolder(**vfolder_item)
                    vfolder.save()
                except ValidationError as e:
                    errored_count += 1
                    self.stdout.write("FAILED")
                    self.stderr.write(e)
                else:
                    if projects:
                        vfolder.projects.add(*Project.objects.filter(code__in=projects))
                    if languages:
                        vfolder.languages.add(*Language.objects.filter(code__in=languages))
                    self.stdout.write("DONE")
                    added_count += 1
            else:
                # Update the already existing virtual folder.
                changed = False

                if not projects:
                    vfolder.all_projects = True
                    changed = True
                    logging.debug("'All projects' for virtual folder '%s' " "will be changed.", vfolder.name)

                if not languages:
                    vfolder.all_languages = True
                    changed = True
                    logging.debug("'All languages' for virtual folder '%s' " "will be changed.", vfolder.name)

                if projects:
                    vfolder.projects.set(*Project.objects.filter(code__in=projects))
                if languages:
                    vfolder.languages.set(*Language.objects.filter(code__in=languages))

                if vfolder.filter_rules != vfolder_item["filter_rules"]:
                    vfolder.filter_rules = vfolder_item["filter_rules"]
                    changed = True
                    logging.debug("Filter rules for virtual folder '%s' will " "be changed.", vfolder.name)

                if "priority" in vfolder_item and vfolder.priority != vfolder_item["priority"]:

                    vfolder.priority = vfolder_item["priority"]
                    changed = True
                    logging.debug(
                        "Priority for virtual folder '%s' will be " "changed to %f.", vfolder.name, vfolder.priority
                    )

                if "is_public" in vfolder_item and vfolder.is_public != vfolder_item["is_public"]:

                    vfolder.is_public = vfolder_item["is_public"]
                    changed = True
                    logging.debug("is_public status for virtual folder " "'%s' will be changed.", vfolder.name)

                if "description" in vfolder_item and vfolder.description.raw != vfolder_item["description"]:

                    vfolder.description = vfolder_item["description"]
                    changed = True
                    logging.debug("Description for virtual folder '%s' will " "be changed.", vfolder.name)

                if changed:
                    try:
                        self.stdout.write(u"Updating virtual folder %s..." % vfolder_item["name"])
                        vfolder.save()
                    except ValidationError as e:
                        errored_count += 1
                        self.stdout.write("FAILED")
                        self.stderr.write(e)
                    else:
                        self.stdout.write("DONE")
                        updated_count += 1

        self.stdout.write(
            "\nErrored: %d\nAdded: %d\n"
            "Updated: %d\nUnchanged: %d"
            % (errored_count, added_count, updated_count, len(vfolders) - errored_count - added_count - updated_count)
        )
开发者ID:phlax,项目名称:pootle,代码行数:104,代码来源:add_vfolders.py


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