forked from squeaky-pl/pystacia
/
__init__.py
102 lines (73 loc) · 2.89 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# coding: utf-8
# pystacia/__init__.py
# Copyright (C) 2011 by Paweł Piotr Przeradowski
# This module is part of Pystacia and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""pystacia is a raster graphics library utilizing ImageMagick."""
__version__ = '0.3dev'
__author__ = 'Pawel Piotr Przeradowski'
from os import environ
if not environ.get('PYSTACIA_SETUP'):
from logging import getLogger, basicConfig
logger = getLogger('pystacia')
level = environ.get('PYSTACIA_LOG')
if level:
basicConfig(level=int(level),
format='%(asctime)s %(name)-12s %(thread)d %(message)s')
logger.debug('Imported main module')
if environ.get('PYSTACIA_TRACE'):
logger.debug('Starting tracing')
import stacktracer # @UnresolvedImport
stacktracer.trace_start('trace.html', interval=5, auto=True)
from pystacia.util import Registry
registry = Registry()
from pystacia import color
colors = color.Factory()
"""Convenience factory for SVG names"""
def lazy_imported(key):
def call(*args, **kw):
from pystacia import image
return getattr(image, key)(*args, **kw)
return call
def really_lazy_enum(key):
class Proxy(object):
def __init__(self, key):
self.__key = key
def __getattr__(self, attr_key):
from pystacia import image
enum = getattr(image, key)
return getattr(enum, attr_key)
return Proxy(key)
# lazy importing proxies
read = lazy_imported('read')
read_blob = lazy_imported('read_blob')
read_raw = lazy_imported('read_raw')
blank = lazy_imported('blank')
checkerboard = lazy_imported('checkerboard')
lena = lazy_imported('lena')
magick_logo = lazy_imported('magick_logo')
rose = lazy_imported('rose')
wizard = lazy_imported('wizard')
granite = lazy_imported('granite')
netscape = lazy_imported('netscape')
Image = lazy_imported('Image')
composites = really_lazy_enum('composites')
types = really_lazy_enum('types')
filters = really_lazy_enum('filters')
colorspaces = really_lazy_enum('colorspaces')
compressions = really_lazy_enum('compressions')
axes = really_lazy_enum('axes')
__all__ = [
'read', 'read_blob', 'read_raw',
'blank', 'checkerboard',
'lena', 'magick_logo', 'rose', 'wizard', 'granite', 'netscape',
'composites', 'types', 'filters',
'colorspaces', 'compressions', 'axes',
'color', 'colors',
'Image',
'registry']
from zope.deprecation import deprecated # @UnresolvedImport
from pystacia.compat import formattable
msg = formattable('Use pystacia.image.{0} instead')
for symbol in set(__all__) - set(['color', 'colors', 'registry']):
deprecated(symbol, msg.format(symbol))