예제 #1
0
    def change_interactive(self, resource_name, _placeholder):
        if resource_name is None:
            resources = Resource.objects.all().select_for_update()
        else:
            resources = [self.get_resource(resource_name)]

        updates = []
        for resource in resources:
            self.stdout.write("Resource '%s' (%s)\n" %
                              (resource.name, resource.desc))
            value = show_resource_value(resource.uplimit, resource.name,
                                        self.unit_style)
            self.stdout.write("Current limit: %s\n" % value)
            while True:
                self.stdout.write("New limit (leave blank to keep current): ")
                try:
                    response = raw_input()
                except EOFError:
                    self.stderr.write("Aborted.\n")
                    exit()
                if response == "":
                    break
                else:
                    try:
                        value = units.parse(response)
                    except units.ParseError:
                        continue
                    updates.append((resource, value))
                    break
        if updates:
            self.stderr.write("Updating...\n")
            update_resources(updates)
예제 #2
0
    def change_with_conf(self, resource_name, config):
        if resource_name is None:
            resources = Resource.objects.all().select_for_update()
        else:
            resources = [self.get_resource(resource_name)]

        updates = []
        for resource in resources:
            limit = config.get(resource.name)
            if limit is not None:
                limit = self.parse_limit(limit)
                updates.append((resource, limit))
        if updates:
            update_resources(updates)
예제 #3
0
 def change_resource_limit(self, resource, limit):
     limit = self.parse_limit(limit)
     update_resources([(resource, limit)])