本文整理汇总了Python中formatter.Formatter.format方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.format方法的具体用法?Python Formatter.format怎么用?Python Formatter.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formatter.Formatter
的用法示例。
在下文中一共展示了Formatter.format方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
def generate(self, save=True):
"Generates photo file in current format"
crop_box = None
if self.crop_left:
crop_box = (self.crop_left, self.crop_top, \
self.crop_left + self.crop_width, self.crop_top + self.crop_height)
important_box = None
if self.photo.important_top is not None:
p = self.photo
important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)
formatter = Formatter(Image.open(self.photo.image.path), self.format, crop_box=crop_box, important_box=important_box)
stretched_photo, crop_box = formatter.format()
self.crop_left, self.crop_top, right, bottom = crop_box
self.crop_width = right - self.crop_left
self.crop_height = bottom - self.crop_top
self.width, self.height = stretched_photo.size
stretched_photo.save(self.file(), quality=self.format.resample_quality)
f = open(self.file())
file = ContentFile(f.read())
f.close()
self.image.save(self.file(relative=True), file, save)
示例2: _generate_img
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
def _generate_img(self):
crop_box = None
if self.crop_left:
crop_box = (self.crop_left, self.crop_top, \
self.crop_left + self.crop_width, self.crop_top + self.crop_height)
important_box = None
if self.photo.important_top is not None:
p = self.photo
important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)
formatter = Formatter(self.photo._get_image(), self.format, crop_box=crop_box, important_box=important_box)
return formatter.format()
示例3: generate
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
def generate(self):
"Generates photo file in current format"
crop_box = None
if self.crop_left:
crop_box = (self.crop_left, self.crop_top, \
self.crop_left + self.crop_width, self.crop_top + self.crop_height)
important_box = None
if self.photo.important_top:
p = self.photo
important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)
formatter = Formatter(Image.open(self.filename), self.format, crop_box=crop_box, important_box=important_box)
stretched_photo, crop_box = formatter.format()
self.width, self.height = stretched_photo.size
self.filename = self.file(relative=True)
stretched_photo.save(self.file(), quality=self.format.resample_quality)
示例4: __init__
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
class Cli:
def __init__(self, module_name, config, parser):
self.__parser = parser
self.formatter = Formatter(module_name)
self.__option_parser = self.__get_option_parser(config, parser)
self.formatter.option_parser = self.__option_parser
def parse_args(self):
return self.__option_parser.parse_args()
def __get_option_parser(self, config, parser):
option_parser = OptionParser(self.formatter.format(config.usage))
self.__add_options(config, parser, option_parser)
self.__add_option_groups(config, option_parser, parser)
return option_parser
def __add_options(self, group, parser, option_parser):
for option in group.options:
self.__add_option(parser, option, option_parser)
def __add_option(self, parser, option, option_parser):
kwargs = self.__get_option_kwargs(parser, option.kwargs)
option_parser.add_option(*option.argv, **kwargs)
def __get_option_kwargs(self, parser, kwargs):
if "callback" in kwargs:
kwargs["callback"] = getattr(parser, kwargs["callback"])
return kwargs
def __add_option_groups(self, config, option_parser, parser):
for group in config.groups:
self.__add_option_group(option_parser, group, parser)
def __add_option_group(self, option_parser, group, parser):
option_parser_group = OptionGroup(option_parser, group.title, group.description)
self.__add_options(group, parser, option_parser_group)
option_parser.add_option_group(option_parser_group)
示例5: _generate_img
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
def _generate_img(self):
crop_box = None
if self.crop_left:
crop_box = (self.crop_left, self.crop_top, \
self.crop_left + self.crop_width, self.crop_top + self.crop_height)
important_box = None
if self.photo.important_top is not None:
p = self.photo
important_box = (p.important_left, p.important_top, p.important_right, p.important_bottom)
image = None
if crop_box is None and self.format.master_id:
try:
fp = FormatedPhoto.objects.get(format=self.format.master_id, photo=self.photo)
image = Image.open(fp.image)
except FormatedPhoto.DoesNotExist:
pass
if image is None:
image = self.photo._get_image()
formatter = Formatter(image, self.format, crop_box=crop_box, important_box=important_box)
return formatter.format()
示例6: Formatter
# 需要导入模块: from formatter import Formatter [as 别名]
# 或者: from formatter.Formatter import format [as 别名]
#!/usr/bin/env python
from info import InstanceInfo
from formatter import Formatter
f = Formatter()
i = InstanceInfo(
name="some_instance",
virt_name="instance-0000043c",
id=1084,
uuid="35315889-d4f1-4067-b14e-34b5e4bd49c8",
fixed_ip="x.x.x.x",
host="novacpu03.foo.bar.baz",
tenant="Something",
vm_state="active",
task_state=None,
vcpus=8,
ram="16.0GB",
snapshots=["6d0fd729-7034-41bb-b006-c98a2f39b275",
"3acc483b-0f2f-4c73-9854-3f4b2482bee6"])
i['something'] = [1,2,3,4,5]
print(f.format([i]))